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

Can't input negative years #2636

Closed
willismonroe opened this issue Apr 23, 2024 · 8 comments · Fixed by #2640
Closed

Can't input negative years #2636

willismonroe opened this issue Apr 23, 2024 · 8 comments · Fixed by #2640

Comments

@willismonroe
Copy link

Describe the bug
I'm trying to work with negative years in a mermaid-js gantt chart but tracing down their date parsing lead me to dayjs. Right now I can get a negative year to display by subtracting years from a positive year date, but there seems to be no way to parse a negative year from the outset.

Expected behavior
I would like to be able to enter dayjs('-2600') and get (NB I don't know if it's a friday) Fri, 01 Jan -2600 00:00:00 GMT.

Information

  • Day.js Version: 1.11.10
  • OS: Linux
  • Browser: Chrome 124
@willismonroe
Copy link
Author

I know this is potentially not easy given the Julian/Gregorian change, but it would be very useful!

@klm-turing
Copy link
Contributor

HI @willismonroe ,
I went through your issue and here's what I've come up with so far

dayjs('-2006').toDate() ==> Wed Jan 01 -2600 00:00:00 GMT-0016 (Greenwich Mean Time).

Is this enough for you? Do you have any other use cases you'd like to test?

@willismonroe
Copy link
Author

I just tried this on a REPL and got the same result as earlier:
image

This is version 1.11.10 btw

@willismonroe
Copy link
Author

Sorry @klm-turing were you showing the output of a proposed fix? If so, that's great. No other issues I'd like to test at the moment, as I mentioned earlier there are quite a few edge cases extra that would be worth looking into, but even just having negative years is a huge improvement.

@klm-turing
Copy link
Contributor

@willismonroe I wanted to know if it was enough for you first.

I linked a PR 2640. Test it and let me know

Screenshot from 2024-04-26 16-49-29

@iamkun
Copy link
Owner

iamkun commented Apr 27, 2024

Maybe it will be better to be implemented via a plugin.
IMHO, this might be a project logic, not a common one in dayjs?

@klm-turing
Copy link
Contributor

klm-turing commented Apr 27, 2024

@iamkun nice touch, I will do that

@klm-turing
Copy link
Contributor

@iamkun The plugin is done, If you have time, Please have a look.

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 a pull request may close this issue.

3 participants