@@ -324,6 +324,8 @@ func TestBooleanRoundtrip(t *testing.T) {
324
324
}
325
325
}
326
326
327
+ func timezone (t time.Time ) string { return t .Format ("-07:00" ) }
328
+
327
329
func TestTimestamp (t * testing.T ) {
328
330
tempFilename := TempFilename ()
329
331
db , err := sql .Open ("sqlite3" , tempFilename )
@@ -342,30 +344,40 @@ func TestTimestamp(t *testing.T) {
342
344
timestamp1 := time .Date (2012 , time .April , 6 , 22 , 50 , 0 , 0 , time .UTC )
343
345
timestamp2 := time .Date (2006 , time .January , 2 , 15 , 4 , 5 , 123456789 , time .UTC )
344
346
timestamp3 := time .Date (2012 , time .November , 4 , 0 , 0 , 0 , 0 , time .UTC )
347
+ tzTest := time .FixedZone ("TEST" , - 9 * 3600 - 13 * 60 )
345
348
tests := []struct {
346
349
value interface {}
347
350
expected time.Time
348
351
}{
349
352
{"nonsense" , time.Time {}},
350
353
{"0000-00-00 00:00:00" , time.Time {}},
351
354
{timestamp1 , timestamp1 },
352
- {timestamp1 .Unix (), timestamp1 },
353
- {timestamp1 .UnixNano () / int64 (time .Millisecond ), timestamp1 },
354
- {timestamp1 .In (time . FixedZone ( "TEST" , - 7 * 3600 )) , timestamp1 },
355
+ {timestamp2 .Unix (), timestamp2 . Truncate ( time . Second ) },
356
+ {timestamp2 .UnixNano () / int64 (time .Millisecond ), timestamp2 . Truncate ( time . Millisecond ) },
357
+ {timestamp1 .In (tzTest ) , timestamp1 . In ( tzTest ) },
355
358
{timestamp1 .Format ("2006-01-02 15:04:05.000" ), timestamp1 },
356
359
{timestamp1 .Format ("2006-01-02T15:04:05.000" ), timestamp1 },
357
360
{timestamp1 .Format ("2006-01-02 15:04:05" ), timestamp1 },
358
361
{timestamp1 .Format ("2006-01-02T15:04:05" ), timestamp1 },
359
362
{timestamp2 , timestamp2 },
360
363
{"2006-01-02 15:04:05.123456789" , timestamp2 },
361
364
{"2006-01-02T15:04:05.123456789" , timestamp2 },
365
+ {"2006-01-02T05:51:05.123456789-09:13" , timestamp2 .In (tzTest )},
362
366
{"2012-11-04" , timestamp3 },
363
367
{"2012-11-04 00:00" , timestamp3 },
364
368
{"2012-11-04 00:00:00" , timestamp3 },
365
369
{"2012-11-04 00:00:00.000" , timestamp3 },
366
370
{"2012-11-04T00:00" , timestamp3 },
367
371
{"2012-11-04T00:00:00" , timestamp3 },
368
372
{"2012-11-04T00:00:00.000" , timestamp3 },
373
+ {"2006-01-02T15:04:05.123456789Z" , timestamp2 },
374
+ {"2012-11-04Z" , timestamp3 },
375
+ {"2012-11-04 00:00Z" , timestamp3 },
376
+ {"2012-11-04 00:00:00Z" , timestamp3 },
377
+ {"2012-11-04 00:00:00.000Z" , timestamp3 },
378
+ {"2012-11-04T00:00Z" , timestamp3 },
379
+ {"2012-11-04T00:00:00Z" , timestamp3 },
380
+ {"2012-11-04T00:00:00.000Z" , timestamp3 },
369
381
}
370
382
for i := range tests {
371
383
_ , err = db .Exec ("INSERT INTO foo(id, ts, dt) VALUES(?, ?, ?)" , i , tests [i ].value , tests [i ].value )
@@ -400,6 +412,14 @@ func TestTimestamp(t *testing.T) {
400
412
if ! tests [id ].expected .Equal (dt ) {
401
413
t .Errorf ("Datetime value for id %v (%v) should be %v, not %v" , id , tests [id ].value , tests [id ].expected , dt )
402
414
}
415
+ if timezone (tests [id ].expected ) != timezone (ts ) {
416
+ t .Errorf ("Timezone for id %v (%v) should be %v, not %v" , id , tests [id ].value ,
417
+ timezone (tests [id ].expected ), timezone (ts ))
418
+ }
419
+ if timezone (tests [id ].expected ) != timezone (dt ) {
420
+ t .Errorf ("Timezone for id %v (%v) should be %v, not %v" , id , tests [id ].value ,
421
+ timezone (tests [id ].expected ), timezone (dt ))
422
+ }
403
423
}
404
424
405
425
if seen != len (tests ) {
0 commit comments