Skip to content

Commit

Permalink
Merge branch 'format-timezone' into combined
Browse files Browse the repository at this point in the history
  • Loading branch information
prantlf committed Sep 18, 2018
2 parents 561fc49 + 19f3f70 commit 6021a21
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
34 changes: 24 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-uglify": "^6.0.0",
"size-limit": "^0.20.0",
"timezone-support": "^1.2.1",
"timezone-support": "^1.3.0",
"typescript": "^3.0.3"
},
"dependencies": {}
Expand Down
4 changes: 3 additions & 1 deletion src/plugin/timeZone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { findTimeZone, setTimeZone, getZonedTime } from 'timezone-support'
import { FORMAT_DEFAULT } from '../../constant'

function updateTime(instance, {
year, month, day, hours, minutes, epoch, zone
year, month, day, dayOfWeek, hours, minutes, epoch, zone
}, convertTimeZone) {
const date = instance.$d
// Update the Date object with the epoch time from the date
Expand All @@ -14,6 +14,7 @@ function updateTime(instance, {
instance.$Y = year
instance.$M = month - 1
instance.$D = day
instance.$W = dayOfWeek
instance.$H = hours
instance.$m = minutes
const { abbreviation, offset } = zone
Expand All @@ -25,6 +26,7 @@ function updateTime(instance, {
instance.$Y = date.getFullYear()
instance.$M = date.getMonth()
instance.$D = date.getDate()
instance.$W = date.getDay()
instance.$H = date.getHours()
instance.$m = date.getMinutes()
}
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/timeZone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ it('Fail constructing with an invalid time zone', () => {

it('Format date converted to other time zone', () => {
const input = '2018-09-02T21:01:22Z'
const format = 'D.M YYYY H:mm:ss [GMT]ZZ (z)'
const format = 'd, D.M YYYY H:mm:ss [GMT]ZZ (z)'
const timeZone = 'Europe/Berlin'
const output = '2.9 2018 23:01:22 GMT+0200 (CEST)'
const output = '0, 2.9 2018 23:01:22 GMT+0200 (CEST)'
expect(dayjs(input).format(format, { timeZone })).toEqual(output)
expect(moment(input).tz(timeZone).format(format)).toEqual(output)
})
Expand Down

0 comments on commit 6021a21

Please sign in to comment.