quarter() difference from Moment
See original GitHub issueDescribe the bug
My assumption is that quarter(value) works identically to that of MomentJS, but it doesn’t appear to be the case.
Expected behavior
let c1 = dayjs('2018-11-25')
let c2 = moment('2018-11-25');
console.log(`2018-11-25: DayJS quarter: ${c1.quarter()} (${c1.format(format)}), Moment quarter: ${c2.quarter()} (${c2.format(format)})`);
c1 = c1.quarter(3);
c2 = c2.quarter(3);
console.log(`quarter(3): DayJS quarter: ${c1.quarter()} (${c1.format(format)}), Moment quarter: ${c2.quarter()} (${c2.format(format)})`);
This is the output of the above:
2018-11-25: DayJS quarter: 4 (2018-11-25), Moment quarter: 4 (2018-11-25)
quarter(3): DayJS quarter: 2 (2019-05-25), Moment quarter: 3 (2018-08-25)
So applying quarter(3) does something weird. It’s not exactly adding three quarters, or I’d expect DayJS to return 2019-08-25.
However, this seems to work correctly:
let a1 = dayjs('2018-03-09')
let a2 = moment('2018-03-09');
console.log(`2018-03-09: DayJS quarter: ${a1.quarter()} (${a1.format(format)}), Moment quarter: ${a2.quarter()} (${a2.format(format)})`);
a1 = a1.quarter(3);
a2 = a2.quarter(3);
console.log(`quarter(3): DayJS quarter: ${a1.quarter()} (${a1.format(format)}), Moment quarter: ${a2.quarter()} (${a2.format(format)})`);
Output:
2018-03-09: DayJS quarter: 1 (2018-03-09), Moment quarter: 1 (2018-03-09)
quarter(3): DayJS quarter: 3 (2018-09-09), Moment quarter: 3 (2018-09-09)
Here is a reproduction on RunKit
Either this is a bug, or I’m misunderstanding how quarter(value) works. If it’s intentional that it works differently than MomentJS, it should be documented, as there’s nothing in the current documentation that it’s different.
Information
- Day.js Version:
1.8.13 - OS: MacOS
10.14.4 - Browser: Chrome
74.0.3729.131
IssueHunt Summary
iamkun has been rewarded.
Backers (Total: $100.00)
issuehunt ($100.00)
Submitted pull Requests
Tips
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on IssueHunt to raise funds.
IssueHunt has been backed by the following sponsors. Become a sponsor
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Moment.js: How do you get the difference between two ...
Here's my attempt. I use the year and the quarter to create a "compound" number. Then subtract these from each other:.
Read more >Moment.js moment().quarter() Method
The moment().quarter() method is used to get or set the quarter of the Moment object. There are 4 quarters in a year, hence...
Read more >Difference - momentjs.com - Read the Docs
If the moment is earlier than the moment you are passing to moment.fn.diff , the return value will be negative. var a =...
Read more >Moment.js | Docs
However, it can not be used to convert a Date object to a different time zone. ... Note: Moments are created at evaluation...
Read more >Moment.js: How do you get the difference between two ...
However, realize this will return the number of whole periods of 3 months each. This may or may not align to the boundaries...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

🎉 This issue has been resolved in version 1.8.14 🎉
The release is available on:
Your semantic-release bot 📦🚀
@iamkun has rewarded $90.00 to @iamkun. See it on IssueHunt