@@ -347,6 +347,8 @@ func TestBooleanRoundtrip(t *testing.T) {
347
347
}
348
348
}
349
349
350
+ func timezone (t time.Time ) string { return t .Format ("-07:00" ) }
351
+
350
352
func TestTimestamp (t * testing.T ) {
351
353
tempFilename := TempFilename (t )
352
354
db , err := sql .Open ("sqlite3" , tempFilename )
@@ -365,30 +367,40 @@ func TestTimestamp(t *testing.T) {
365
367
timestamp1 := time .Date (2012 , time .April , 6 , 22 , 50 , 0 , 0 , time .UTC )
366
368
timestamp2 := time .Date (2006 , time .January , 2 , 15 , 4 , 5 , 123456789 , time .UTC )
367
369
timestamp3 := time .Date (2012 , time .November , 4 , 0 , 0 , 0 , 0 , time .UTC )
370
+ tzTest := time .FixedZone ("TEST" , - 9 * 3600 - 13 * 60 )
368
371
tests := []struct {
369
372
value interface {}
370
373
expected time.Time
371
374
}{
372
375
{"nonsense" , time.Time {}},
373
376
{"0000-00-00 00:00:00" , time.Time {}},
374
377
{timestamp1 , timestamp1 },
375
- {timestamp1 .Unix (), timestamp1 },
376
- {timestamp1 .UnixNano () / int64 (time .Millisecond ), timestamp1 },
377
- {timestamp1 .In (time . FixedZone ( "TEST" , - 7 * 3600 )) , timestamp1 },
378
+ {timestamp2 .Unix (), timestamp2 . Truncate ( time . Second ) },
379
+ {timestamp2 .UnixNano () / int64 (time .Millisecond ), timestamp2 . Truncate ( time . Millisecond ) },
380
+ {timestamp1 .In (tzTest ) , timestamp1 . In ( tzTest ) },
378
381
{timestamp1 .Format ("2006-01-02 15:04:05.000" ), timestamp1 },
379
382
{timestamp1 .Format ("2006-01-02T15:04:05.000" ), timestamp1 },
380
383
{timestamp1 .Format ("2006-01-02 15:04:05" ), timestamp1 },
381
384
{timestamp1 .Format ("2006-01-02T15:04:05" ), timestamp1 },
382
385
{timestamp2 , timestamp2 },
383
386
{"2006-01-02 15:04:05.123456789" , timestamp2 },
384
387
{"2006-01-02T15:04:05.123456789" , timestamp2 },
388
+ {"2006-01-02T05:51:05.123456789-09:13" , timestamp2 .In (tzTest )},
385
389
{"2012-11-04" , timestamp3 },
386
390
{"2012-11-04 00:00" , timestamp3 },
387
391
{"2012-11-04 00:00:00" , timestamp3 },
388
392
{"2012-11-04 00:00:00.000" , timestamp3 },
389
393
{"2012-11-04T00:00" , timestamp3 },
390
394
{"2012-11-04T00:00:00" , timestamp3 },
391
395
{"2012-11-04T00:00:00.000" , timestamp3 },
396
+ {"2006-01-02T15:04:05.123456789Z" , timestamp2 },
397
+ {"2012-11-04Z" , timestamp3 },
398
+ {"2012-11-04 00:00Z" , timestamp3 },
399
+ {"2012-11-04 00:00:00Z" , timestamp3 },
400
+ {"2012-11-04 00:00:00.000Z" , timestamp3 },
401
+ {"2012-11-04T00:00Z" , timestamp3 },
402
+ {"2012-11-04T00:00:00Z" , timestamp3 },
403
+ {"2012-11-04T00:00:00.000Z" , timestamp3 },
392
404
}
393
405
for i := range tests {
394
406
_ , err = db .Exec ("INSERT INTO foo(id, ts, dt) VALUES(?, ?, ?)" , i , tests [i ].value , tests [i ].value )
@@ -423,6 +435,14 @@ func TestTimestamp(t *testing.T) {
423
435
if ! tests [id ].expected .Equal (dt ) {
424
436
t .Errorf ("Datetime value for id %v (%v) should be %v, not %v" , id , tests [id ].value , tests [id ].expected , dt )
425
437
}
438
+ if timezone (tests [id ].expected ) != timezone (ts ) {
439
+ t .Errorf ("Timezone for id %v (%v) should be %v, not %v" , id , tests [id ].value ,
440
+ timezone (tests [id ].expected ), timezone (ts ))
441
+ }
442
+ if timezone (tests [id ].expected ) != timezone (dt ) {
443
+ t .Errorf ("Timezone for id %v (%v) should be %v, not %v" , id , tests [id ].value ,
444
+ timezone (tests [id ].expected ), timezone (dt ))
445
+ }
426
446
}
427
447
428
448
if seen != len (tests ) {
0 commit comments