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

Improved "treat 0000-00-00 00:00:00 as nil Date" #1097

Merged
merged 1 commit into from May 19, 2011
Merged

Improved "treat 0000-00-00 00:00:00 as nil Date" #1097

merged 1 commit into from May 19, 2011

Conversation

kirillrdy
Copy link

It is not right to assume that if year is 0 then date is nil.
In our example we store dates in BC and 0000-01-01 is a valid date

So I've added check that for date to be nil year month and mday have to be 0.

I couldnt find a test for this case and wasnt sure where is a good place to add it.

Cheers,
Kirill R

@martinotten
Copy link

'"Year zero" does not exist in the widely used Gregorian calendar or in its predecessor, the Julian calendar. Under those systems, the year 1 BC is followed by AD 1.' http://en.wikipedia.org/wiki/0_(year)

Are you sure that 0000-01-01 is a valid date in BC?

@kirillrdy
Copy link
Author

Sorry, i should explain.

year 0000 is 1 BC
Postgres supports BC dates , as in it actually stores it as "0001-01-01 BC" which when queried as a date returns 0000-01-01, which then rails makes nil

hope it makes sence.

@kirillrdy
Copy link
Author

sorry one more thing
when you save Date.new(-1000,1,1) to rails Postgres stores it as "1001-01-01 BC"
It does conversion based on fact that year 0 doesnt exist. so first year before 1 AD is 1 BC, hence year 0 is 1 BC

@NZKoz
Copy link
Member

NZKoz commented May 19, 2011

Seems fine to me, Date.new(0,0,0) raises ArgumentError: invalid date but Date.new(0,1,1) returns a date.

I'm not sure that Date and DateTime will do sensible things with BC dates, but seems harmless enough to support the values if the database returns them.

NZKoz added a commit that referenced this pull request May 19, 2011
Improved "treat  0000-00-00 00:00:00 as nil Date"
@NZKoz NZKoz merged commit 2c08a74 into rails:master May 19, 2011
kamipo added a commit to kamipo/rails that referenced this pull request Feb 23, 2018
BC dates are supported by both date and datetime types.

https://www.postgresql.org/docs/current/static/datatype-datetime.html

Since rails#1097, new datetime allows year zero as 1 BC, but new date does
not. It should be allowed even in new date consistently.
kamipo added a commit that referenced this pull request Feb 28, 2018
BC dates are supported by both date and datetime types.

https://www.postgresql.org/docs/current/static/datatype-datetime.html

Since #1097, new datetime allows year zero as 1 BC, but new date does
not. It should be allowed even in new date consistently.
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.

None yet

3 participants