question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

quarter() difference from Moment

See original GitHub issue

Issuehunt badges

Describe 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 iamkun has been rewarded.

Backers (Total: $100.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
iamkuncommented, May 7, 2019

🎉 This issue has been resolved in version 1.8.14 🎉

The release is available on:

Your semantic-release bot 📦🚀

0reactions
issuehunt-app[bot]commented, Sep 16, 2019

@iamkun has rewarded $90.00 to @iamkun. See it on IssueHunt

  • 💰 Total deposit: $100.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $10.00
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found