dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

fix: incorrect startOf/endOf behavior with +00:00 timezone

Open sevtdy opened this issue 4 years ago • 9 comments

fix: incorrect startOf/endOf behavior with +00:00 timezone

assume I'm in +08:00, when I parse time string with any regions in +00:00(like UTC, Africa/Abidjan), got the incorrect result

example: incorrect in dayjs:

dayjs.tz('2021-04-01', 'Asia/Hong_Kong').endOf('day').format()
// "2021-04-01T23:59:59+08:00"
dayjs.tz('2021-04-01', 'Africa/Abidjan').endOf('day').format()
// "2021-04-01T15:59:59Z"
dayjs.tz('2021-04-01', 'UTC').endOf('day').format()
// "2021-04-01T15:59:59Z"

expect work like moment

moment.tz('2021-04-01', 'Asia/Hong_Kong').endOf('day').format()
// "2021-04-01T23:59:59+08:00"
moment.tz('2021-04-01', 'Africa/Abidjan').endOf('day').format()
// "2021-04-01T23:59:59Z"
moment.tz('2021-04-01', 'UTC').endOf('day').format()
// "2021-04-01T23:59:59Z"

clone form #1506

sevtdy avatar May 31 '21 15:05 sevtdy

sorry for open this PR multi-time, look like there is some problem with Travis-CI and I'm trying to solve this with Travis support, this PR is a test for Travis support.

sevtdy avatar May 31 '21 15:05 sevtdy

Thanks.

It is odd that the PR sent from your account could not trigger the CI. But the rest looks fine.

iamkun avatar Jun 01 '21 04:06 iamkun

I run the npm test on my locale machine and it fails with some errors.

iamkun avatar Jun 28 '21 06:06 iamkun

I pass all the tests on my machine, can you share the error?

still talking to Travis support 🥲

sevtdy avatar Jun 28 '21 08:06 sevtdy

Codecov Report

Merging #1512 (2f1490b) into dev (b3ab757) will not change coverage. The diff coverage is n/a.

:exclamation: Current head 2f1490b differs from pull request most recent head e49ecaa. Consider uploading reports for the commit e49ecaa to get more accurate results

@@            Coverage Diff             @@
##               dev     #1512    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          183       176     -7     
  Lines         2111      1973   -138     
  Branches       554       501    -53     
==========================================
- Hits          2111      1973   -138     
Impacted Files Coverage Δ
src/plugin/timezone/index.js 100.00% <ø> (ø)

... and 21 files with indirect coverage changes

codecov[bot] avatar Jun 28 '21 13:06 codecov[bot]

finally... CI work

sevtdy avatar Jun 28 '21 13:06 sevtdy

@iamkun this PR has been open for a long time, just want to know dayjs considers this behavior normal or a bug?

sevtdy avatar Apr 25 '22 02:04 sevtdy

According to your fix, is that mean, we should not update the startOf func in a timezone plugin, and the problem is solved?

iamkun avatar Apr 26 '22 01:04 iamkun

@iamkun hi, It appears that this issue still exists. I update the code with latest version, would be great you can take a look on this.

reply your last comment: yes, I think we should not update startOf func in a timezone plugin

I found that these line break $D,$H...etc https://github.com/iamkun/dayjs/blob/1e9ba761ff4e3f2759106dfe1aa9054d5826451c/src/plugin/timezone/index.js#L123-L125

dayjs.tz('2021-05-10 00:00:00', 'UTC')
$d: Mon May 10 2021 00:08:00 GMT+0800 (China Standard Time)
$D: 10
$H: 0
$L: 'en'
$m: 0
$M: 4
$ms: 0
$s: 0
$u: undefined
$W: 1
$x: {}
$y: 2021

// startOfWithoutTz.tz(this.$x.$timezone, true) 
$d: Mon May 10 2021 00:00:00 GMT+0800 (China Standard Time)
$D: 9
$H: 16
$L: 'en'
$m: 0
$M: 4
$ms: 0
$offset: 0
$s: 0
$u: true
$W: 0
$x: {$timezone: 'UTC'}
$y: 2021

then format func will return incorrect format string

sevtdy avatar Dec 05 '22 15:12 sevtdy