Skip to content

Conversation

@rentianxiang
Copy link

Describe the bug
This is NOT a bug, it's just a feature i wish dayjs to have.

Expected behavior
So my project requires to translate between an ISO8601 date(year week weekday) and an actual Date object.
I found dayjs can translate Date to ISO8601 easily by using isoWeek and isoWeekday, but it does not support for the reverse action.
i tried with dayjs('2021', 'YYYY').isoWeek(1), but it returns the first isoweek of 2020 :(

So i added a new function under dayjs().startOf(), named "yearisoweek" (idk what it should be called..) to calculate the first isoWeek and isoWeekday for a given date (eg. dayjs('2021-04-25', 'YYYY-MM-DD).startOf('yearisoweek) == dayjs('2021-01-04, 'YYYY-MM-DD')), so it gives 2021W011. After it founds the first isoWeek and first isoWeekday of this year, it should be easy to calculate other ISO8601 dates by using the dayjs.add(week, 'week') and dayjs().add(day, 'day') functions.

In the test case, i found my method is not included in moment.js, it cannot be work with the startOf test in the badMutable.test.js, so i put them i isoWeek.test.js, under startOf yearisoweek

again the name is crap..cant figure a better one atm.

this is my first time doing a pr request, let me know where i could improve, thanks!

hope this could help you guys xD

Information

Day.js Version [v1.10.4]
OS: [macOS]
Browser [nodejs]
Time zone: [UTC+08:00]

@codecov
Copy link

codecov bot commented Apr 25, 2021

Codecov Report

Merging #1474 (6b01922) into dev (0fdac93) will decrease coverage by 0.05%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev    #1474      +/-   ##
==========================================
- Coverage   99.94%   99.88%   -0.06%     
==========================================
  Files         176      176              
  Lines        1770     1779       +9     
  Branches      411      414       +3     
==========================================
+ Hits         1769     1777       +8     
- Misses          1        2       +1     
Impacted Files Coverage Δ
src/index.js 99.45% <88.88%> (-0.55%) ⬇️

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 0fdac93...6b01922. Read the comment docs.

@iamkun
Copy link
Owner

iamkun commented May 26, 2021

Maybe we could support this as a plugin?

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