Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

sevtdy
Copy link

@sevtdy sevtdy commented May 31, 2021

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
Copy link
Author

sevtdy commented May 31, 2021

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.

@iamkun
Copy link
Owner

iamkun commented Jun 1, 2021

Thanks.

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

@sevtdy sevtdy closed this Jun 5, 2021
@sevtdy sevtdy reopened this Jun 5, 2021
@sevtdy sevtdy closed this Jun 9, 2021
@sevtdy sevtdy reopened this Jun 9, 2021
@sevtdy sevtdy closed this Jun 14, 2021
@sevtdy sevtdy reopened this Jun 14, 2021
@sevtdy sevtdy closed this Jun 28, 2021
@sevtdy sevtdy reopened this Jun 28, 2021
@iamkun
Copy link
Owner

iamkun commented Jun 28, 2021

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

@sevtdy
Copy link
Author

sevtdy commented Jun 28, 2021

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

still talking to Travis support 🥲

@sevtdy sevtdy closed this Jun 28, 2021
@sevtdy sevtdy reopened this Jun 28, 2021
@codecov
Copy link

codecov bot commented Jun 28, 2021

Codecov Report

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

❗ 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

@sevtdy
Copy link
Author

sevtdy commented Jun 28, 2021

finally... CI work

@sevtdy sevtdy changed the title test trigger Travis-CI fix: incorrect startOf/endOf behavior with +00:00 timezone Jun 28, 2021
@sevtdy
Copy link
Author

sevtdy commented Apr 25, 2022

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

@iamkun
Copy link
Owner

iamkun commented Apr 26, 2022

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

@sevtdy
Copy link
Author

sevtdy commented Dec 5, 2022

@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

const withoutTz = d(this.format('YYYY-MM-DD HH:mm:ss:SSS'))
const startOfWithoutTz = oldStartOf.call(withoutTz, units, startOf)
return startOfWithoutTz.tz(this.$x.$timezone, true)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants