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

feat: #965 add duration.format() #1202

Merged
merged 4 commits into from
Nov 24, 2020
Merged

feat: #965 add duration.format() #1202

merged 4 commits into from
Nov 24, 2020

Conversation

verzac
Copy link
Contributor

@verzac verzac commented Nov 10, 2020

Heya! This should close #965. Key things to note:

  • Is it okay to change REGEX_FORMAT to accept singular Ys? From what I've seen in the code in src/index.js, it seems like the original .format() ignores regex matches which are not in the const matches = { ... } variable, so this should be safe to do.
  • Single Y would be very useful, because you don't often display durations which has double-digit years. So you can do dayjs.duration(15, 'years').format('Y years has passed') === '15 years has passed'

Also, difference between the original dayjs.format() and this format:

  • No 'A'/'a' token (because you can't reason about meridians in durations)
  • No 'dddd' token
  • No 'ZZ' token

Not sure why commit 6545739 got dragged along as a change in the diff, but doesn't seem like any files are explicitly changed after I resync'd with upstream, so...

@codecov
Copy link

codecov bot commented Nov 10, 2020

Codecov Report

Merging #1202 (7ba0d19) into dev (9544ed2) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##               dev     #1202   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          174       174           
  Lines         1653      1657    +4     
  Branches       374       378    +4     
=========================================
+ Hits          1653      1657    +4     
Impacted Files Coverage Δ
src/constant.js 100.00% <100.00%> (ø)
src/plugin/duration/index.js 100.00% <100.00%> (ø)
src/plugin/customParseFormat/index.js 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9544ed2...7ba0d19. Read the comment docs.

@verzac
Copy link
Contributor Author

verzac commented Nov 14, 2020

Hola @iamkun, Is there anything missing from this PR, or perhaps something you're unsure of?

@iamkun
Copy link
Owner

iamkun commented Nov 14, 2020

Thanks. I'm just too busy to review this. Will do it in the coming week.

@iamkun iamkun merged commit 9a859a1 into iamkun:dev Nov 24, 2020
@linjiacheng
Copy link

when will this feat be released?

iamkun pushed a commit that referenced this pull request Dec 5, 2020
## [1.9.7](v1.9.6...v1.9.7) (2020-12-05)

### Bug Fixes

* add duration.format to format a Duration ([#1202](#1202)) ([9a859a1](9a859a1))
* Add function handling for relativeTime.future and relativeTime.past ([#1197](#1197)) ([ef1979c](ef1979c))
* avoid install installed plugin ([#1214](#1214)) ([a92eb6c](a92eb6c))
* avoid memory leak after installing a plugin too many times ([b8d2e32](b8d2e32))
* fix diff bug when UTC plugin enabled ([#1201](#1201)) ([9544ed2](9544ed2)), closes [#1200](#1200)
* fix startOf/endOf bug in timezone plugin ([#1229](#1229)) ([eb5fbc4](eb5fbc4))
* fix utc plugin diff edge case ([#1187](#1187)) ([971b3d4](971b3d4))
* update customParseFormat plugin to parse 2-digit offset ([#1209](#1209)) ([b56936a](b56936a)), closes [#1205](#1205)
* Update timezone plugin type definition ([#1221](#1221)) ([34cfb92](34cfb92))
@iamkun
Copy link
Owner

iamkun commented Dec 5, 2020

🎉 This PR is included in version 1.9.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

@iamkun iamkun added the released label Dec 5, 2020
andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this pull request May 10, 2022
## [1.9.7](iamkun/dayjs@v1.9.6...v1.9.7) (2020-12-05)

### Bug Fixes

* add duration.format to format a Duration ([#1202](iamkun/dayjs#1202)) ([9a859a1](iamkun/dayjs@9a859a1))
* Add function handling for relativeTime.future and relativeTime.past ([#1197](iamkun/dayjs#1197)) ([ef1979c](iamkun/dayjs@ef1979c))
* avoid install installed plugin ([#1214](iamkun/dayjs#1214)) ([a92eb6c](iamkun/dayjs@a92eb6c))
* avoid memory leak after installing a plugin too many times ([b8d2e32](iamkun/dayjs@b8d2e32))
* fix diff bug when UTC plugin enabled ([#1201](iamkun/dayjs#1201)) ([9544ed2](iamkun/dayjs@9544ed2)), closes [#1200](iamkun/dayjs#1200)
* fix startOf/endOf bug in timezone plugin ([#1229](iamkun/dayjs#1229)) ([eb5fbc4](iamkun/dayjs@eb5fbc4))
* fix utc plugin diff edge case ([#1187](iamkun/dayjs#1187)) ([971b3d4](iamkun/dayjs@971b3d4))
* update customParseFormat plugin to parse 2-digit offset ([#1209](iamkun/dayjs#1209)) ([b56936a](iamkun/dayjs@b56936a)), closes [#1205](iamkun/dayjs#1205)
* Update timezone plugin type definition ([#1221](iamkun/dayjs#1221)) ([34cfb92](iamkun/dayjs@34cfb92))
andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this pull request May 10, 2022
## [1.9.7](iamkun/dayjs@v1.9.6...v1.9.7) (2020-12-05)

### Bug Fixes

* add duration.format to format a Duration ([#1202](iamkun/dayjs#1202)) ([9a859a1](iamkun/dayjs@9a859a1))
* Add function handling for relativeTime.future and relativeTime.past ([#1197](iamkun/dayjs#1197)) ([ef1979c](iamkun/dayjs@ef1979c))
* avoid install installed plugin ([#1214](iamkun/dayjs#1214)) ([a92eb6c](iamkun/dayjs@a92eb6c))
* avoid memory leak after installing a plugin too many times ([b8d2e32](iamkun/dayjs@b8d2e32))
* fix diff bug when UTC plugin enabled ([#1201](iamkun/dayjs#1201)) ([9544ed2](iamkun/dayjs@9544ed2)), closes [#1200](iamkun/dayjs#1200)
* fix startOf/endOf bug in timezone plugin ([#1229](iamkun/dayjs#1229)) ([eb5fbc4](iamkun/dayjs@eb5fbc4))
* fix utc plugin diff edge case ([#1187](iamkun/dayjs#1187)) ([971b3d4](iamkun/dayjs@971b3d4))
* update customParseFormat plugin to parse 2-digit offset ([#1209](iamkun/dayjs#1209)) ([b56936a](iamkun/dayjs@b56936a)), closes [#1205](iamkun/dayjs#1205)
* Update timezone plugin type definition ([#1221](iamkun/dayjs#1221)) ([34cfb92](iamkun/dayjs@34cfb92))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How we can format the duration in dayjs.
4 participants