Skip to content

Commit

Permalink
Merge pull request #187 from ptrkcsk/format-in-time-zone-with-offset
Browse files Browse the repository at this point in the history
test more ways of calling `formatInTimeZone()`
  • Loading branch information
marnusw committed Jul 9, 2022
2 parents d8f94af + ff0cb1b commit 847dce4
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions src/formatInTimeZone/test.js
Expand Up @@ -2,11 +2,44 @@ import assert from 'power-assert'
import formatInTimeZone from './index'

describe('formatInTimeZone', function () {
it('shifts the date to the zoned time and formats', function () {
describe('shifts the date to the zoned time and formats', function () {
var date = '1986-04-04T10:32:55.123Z'
var timeZone = 'Europe/Paris'
var result = formatInTimeZone(date, timeZone, "dd.MM.yyyy HH:mm 'UTC'xxx")
assert(result === '04.04.1986 12:32 UTC+02:00')
var tests = [
{
expected: '04.04.1986 12:32 UTC+02:00',
format: "dd.MM.yyyy HH:mm 'UTC'xxx",
formatType: 'offset',
timeZoneType: 'name',
timeZone: 'Europe/Paris',
},
{
expected: '04.04.1986 12:32 UTC+02:00',
format: "dd.MM.yyyy HH:mm 'UTC'xxx",
formatType: 'offset',
timeZoneType: 'offset',
timeZone: '+02:00',
},
{
expected: '04.04.1986 12:32 Central European Summer Time',
format: 'dd.MM.yyyy HH:mm zzzz',
formatType: 'name',
timeZoneType: 'name',
timeZone: 'Europe/Paris',
},
{
expected: '04.04.1986 12:32 Central European Summer Time',
format: 'dd.MM.yyyy HH:mm zzzz',
formatType: 'name',
timeZoneType: 'offset',
timeZone: '+02:00',
},
]

tests.forEach(function (test) {
it(`format type: ${test.formatType}, time zone type: ${test.timeZoneType}`, function () {
assert(formatInTimeZone(date, test.timeZone, test.format) === test.expected)
})
})
})

it('throws a RangeError on invalid time zones', function () {
Expand Down

0 comments on commit 847dce4

Please sign in to comment.