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

Incorrect Parse of 0001-01-01 00:00:00 #232

Closed
lesichkovm opened this issue Apr 1, 2024 · 7 comments
Closed

Incorrect Parse of 0001-01-01 00:00:00 #232

lesichkovm opened this issue Apr 1, 2024 · 7 comments
Labels
Bug Report a reproducible bug or regression

Comments

@lesichkovm
Copy link

lesichkovm commented Apr 1, 2024

Hello,

I encountered an issue with the following code:

0001-01-01 00:00:00 +0000 GMT

golang version: 1.22 (latest)

carbon version: 2.3.10 (latest)

time zone: GMT

I expected to get:

0001-01-01 00:00:00

But I actually get:

nothing

Example of issue:
https://play.golang.com/p/L6HDUXlCDEz

How it is supposed to work:
image

Thanks!

@lesichkovm lesichkovm added the Bug Report a reproducible bug or regression label Apr 1, 2024
@gouguoyin
Copy link
Member

gouguoyin commented Apr 1, 2024

After testing, in golang, 0001-01-01 00:00:00+0000 GMT is a zero value, but 0000-01-01 00:00:00+0000 GMT or 0002-01-01 00:00:00+0000 GMT is not

image

https://play.golang.com/p/Ozr7GaWc0sD

@lesichkovm
Copy link
Author

This looks very wrong. According to AI:

"0000-01-01 00:00:00" is not a valid date according to the most common date and time  standards. Here's why: 
Year Zero Doesn't Exist: Our calendar system doesn't have a year zero. There was no year 0 between 1 BC and 1 AD.

@lesichkovm
Copy link
Author

We should add support for '0001-01-01 00:00:00' to Carbon, as it is a valid datetime, and can be saved in i.e. MySQL. For instance, when getting the data from the database it reads as '0001-01-01 00:00:00', but once it is passed into Carbon it gets blank.

@lesichkovm
Copy link
Author

After testing, in golang, 0001-01-01 00:00:00+0000 GMT is a zero value, but 0000-01-01 00:00:00+0000 GMT or 0002-01-01 00:00:00+0000 GMT is not

Your tests will pass if you update the time layout:

https://play.golang.com/p/AUKnroJAxlj

@gouguoyin
Copy link
Member

After testing, in golang, 0001-01-01 00:00:00+0000 GMT is a zero value, but 0000-01-01 00:00:00+0000 GMT or 0002-01-01 00:00:00+0000 GMT is not

Your tests will pass if you update the time layout:

https://play.golang.com/p/AUKnroJAxlj

The layout does not match the time string,the layout contains a time zone, but the time string does not

@lesichkovm
Copy link
Author

Sorted by using 0002-01-01 00:00:00 which is the earliest valid date

@gouguoyin
Copy link
Member

V2.3.11 has been optimized and released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report a reproducible bug or regression
Development

No branches or pull requests

2 participants