github.com/ader1990/go@v0.0.0-20140630135419-8c24447fa791/src/pkg/time/format_test.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package time_test 6 7 import ( 8 "fmt" 9 "strconv" 10 "strings" 11 "testing" 12 "testing/quick" 13 . "time" 14 ) 15 16 type TimeFormatTest struct { 17 time Time 18 formattedValue string 19 } 20 21 var rfc3339Formats = []TimeFormatTest{ 22 {Date(2008, 9, 17, 20, 4, 26, 0, UTC), "2008-09-17T20:04:26Z"}, 23 {Date(1994, 9, 17, 20, 4, 26, 0, FixedZone("EST", -18000)), "1994-09-17T20:04:26-05:00"}, 24 {Date(2000, 12, 26, 1, 15, 6, 0, FixedZone("OTO", 15600)), "2000-12-26T01:15:06+04:20"}, 25 } 26 27 func TestRFC3339Conversion(t *testing.T) { 28 for _, f := range rfc3339Formats { 29 if f.time.Format(RFC3339) != f.formattedValue { 30 t.Error("RFC3339:") 31 t.Errorf(" want=%+v", f.formattedValue) 32 t.Errorf(" have=%+v", f.time.Format(RFC3339)) 33 } 34 } 35 } 36 37 type FormatTest struct { 38 name string 39 format string 40 result string 41 } 42 43 var formatTests = []FormatTest{ 44 {"ANSIC", ANSIC, "Wed Feb 4 21:00:57 2009"}, 45 {"UnixDate", UnixDate, "Wed Feb 4 21:00:57 PST 2009"}, 46 {"RubyDate", RubyDate, "Wed Feb 04 21:00:57 -0800 2009"}, 47 {"RFC822", RFC822, "04 Feb 09 21:00 PST"}, 48 {"RFC850", RFC850, "Wednesday, 04-Feb-09 21:00:57 PST"}, 49 {"RFC1123", RFC1123, "Wed, 04 Feb 2009 21:00:57 PST"}, 50 {"RFC1123Z", RFC1123Z, "Wed, 04 Feb 2009 21:00:57 -0800"}, 51 {"RFC3339", RFC3339, "2009-02-04T21:00:57-08:00"}, 52 {"RFC3339Nano", RFC3339Nano, "2009-02-04T21:00:57.0123456-08:00"}, 53 {"Kitchen", Kitchen, "9:00PM"}, 54 {"am/pm", "3pm", "9pm"}, 55 {"AM/PM", "3PM", "9PM"}, 56 {"two-digit year", "06 01 02", "09 02 04"}, 57 // Three-letter months and days must not be followed by lower-case letter. 58 {"Janet", "Hi Janet, the Month is January", "Hi Janet, the Month is February"}, 59 // Time stamps, Fractional seconds. 60 {"Stamp", Stamp, "Feb 4 21:00:57"}, 61 {"StampMilli", StampMilli, "Feb 4 21:00:57.012"}, 62 {"StampMicro", StampMicro, "Feb 4 21:00:57.012345"}, 63 {"StampNano", StampNano, "Feb 4 21:00:57.012345600"}, 64 } 65 66 func TestFormat(t *testing.T) { 67 // The numeric time represents Thu Feb 4 21:00:57.012345600 PST 2010 68 time := Unix(0, 1233810057012345600) 69 for _, test := range formatTests { 70 result := time.Format(test.format) 71 if result != test.result { 72 t.Errorf("%s expected %q got %q", test.name, test.result, result) 73 } 74 } 75 } 76 77 func TestFormatShortYear(t *testing.T) { 78 years := []int{ 79 -100001, -100000, -99999, 80 -10001, -10000, -9999, 81 -1001, -1000, -999, 82 -101, -100, -99, 83 -11, -10, -9, 84 -1, 0, 1, 85 9, 10, 11, 86 99, 100, 101, 87 999, 1000, 1001, 88 9999, 10000, 10001, 89 99999, 100000, 100001, 90 } 91 92 for _, y := range years { 93 time := Date(y, January, 1, 0, 0, 0, 0, UTC) 94 result := time.Format("2006.01.02") 95 var want string 96 if y < 0 { 97 // The 4 in %04d counts the - sign, so print -y instead 98 // and introduce our own - sign. 99 want = fmt.Sprintf("-%04d.%02d.%02d", -y, 1, 1) 100 } else { 101 want = fmt.Sprintf("%04d.%02d.%02d", y, 1, 1) 102 } 103 if result != want { 104 t.Errorf("(jan 1 %d).Format(\"2006.01.02\") = %q, want %q", y, result, want) 105 } 106 } 107 } 108 109 type ParseTest struct { 110 name string 111 format string 112 value string 113 hasTZ bool // contains a time zone 114 hasWD bool // contains a weekday 115 yearSign int // sign of year, -1 indicates the year is not present in the format 116 fracDigits int // number of digits of fractional second 117 } 118 119 var parseTests = []ParseTest{ 120 {"ANSIC", ANSIC, "Thu Feb 4 21:00:57 2010", false, true, 1, 0}, 121 {"UnixDate", UnixDate, "Thu Feb 4 21:00:57 PST 2010", true, true, 1, 0}, 122 {"RubyDate", RubyDate, "Thu Feb 04 21:00:57 -0800 2010", true, true, 1, 0}, 123 {"RFC850", RFC850, "Thursday, 04-Feb-10 21:00:57 PST", true, true, 1, 0}, 124 {"RFC1123", RFC1123, "Thu, 04 Feb 2010 21:00:57 PST", true, true, 1, 0}, 125 {"RFC1123", RFC1123, "Thu, 04 Feb 2010 22:00:57 PDT", true, true, 1, 0}, 126 {"RFC1123Z", RFC1123Z, "Thu, 04 Feb 2010 21:00:57 -0800", true, true, 1, 0}, 127 {"RFC3339", RFC3339, "2010-02-04T21:00:57-08:00", true, false, 1, 0}, 128 {"custom: \"2006-01-02 15:04:05-07\"", "2006-01-02 15:04:05-07", "2010-02-04 21:00:57-08", true, false, 1, 0}, 129 // Optional fractional seconds. 130 {"ANSIC", ANSIC, "Thu Feb 4 21:00:57.0 2010", false, true, 1, 1}, 131 {"UnixDate", UnixDate, "Thu Feb 4 21:00:57.01 PST 2010", true, true, 1, 2}, 132 {"RubyDate", RubyDate, "Thu Feb 04 21:00:57.012 -0800 2010", true, true, 1, 3}, 133 {"RFC850", RFC850, "Thursday, 04-Feb-10 21:00:57.0123 PST", true, true, 1, 4}, 134 {"RFC1123", RFC1123, "Thu, 04 Feb 2010 21:00:57.01234 PST", true, true, 1, 5}, 135 {"RFC1123Z", RFC1123Z, "Thu, 04 Feb 2010 21:00:57.01234 -0800", true, true, 1, 5}, 136 {"RFC3339", RFC3339, "2010-02-04T21:00:57.012345678-08:00", true, false, 1, 9}, 137 {"custom: \"2006-01-02 15:04:05\"", "2006-01-02 15:04:05", "2010-02-04 21:00:57.0", false, false, 1, 0}, 138 // Amount of white space should not matter. 139 {"ANSIC", ANSIC, "Thu Feb 4 21:00:57 2010", false, true, 1, 0}, 140 {"ANSIC", ANSIC, "Thu Feb 4 21:00:57 2010", false, true, 1, 0}, 141 // Case should not matter 142 {"ANSIC", ANSIC, "THU FEB 4 21:00:57 2010", false, true, 1, 0}, 143 {"ANSIC", ANSIC, "thu feb 4 21:00:57 2010", false, true, 1, 0}, 144 // Fractional seconds. 145 {"millisecond", "Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 21:00:57.012 2010", false, true, 1, 3}, 146 {"microsecond", "Mon Jan _2 15:04:05.000000 2006", "Thu Feb 4 21:00:57.012345 2010", false, true, 1, 6}, 147 {"nanosecond", "Mon Jan _2 15:04:05.000000000 2006", "Thu Feb 4 21:00:57.012345678 2010", false, true, 1, 9}, 148 // Leading zeros in other places should not be taken as fractional seconds. 149 {"zero1", "2006.01.02.15.04.05.0", "2010.02.04.21.00.57.0", false, false, 1, 1}, 150 {"zero2", "2006.01.02.15.04.05.00", "2010.02.04.21.00.57.01", false, false, 1, 2}, 151 // Month and day names only match when not followed by a lower-case letter. 152 {"Janet", "Hi Janet, the Month is January: Jan _2 15:04:05 2006", "Hi Janet, the Month is February: Feb 4 21:00:57 2010", false, true, 1, 0}, 153 154 // GMT with offset. 155 {"GMT-8", UnixDate, "Fri Feb 5 05:00:57 GMT-8 2010", true, true, 1, 0}, 156 157 // Accept any number of fractional second digits (including none) for .999... 158 // In Go 1, .999... was completely ignored in the format, meaning the first two 159 // cases would succeed, but the next four would not. Go 1.1 accepts all six. 160 {"", "2006-01-02 15:04:05.9999 -0700 MST", "2010-02-04 21:00:57 -0800 PST", true, false, 1, 0}, 161 {"", "2006-01-02 15:04:05.999999999 -0700 MST", "2010-02-04 21:00:57 -0800 PST", true, false, 1, 0}, 162 {"", "2006-01-02 15:04:05.9999 -0700 MST", "2010-02-04 21:00:57.0123 -0800 PST", true, false, 1, 4}, 163 {"", "2006-01-02 15:04:05.999999999 -0700 MST", "2010-02-04 21:00:57.0123 -0800 PST", true, false, 1, 4}, 164 {"", "2006-01-02 15:04:05.9999 -0700 MST", "2010-02-04 21:00:57.012345678 -0800 PST", true, false, 1, 9}, 165 {"", "2006-01-02 15:04:05.999999999 -0700 MST", "2010-02-04 21:00:57.012345678 -0800 PST", true, false, 1, 9}, 166 167 // issue 4502. 168 {"", StampNano, "Feb 4 21:00:57.012345678", false, false, -1, 9}, 169 {"", "Jan _2 15:04:05.999", "Feb 4 21:00:57.012300000", false, false, -1, 4}, 170 {"", "Jan _2 15:04:05.999", "Feb 4 21:00:57.012345678", false, false, -1, 9}, 171 {"", "Jan _2 15:04:05.999999999", "Feb 4 21:00:57.0123", false, false, -1, 4}, 172 {"", "Jan _2 15:04:05.999999999", "Feb 4 21:00:57.012345678", false, false, -1, 9}, 173 } 174 175 func TestParse(t *testing.T) { 176 for _, test := range parseTests { 177 time, err := Parse(test.format, test.value) 178 if err != nil { 179 t.Errorf("%s error: %v", test.name, err) 180 } else { 181 checkTime(time, &test, t) 182 } 183 } 184 } 185 186 func TestParseInSydney(t *testing.T) { 187 loc, err := LoadLocation("Australia/Sydney") 188 if err != nil { 189 t.Fatal(err) 190 } 191 192 // Check that Parse (and ParseInLocation) understand 193 // that Feb EST and Aug EST are different time zones in Sydney 194 // even though both are called EST. 195 t1, err := ParseInLocation("Jan 02 2006 MST", "Feb 01 2013 EST", loc) 196 if err != nil { 197 t.Fatal(err) 198 } 199 t2 := Date(2013, February, 1, 00, 00, 00, 0, loc) 200 if t1 != t2 { 201 t.Fatalf("ParseInLocation(Feb 01 2013 EST, Sydney) = %v, want %v", t1, t2) 202 } 203 _, offset := t1.Zone() 204 if offset != 11*60*60 { 205 t.Fatalf("ParseInLocation(Feb 01 2013 EST, Sydney).Zone = _, %d, want _, %d", offset, 11*60*60) 206 } 207 208 t1, err = ParseInLocation("Jan 02 2006 MST", "Aug 01 2013 EST", loc) 209 if err != nil { 210 t.Fatal(err) 211 } 212 t2 = Date(2013, August, 1, 00, 00, 00, 0, loc) 213 if t1 != t2 { 214 t.Fatalf("ParseInLocation(Aug 01 2013 EST, Sydney) = %v, want %v", t1, t2) 215 } 216 _, offset = t1.Zone() 217 if offset != 10*60*60 { 218 t.Fatalf("ParseInLocation(Aug 01 2013 EST, Sydney).Zone = _, %d, want _, %d", offset, 10*60*60) 219 } 220 } 221 222 func TestLoadLocationZipFile(t *testing.T) { 223 ForceZipFileForTesting(true) 224 defer ForceZipFileForTesting(false) 225 226 _, err := LoadLocation("Australia/Sydney") 227 if err != nil { 228 t.Fatal(err) 229 } 230 } 231 232 var rubyTests = []ParseTest{ 233 {"RubyDate", RubyDate, "Thu Feb 04 21:00:57 -0800 2010", true, true, 1, 0}, 234 // Ignore the time zone in the test. If it parses, it'll be OK. 235 {"RubyDate", RubyDate, "Thu Feb 04 21:00:57 -0000 2010", false, true, 1, 0}, 236 {"RubyDate", RubyDate, "Thu Feb 04 21:00:57 +0000 2010", false, true, 1, 0}, 237 {"RubyDate", RubyDate, "Thu Feb 04 21:00:57 +1130 2010", false, true, 1, 0}, 238 } 239 240 // Problematic time zone format needs special tests. 241 func TestRubyParse(t *testing.T) { 242 for _, test := range rubyTests { 243 time, err := Parse(test.format, test.value) 244 if err != nil { 245 t.Errorf("%s error: %v", test.name, err) 246 } else { 247 checkTime(time, &test, t) 248 } 249 } 250 } 251 252 func checkTime(time Time, test *ParseTest, t *testing.T) { 253 // The time should be Thu Feb 4 21:00:57 PST 2010 254 if test.yearSign >= 0 && test.yearSign*time.Year() != 2010 { 255 t.Errorf("%s: bad year: %d not %d", test.name, time.Year(), 2010) 256 } 257 if time.Month() != February { 258 t.Errorf("%s: bad month: %s not %s", test.name, time.Month(), February) 259 } 260 if time.Day() != 4 { 261 t.Errorf("%s: bad day: %d not %d", test.name, time.Day(), 4) 262 } 263 if time.Hour() != 21 { 264 t.Errorf("%s: bad hour: %d not %d", test.name, time.Hour(), 21) 265 } 266 if time.Minute() != 0 { 267 t.Errorf("%s: bad minute: %d not %d", test.name, time.Minute(), 0) 268 } 269 if time.Second() != 57 { 270 t.Errorf("%s: bad second: %d not %d", test.name, time.Second(), 57) 271 } 272 // Nanoseconds must be checked against the precision of the input. 273 nanosec, err := strconv.ParseUint("012345678"[:test.fracDigits]+"000000000"[:9-test.fracDigits], 10, 0) 274 if err != nil { 275 panic(err) 276 } 277 if time.Nanosecond() != int(nanosec) { 278 t.Errorf("%s: bad nanosecond: %d not %d", test.name, time.Nanosecond(), nanosec) 279 } 280 name, offset := time.Zone() 281 if test.hasTZ && offset != -28800 { 282 t.Errorf("%s: bad tz offset: %s %d not %d", test.name, name, offset, -28800) 283 } 284 if test.hasWD && time.Weekday() != Thursday { 285 t.Errorf("%s: bad weekday: %s not %s", test.name, time.Weekday(), Thursday) 286 } 287 } 288 289 func TestFormatAndParse(t *testing.T) { 290 const fmt = "Mon MST " + RFC3339 // all fields 291 f := func(sec int64) bool { 292 t1 := Unix(sec, 0) 293 if t1.Year() < 1000 || t1.Year() > 9999 { 294 // not required to work 295 return true 296 } 297 t2, err := Parse(fmt, t1.Format(fmt)) 298 if err != nil { 299 t.Errorf("error: %s", err) 300 return false 301 } 302 if t1.Unix() != t2.Unix() || t1.Nanosecond() != t2.Nanosecond() { 303 t.Errorf("FormatAndParse %d: %q(%d) %q(%d)", sec, t1, t1.Unix(), t2, t2.Unix()) 304 return false 305 } 306 return true 307 } 308 f32 := func(sec int32) bool { return f(int64(sec)) } 309 cfg := &quick.Config{MaxCount: 10000} 310 311 // Try a reasonable date first, then the huge ones. 312 if err := quick.Check(f32, cfg); err != nil { 313 t.Fatal(err) 314 } 315 if err := quick.Check(f, cfg); err != nil { 316 t.Fatal(err) 317 } 318 } 319 320 type ParseTimeZoneTest struct { 321 value string 322 length int 323 ok bool 324 } 325 326 var parseTimeZoneTests = []ParseTimeZoneTest{ 327 {"gmt hi there", 0, false}, 328 {"GMT hi there", 3, true}, 329 {"GMT+12 hi there", 6, true}, 330 {"GMT+00 hi there", 3, true}, // 0 or 00 is not a legal offset. 331 {"GMT-5 hi there", 5, true}, 332 {"GMT-51 hi there", 3, true}, 333 {"ChST hi there", 4, true}, 334 {"MeST hi there", 4, true}, 335 {"MSDx", 3, true}, 336 {"MSDY", 0, false}, // four letters must end in T. 337 {"ESAST hi", 5, true}, 338 {"ESASTT hi", 0, false}, // run of upper-case letters too long. 339 {"ESATY hi", 0, false}, // five letters must end in T. 340 } 341 342 func TestParseTimeZone(t *testing.T) { 343 for _, test := range parseTimeZoneTests { 344 length, ok := ParseTimeZone(test.value) 345 if ok != test.ok { 346 t.Errorf("expected %t for %q got %t", test.ok, test.value, ok) 347 } else if length != test.length { 348 t.Errorf("expected %d for %q got %d", test.length, test.value, length) 349 } 350 } 351 } 352 353 type ParseErrorTest struct { 354 format string 355 value string 356 expect string // must appear within the error 357 } 358 359 var parseErrorTests = []ParseErrorTest{ 360 {ANSIC, "Feb 4 21:00:60 2010", "cannot parse"}, // cannot parse Feb as Mon 361 {ANSIC, "Thu Feb 4 21:00:57 @2010", "cannot parse"}, 362 {ANSIC, "Thu Feb 4 21:00:60 2010", "second out of range"}, 363 {ANSIC, "Thu Feb 4 21:61:57 2010", "minute out of range"}, 364 {ANSIC, "Thu Feb 4 24:00:60 2010", "hour out of range"}, 365 {"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59x01 2010", "cannot parse"}, 366 {"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59.xxx 2010", "cannot parse"}, 367 {"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59.-123 2010", "fractional second out of range"}, 368 // issue 4502. StampNano requires exactly 9 digits of precision. 369 {StampNano, "Dec 7 11:22:01.000000", `cannot parse ".000000" as ".000000000"`}, 370 {StampNano, "Dec 7 11:22:01.0000000000", "extra text: 0"}, 371 // issue 4493. Helpful errors. 372 {RFC3339, "2006-01-02T15:04:05Z07:00", `parsing time "2006-01-02T15:04:05Z07:00": extra text: 07:00`}, 373 {RFC3339, "2006-01-02T15:04_abc", `parsing time "2006-01-02T15:04_abc" as "2006-01-02T15:04:05Z07:00": cannot parse "_abc" as ":"`}, 374 {RFC3339, "2006-01-02T15:04:05_abc", `parsing time "2006-01-02T15:04:05_abc" as "2006-01-02T15:04:05Z07:00": cannot parse "_abc" as "Z07:00"`}, 375 {RFC3339, "2006-01-02T15:04:05Z_abc", `parsing time "2006-01-02T15:04:05Z_abc": extra text: _abc`}, 376 } 377 378 func TestParseErrors(t *testing.T) { 379 for _, test := range parseErrorTests { 380 _, err := Parse(test.format, test.value) 381 if err == nil { 382 t.Errorf("expected error for %q %q", test.format, test.value) 383 } else if strings.Index(err.Error(), test.expect) < 0 { 384 t.Errorf("expected error with %q for %q %q; got %s", test.expect, test.format, test.value, err) 385 } 386 } 387 } 388 389 func TestNoonIs12PM(t *testing.T) { 390 noon := Date(0, January, 1, 12, 0, 0, 0, UTC) 391 const expect = "12:00PM" 392 got := noon.Format("3:04PM") 393 if got != expect { 394 t.Errorf("got %q; expect %q", got, expect) 395 } 396 got = noon.Format("03:04PM") 397 if got != expect { 398 t.Errorf("got %q; expect %q", got, expect) 399 } 400 } 401 402 func TestMidnightIs12AM(t *testing.T) { 403 midnight := Date(0, January, 1, 0, 0, 0, 0, UTC) 404 expect := "12:00AM" 405 got := midnight.Format("3:04PM") 406 if got != expect { 407 t.Errorf("got %q; expect %q", got, expect) 408 } 409 got = midnight.Format("03:04PM") 410 if got != expect { 411 t.Errorf("got %q; expect %q", got, expect) 412 } 413 } 414 415 func Test12PMIsNoon(t *testing.T) { 416 noon, err := Parse("3:04PM", "12:00PM") 417 if err != nil { 418 t.Fatal("error parsing date:", err) 419 } 420 if noon.Hour() != 12 { 421 t.Errorf("got %d; expect 12", noon.Hour()) 422 } 423 noon, err = Parse("03:04PM", "12:00PM") 424 if err != nil { 425 t.Fatal("error parsing date:", err) 426 } 427 if noon.Hour() != 12 { 428 t.Errorf("got %d; expect 12", noon.Hour()) 429 } 430 } 431 432 func Test12AMIsMidnight(t *testing.T) { 433 midnight, err := Parse("3:04PM", "12:00AM") 434 if err != nil { 435 t.Fatal("error parsing date:", err) 436 } 437 if midnight.Hour() != 0 { 438 t.Errorf("got %d; expect 0", midnight.Hour()) 439 } 440 midnight, err = Parse("03:04PM", "12:00AM") 441 if err != nil { 442 t.Fatal("error parsing date:", err) 443 } 444 if midnight.Hour() != 0 { 445 t.Errorf("got %d; expect 0", midnight.Hour()) 446 } 447 } 448 449 // Check that a time without a Zone still produces a (numeric) time zone 450 // when formatted with MST as a requested zone. 451 func TestMissingZone(t *testing.T) { 452 time, err := Parse(RubyDate, "Thu Feb 02 16:10:03 -0500 2006") 453 if err != nil { 454 t.Fatal("error parsing date:", err) 455 } 456 expect := "Thu Feb 2 16:10:03 -0500 2006" // -0500 not EST 457 str := time.Format(UnixDate) // uses MST as its time zone 458 if str != expect { 459 t.Errorf("got %s; expect %s", str, expect) 460 } 461 } 462 463 func TestMinutesInTimeZone(t *testing.T) { 464 time, err := Parse(RubyDate, "Mon Jan 02 15:04:05 +0123 2006") 465 if err != nil { 466 t.Fatal("error parsing date:", err) 467 } 468 expected := (1*60 + 23) * 60 469 _, offset := time.Zone() 470 if offset != expected { 471 t.Errorf("ZoneOffset = %d, want %d", offset, expected) 472 } 473 } 474 475 type SecondsTimeZoneOffsetTest struct { 476 format string 477 value string 478 expectedoffset int 479 } 480 481 var secondsTimeZoneOffsetTests = []SecondsTimeZoneOffsetTest{ 482 {"2006-01-02T15:04:05-070000", "1871-01-01T05:33:02-003408", -(34*60 + 8)}, 483 {"2006-01-02T15:04:05-07:00:00", "1871-01-01T05:33:02-00:34:08", -(34*60 + 8)}, 484 {"2006-01-02T15:04:05-070000", "1871-01-01T05:33:02+003408", 34*60 + 8}, 485 {"2006-01-02T15:04:05-07:00:00", "1871-01-01T05:33:02+00:34:08", 34*60 + 8}, 486 {"2006-01-02T15:04:05Z070000", "1871-01-01T05:33:02-003408", -(34*60 + 8)}, 487 {"2006-01-02T15:04:05Z07:00:00", "1871-01-01T05:33:02+00:34:08", 34*60 + 8}, 488 } 489 490 func TestParseSecondsInTimeZone(t *testing.T) { 491 // should accept timezone offsets with seconds like: Zone America/New_York -4:56:02 - LMT 1883 Nov 18 12:03:58 492 for _, test := range secondsTimeZoneOffsetTests { 493 time, err := Parse(test.format, test.value) 494 if err != nil { 495 t.Fatal("error parsing date:", err) 496 } 497 _, offset := time.Zone() 498 if offset != test.expectedoffset { 499 t.Errorf("ZoneOffset = %d, want %d", offset, test.expectedoffset) 500 } 501 } 502 } 503 504 func TestFormatSecondsInTimeZone(t *testing.T) { 505 d := Date(1871, 9, 17, 20, 4, 26, 0, FixedZone("LMT", -(34*60+8))) 506 timestr := d.Format("2006-01-02T15:04:05Z070000") 507 expected := "1871-09-17T20:04:26-003408" 508 if timestr != expected { 509 t.Errorf("Got %s, want %s", timestr, expected) 510 } 511 }