OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 Google Inc. All rights reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style |
| 5 * license that can be found in the LICENSE file or at |
| 6 * https://developers.google.com/open-source/licenses/bsd |
| 7 */ |
| 8 |
| 9 part of charted.test.locale; |
| 10 |
| 11 testTimeFormat() { |
| 12 EnUsLocale locale = new EnUsLocale(); |
| 13 |
| 14 group('TimeFormat.apply()', () { |
| 15 test('correctly applies %a and %A', () { |
| 16 TimeFormat format = locale.timeFormat('%a %A'); |
| 17 expect(format.apply(new DateTime(2014, 3, 9)), equals('Sun Sunday')); |
| 18 expect(format.apply(new DateTime(2014, 3, 10)), equals('Mon Monday')); |
| 19 expect(format.apply(new DateTime(2014, 3, 15)), equals('Sat Saturday')); |
| 20 }); |
| 21 test('correctly applies %b and %B', () { |
| 22 TimeFormat format = locale.timeFormat('%b %B'); |
| 23 expect(format.apply(new DateTime(2014, 1)), equals('Jan January')); |
| 24 expect(format.apply(new DateTime(2014, 2)), equals('Feb February')); |
| 25 expect(format.apply(new DateTime(2014, 3)), equals('Mar March')); |
| 26 }); |
| 27 test('correctly applies %c', () { |
| 28 TimeFormat format = locale.timeFormat('%c'); |
| 29 expect(format.apply(new DateTime(2014, 2, 3, 4, 15, 32)), |
| 30 equals('Mon Feb 3 04:15:32 2014')); |
| 31 }); |
| 32 test('correctly applies %d', () { |
| 33 TimeFormat format = locale.timeFormat('%d'); |
| 34 expect(format.apply(new DateTime(2014, 2, 3)), equals('03')); |
| 35 expect(format.apply(new DateTime(2014, 2, 13)), equals('13')); |
| 36 }); |
| 37 test('correctly applies %e', () { |
| 38 TimeFormat format = locale.timeFormat('%e'); |
| 39 expect(format.apply(new DateTime(2014, 2, 3)), equals('3')); |
| 40 expect(format.apply(new DateTime(2014, 2, 13)), equals('13')); |
| 41 }); |
| 42 test('correctly applies %H and %I', () { |
| 43 TimeFormat format = locale.timeFormat('%H %I'); |
| 44 expect(format.apply(new DateTime(2014, 2, 3, 5)), equals('05 05')); |
| 45 expect(format.apply(new DateTime(2014, 2, 3, 13)), equals('13 01')); |
| 46 }); |
| 47 test('correctly applies %j', () { |
| 48 TimeFormat format = locale.timeFormat('%j'); |
| 49 expect(format.apply(new DateTime(2014, 1, 1)), equals('001')); |
| 50 expect(format.apply(new DateTime(2014, 6, 13)), equals('164')); |
| 51 expect(format.apply(new DateTime(2014, 12, 31)), equals('365')); |
| 52 }); |
| 53 test('correctly applies %m', () { |
| 54 TimeFormat format = locale.timeFormat('%m'); |
| 55 expect(format.apply(new DateTime(2014, 3)), equals('03')); |
| 56 expect(format.apply(new DateTime(2014, 11)), equals('11')); |
| 57 }); |
| 58 test('correctly applies %M', () { |
| 59 TimeFormat format = locale.timeFormat('%M'); |
| 60 expect(format.apply(new DateTime(2014, 2, 3, 1, 3)), equals('03')); |
| 61 expect(format.apply(new DateTime(2014, 2, 3, 1, 59)), equals('59')); |
| 62 }); |
| 63 test('correctly applies %L', () { |
| 64 TimeFormat format = locale.timeFormat('%L'); |
| 65 expect(format.apply(new DateTime(14, 2, 3, 1, 3, 0, 23)), equals('023')); |
| 66 expect(format.apply(new DateTime(14, 2, 3, 1, 3, 0, 123)), equals('123')); |
| 67 }); |
| 68 test('correctly applies %p', () { |
| 69 TimeFormat format = locale.timeFormat('%p'); |
| 70 expect(format.apply(new DateTime(2014, 2, 3, 1)), equals('AM')); |
| 71 expect(format.apply(new DateTime(2014, 2, 3, 13)), equals('PM')); |
| 72 }); |
| 73 test('correctly applies %S', () { |
| 74 TimeFormat format = locale.timeFormat('%S'); |
| 75 expect(format.apply(new DateTime(2014, 2, 3, 1, 3, 1)), equals('01')); |
| 76 expect(format.apply(new DateTime(2014, 2, 3, 1, 3, 23)), equals('23')); |
| 77 }); |
| 78 test('correctly applies %x', () { |
| 79 TimeFormat format = locale.timeFormat('%x'); |
| 80 expect(format.apply(new DateTime(2014, 2, 3)), equals('02/03/2014')); |
| 81 }); |
| 82 test('correctly applies %X', () { |
| 83 TimeFormat format = locale.timeFormat('%X'); |
| 84 expect(format.apply(new DateTime(4, 2, 3, 1, 3, 15)), equals('01:03:15')); |
| 85 }); |
| 86 test('correctly applies %y and %Y', () { |
| 87 TimeFormat format = locale.timeFormat('%y %Y'); |
| 88 expect(format.apply(new DateTime(1904)), equals('04 1904')); |
| 89 expect(format.apply(new DateTime(2004)), equals('04 2004')); |
| 90 expect(format.apply(new DateTime(2094)), equals('94 2094')); |
| 91 }); |
| 92 test('correctly applies %%', () { |
| 93 TimeFormat format = locale.timeFormat('%%'); |
| 94 expect(format.apply(new DateTime(1904)), equals('%')); |
| 95 }); |
| 96 }); |
| 97 |
| 98 test('TimeFormat.parse()correctly parses string', () { |
| 99 TimeFormat format = locale.timeFormat('%x'); |
| 100 expect(format.parse("02/03/2014"), new isInstanceOf<DateTime>()); |
| 101 expect(() => format.parse("2014-02-03"), |
| 102 throwsA(new isInstanceOf<FormatException>())); |
| 103 }); |
| 104 |
| 105 var multiFormat = locale.timeFormat().multi([ |
| 106 [".%L", (d) => (d as DateTime).millisecond > 0], |
| 107 [":%S", (d) => (d as DateTime).second > 0], |
| 108 ["%Y", (d) => true] |
| 109 ]); |
| 110 |
| 111 test('TimeFormat.multi() correctly formats time string', () { |
| 112 expect(multiFormat(new DateTime(2014, 1, 1, 1, 1, 3, 123)), equals('.123')); |
| 113 expect(multiFormat(new DateTime(2014, 1, 1, 1, 1, 3)), equals(':03')); |
| 114 expect(multiFormat(new DateTime(2014)), equals('2014')); |
| 115 }); |
| 116 |
| 117 var iso = TimeFormat.iso(); |
| 118 test('TimeFormat.iso() correctly formats time string', () { |
| 119 expect(iso.apply(new DateTime(2014, 2, 3, 4, 5, 6, 123)), |
| 120 equals('2014-02-03T04:05:06.123Z')); |
| 121 }); |
| 122 |
| 123 var utc = locale.timeFormat().utc("%Y-%m-%d %H:%M:%S"); |
| 124 test('TimeFormat.iso() correctly formats time string', () { |
| 125 expect(utc.apply(new DateTime(2014, 2, 3, 4, 5, 6, 123)), |
| 126 equals('2014-02-03 04:05:06')); |
| 127 }); |
| 128 } |
OLD | NEW |