|
1 | 1 | import assert from 'power-assert' |
2 | | -import { enGB } from 'date-fns/locale/en-GB' |
3 | 2 | import { formatInTimeZone } from './index.js' |
| 3 | +import { setDefaultOptions } from 'date-fns' |
| 4 | +import { vi, enGB, de } from 'date-fns/locale' |
4 | 5 |
|
5 | 6 | describe('formatInTimeZone', function () { |
6 | 7 | it('treat date only string in the timezone specified in the options', function () { |
@@ -115,4 +116,58 @@ describe('formatInTimeZone', function () { |
115 | 116 | RangeError |
116 | 117 | ) |
117 | 118 | }) |
| 119 | + |
| 120 | + describe('setDefaultOptions for locale', function () { |
| 121 | + var date = '1986-04-04T10:32:55.123Z' |
| 122 | + var timeZone = 'Europe/Paris' |
| 123 | + var format = "PPPP 'UTC'xxx" |
| 124 | + var tests = [ |
| 125 | + { |
| 126 | + expected: 'Freitag, 4. April 1986 UTC+02:00', |
| 127 | + locale: de, |
| 128 | + }, |
| 129 | + { |
| 130 | + expected: 'Thứ Sáu, ngày 4 tháng 04 năm 1986 UTC+02:00', |
| 131 | + locale: vi, |
| 132 | + }, |
| 133 | + ] |
| 134 | + |
| 135 | + tests.forEach(function (test) { |
| 136 | + it(`locale: ${test.locale.code}`, function () { |
| 137 | + setDefaultOptions({ locale: test.locale }) |
| 138 | + assert.equal(formatInTimeZone(date, timeZone, format), test.expected) |
| 139 | + }) |
| 140 | + }) |
| 141 | + |
| 142 | + afterEach(() => { |
| 143 | + setDefaultOptions({ locale: undefined }) |
| 144 | + }) |
| 145 | + }) |
| 146 | + |
| 147 | + describe('setDefaultOptions for locale using tzIntlTimeZoneName', function () { |
| 148 | + var date = '1986-04-04T10:32:55.123Z' |
| 149 | + var timeZone = 'Europe/Paris' |
| 150 | + var format = 'dd.MM.yyyy HH:mm zzzz' |
| 151 | + var tests = [ |
| 152 | + { |
| 153 | + expected: '04.04.1986 12:32 Mitteleuropäische Sommerzeit', |
| 154 | + locale: de, |
| 155 | + }, |
| 156 | + { |
| 157 | + expected: '04.04.1986 12:32 Giờ mùa hè Trung Âu', |
| 158 | + locale: vi, |
| 159 | + }, |
| 160 | + ] |
| 161 | + |
| 162 | + tests.forEach(function (test) { |
| 163 | + it(`locale: ${test.locale.code}`, function () { |
| 164 | + setDefaultOptions({ locale: test.locale }) |
| 165 | + assert.equal(formatInTimeZone(date, timeZone, format), test.expected) |
| 166 | + }) |
| 167 | + }) |
| 168 | + |
| 169 | + afterEach(() => { |
| 170 | + setDefaultOptions({ locale: undefined }) |
| 171 | + }) |
| 172 | + }) |
118 | 173 | }) |
0 commit comments