OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import "package:expect/expect.dart"; |
| 6 |
| 7 // Test DateTime timeZoneName and timeZoneOffset getters. |
| 8 |
| 9 testUtc() { |
| 10 var d = DateTime.parse("2012-03-04T03:25:38.123Z"); |
| 11 Expect.equals("UTC", d.timeZoneName); |
| 12 Expect.equals(0, d.timeZoneOffset.inSeconds); |
| 13 } |
| 14 |
| 15 testLocal() { |
| 16 checkOffset(String name, Duration offset) { |
| 17 // Timezone abbreviations are not in bijection with their timezones. |
| 18 // For example AST stands for "Arab Standard Time" (UTC+03), as well as |
| 19 // "Arabian Standard Time" (UTC+04), or PST stands for Pacific Standard Time |
| 20 // and Philippine Standard Time. |
| 21 // |
| 22 // Hardcode some common timezones. |
| 23 if (name == "CET") { |
| 24 Expect.equals(1, offset.inHours); |
| 25 } else if (name == "CEST") { |
| 26 Expect.equals(2, offset.inHours); |
| 27 } else if (name == "GMT") { |
| 28 Expect.equals(0, offset.inSeconds); |
| 29 } else if (name == "EST") { |
| 30 Expect.equals(-5, offset.inHours); |
| 31 } else if (name == "EDT") { |
| 32 Expect.equals(-4, offset.inHours); |
| 33 } else if (name == "PDT") { |
| 34 Expect.equals(-7, offset.inHours); |
| 35 } |
| 36 } |
| 37 |
| 38 var d = DateTime.parse("2012-01-02T13:45:23"); |
| 39 String name = d.timeZoneName; |
| 40 checkOffset(name, d.timeZoneOffset); |
| 41 |
| 42 d = DateTime.parse("2012-07-02T13:45:23"); |
| 43 name = d.timeZoneName; |
| 44 checkOffset(name, d.timeZoneOffset); |
| 45 } |
| 46 |
| 47 main() { |
| 48 testUtc(); |
| 49 testLocal(); |
| 50 } |
OLD | NEW |