File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 1
1
import time
2
+ import math
2
3
3
4
const (
4
5
time_to_test = time.Time{
@@ -223,3 +224,24 @@ fn test_unix_time() {
223
224
assert utm2 - utm1 > 2
224
225
assert utm2 - utm1 < 999
225
226
}
227
+
228
+ fn test_offset () {
229
+ u := time.utc ()
230
+ n := time.now ()
231
+ //
232
+ mut diff_seconds := 0
233
+ if u.day != n.day {
234
+ if u.day > n.day {
235
+ diff_seconds = int (math.abs (((u.hour * 60 + u.minute) - (n.hour * 60 + n.minute)) * 60 )) - 86400
236
+ } else {
237
+ diff_seconds = 86400 - int (math.abs (((u.hour * 60 + u.minute) - (n.hour * 60 + n.minute)) * 60 ))
238
+ }
239
+ if math.abs (u.day - n.day) > 1 { // different month
240
+ diff_seconds = diff_seconds * - 1
241
+ }
242
+ } else { // same day
243
+ diff_seconds = ((n.hour * 60 + n.minute) - (u.hour * 60 + u.minute)) * 60
244
+ }
245
+
246
+ assert diff_seconds == time.offset ()
247
+ }
Original file line number Diff line number Diff line change @@ -114,8 +114,8 @@ pub fn (t Time) local() Time {
114
114
hour: st_local.hour
115
115
minute: st_local.minute
116
116
second: st_local.second // These are the same
117
- microsecond: t.microsecond
118
- unix: t.unix
117
+ microsecond: st_local.millisecond * 1000
118
+ unix: u64 (st_local. unix_time ())
119
119
}
120
120
return t_local
121
121
}
You can’t perform that action at this time.
0 commit comments