Fix incorrect to_gmt_offset result

This commit is contained in:
Alex Ling
2024-09-28 16:45:14 +07:00
committed by Christoffer Lerno
parent 8a0b0f5cf5
commit fe9e434020
2 changed files with 23 additions and 1 deletions

View File

@@ -105,7 +105,8 @@ fn TzDateTime DateTime.to_gmt_offset(self, int gmt_offset)
* @ensure self.time == return.time
**/
fn TzDateTime TzDateTime.to_gmt_offset(self, int gmt_offset) {
Time time = self.time + (Time)(gmt_offset - self.gmt_offset) * (Time)time::SEC;
if (self.gmt_offset == gmt_offset) return self;
Time time = self.time + (Time)gmt_offset * (Time)time::SEC;
DateTime dt = from_time(time);
dt.time = self.time;
return { dt, gmt_offset };