-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
TimeZone - a plugin with time zone support for parsing and formatting strings #325
Conversation
The build fails only on Node.js 6, because of the usage of $ npm run build
> dayjs@0.0.0-development build /home/travis/build/iamkun/dayjs
> cross-env BABEL_ENV=build node build && npm run size
/home/travis/build/iamkun/dayjs/build/index.js:13
async function build(option) {
^^^^^^^^
SyntaxError: Unexpected token function |
b0e8925
to
6ef09ca
Compare
Codecov Report
@@ Coverage Diff @@
## master #325 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 32 33 +1
Lines 386 441 +55
Branches 53 63 +10
=====================================
+ Hits 386 441 +55
Continue to review full report at Codecov.
|
we build |
Add test for parsing a string with time zone.
a4aa732
to
c8f6314
Compare
Oh, I am sorry, @iamkun. I implemented other workaround for not having the built files for testing. I will need to figure out the code coverage yet, which does not show me any report. |
@prantlf you may could run |
c8f6314
to
4b5c7d5
Compare
Yes, that helped, thanks! :-) I think, that I confused codecov by rebasing the PR branch to the current master and forcing the re-push. |
4b5c7d5
to
dfb647e
Compare
* Use the timezone-support module to get a lightweight time zone support. * Construct Dayjs from a zone-less string and an explit time zone. * Format a string with Dayjs converted to other time zone.
dfb647e
to
505b201
Compare
It would be possible to bundle the timezone-support module to the timeZone plugin. It is a single-file dependency.
Upgrade timezone-support to 1.3.0 suporting dayOfWeek.
Codecov Report
@@ Coverage Diff @@
## master #325 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 32 33 +1
Lines 386 440 +54
Branches 53 63 +10
=====================================
+ Hits 386 440 +54
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #325 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 32 33 +1
Lines 386 442 +56
Branches 53 63 +10
=====================================
+ Hits 386 442 +56
Continue to review full report at Codecov.
|
3 similar comments
Codecov Report
@@ Coverage Diff @@
## master #325 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 32 33 +1
Lines 386 442 +56
Branches 53 63 +10
=====================================
+ Hits 386 442 +56
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #325 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 32 33 +1
Lines 386 442 +56
Branches 53 63 +10
=====================================
+ Hits 386 442 +56
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #325 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 32 33 +1
Lines 386 442 +56
Branches 53 63 +10
=====================================
+ Hits 386 442 +56
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #325 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 32 33 +1
Lines 386 442 +56
Branches 53 63 +10
=====================================
+ Hits 386 442 +56
Continue to review full report at Codecov.
|
2 similar comments
Codecov Report
@@ Coverage Diff @@
## master #325 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 32 33 +1
Lines 386 442 +56
Branches 53 63 +10
=====================================
+ Hits 386 442 +56
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #325 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 32 33 +1
Lines 386 442 +56
Branches 53 63 +10
=====================================
+ Hits 386 442 +56
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #325 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 32 44 +12
Lines 386 481 +95
Branches 53 65 +12
=====================================
+ Hits 386 481 +95
Continue to review full report at Codecov.
|
@pedro-mass, true, I ignored the day of the week in the original submission. I added it by the latest update. All properties of the |
@prantlf This looks awesome, thanks for the hard work and contribution! |
Thank you! Let's see how it goes on :-) I was thinking about introducing an interface compatible with Moment.js: // Alternative to the constructor:
// dayjs('2018-09-29 21:34', { timeZone: 'Europe/Berlin' })
dayjs.tz('2018-09-29 21:34', 'Europe/Berlin')
// Convert an existing Day.js instance to other time zone
dayjs().tz('Europe/Berlin') The alternative to the constructor means no problem to the further usage. You might question if it is worth adding, because you need to pass the time zone as a parameter anyway, unlike the static method The time zone conversion for a Day.js instance may confuse the end-user. Day.js stores a
The first approach would be interesting to prototype. It could turn up lightweight and quick. I chose the third approach, because it was not intrusive, it was feasible as a plugin and the interface could be kept if the first approach won later. However, The third approach does store the time zone information publicly in a |
@prantlf Thanks for that great contribution! The interface compatible with Moment.js would be very great. 👏 |
@aralroca, I'm afraid, that I went for the option 3 from my comment above, which doesn't allow implementing the interface fully compatible with Moment.js... :'-{ I could implement the static The trouble with the static const date = dayjs.tz('2018-09-29 21:34', 'Europe/Berlin')
// Some code here, or the date may be passed to a distant function
const output = date.format('DD/MM/YYYY') What would you expect from such |
Hi, I'm inquiring to the status of this PR. Would be incredibly useful to have timezone support in dayjs. Thanks. |
curious about status too |
@danielb2 You might not need dayjs. https://caniuse.com/#search=datetimeformat For older browsers, there's a polyfill (npm module |
Any Update? I can't wait for this plugin. |
This pr introduced a heavy dependency which is not really suitable to dayjs. We will introduce a time zone plugin base on
|
Day.js Time Zone Plugin https://day.js.org/docs/en/timezone/timezone |
|
||
| Format | Output | Description | | ||
| ------ | ------ | ----------------------- | | ||
| `z` | CEST | Time zone abbreviation | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamkun any chance to implement this as part of the timezone plugin?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Day.js Time Zone Plugin https://day.js.org/docs/en/timezone/timezone
Attempts to implement #323 by introducing the TimeZone plugin.
It uses the IANA time zone database, packed to a JSON format by moment-time-zone and with a simple interface to it provided by timezone-support.
Although the
Intl
time zone support has been introduced, there are still browsers or platforms, which do not support it and would not mind "paying for" the support by including more JavaScript code. The size of the time zone supporting library without the Day.js plugin: source 185 kB, minified 182 kB, gzipped 24 kB.I can imagine adding support for remembering the time zone for future calls to
.format()
as discussed at #46.Time zone conversions are possible already without an additional API. Jut use UTC date from one Day.js object and format it the target time zone using the other (or the same) Day.js object.