Skip to content

Commit

Permalink
Merge pull request #169 from zkruw/master
Browse files Browse the repository at this point in the history
Round tz offset correct
  • Loading branch information
marnusw committed Mar 25, 2022
2 parents 2f127f3 + 8316ce8 commit 7c6c09f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/format/formatters/index.js
Expand Up @@ -119,7 +119,7 @@ function formatTimezone(offset, dirtyDelimeter) {
var sign = offset > 0 ? '-' : '+'
var absOffset = Math.abs(offset)
var hours = addLeadingZeros(Math.floor(absOffset / 60), 2)
var minutes = addLeadingZeros(absOffset % 60, 2)
var minutes = addLeadingZeros(Math.floor(absOffset % 60), 2)
return sign + hours + delimeter + minutes
}

Expand Down
7 changes: 7 additions & 0 deletions src/format/test.js
Expand Up @@ -684,6 +684,13 @@ describe('format', function () {
const result = format(offsetDate, "yyyy-MM-dd h:mmaaaaa'm' xxx XXX OOO zzz", { timeZone })
assert.equal(result, '2020-10-31 9:37pm -05:00 -05:00 GMT-5 CDT')
})

it('https://github.com/marnusw/date-fns-tz/issues/168', () => {
const timeZone = 'Europe/Stockholm'
const dateInUTC = Date.UTC(1888, 11, 1)
const result = format(dateInUTC, "yyyy-MM-dd'T'HH:mm:ss.SSSxxx", { timeZone })
assert.equal(result, '1888-12-01T01:00:14.000+01:00')
})
})

describe('timestamp', function () {
Expand Down

0 comments on commit 7c6c09f

Please sign in to comment.