You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document the provider-specific date/time types #2973
I've got a scenario with a customer database that contains dates exceeding the range the NodaTime can represent, it would seem. I'm interested in workarounds or potential solutions to this problem. I can probably convince the customer to pull some of these dates back, but I'm curious if there is a more general solution available.
Stack trace:
System.AggregateException: One or more errors occurred. (One or more errors occurred. (Value should be in range [-4371222-2932896] (Parameter 'daysSinceEpoch')
Actual value was 3670690.))
---> System.AggregateException: One or more errors occurred. (Value should be in range [-4371222-2932896] (Parameter 'daysSinceEpoch')
Actual value was 3670690.)
---> System.ArgumentOutOfRangeException: Value should be in range [-4371222-2932896] (Parameter 'daysSinceEpoch')
Actual value was 3670690.
at NodaTime.Utility.Preconditions.ThrowArgumentOutOfRangeException[T](String paramName, T value, T minInclusive, T maxInclusive)
at NodaTime.CalendarSystem.GetYearMonthDayCalendarFromDaysSinceEpoch(Int32 daysSinceEpoch)
at NodaTime.Fields.FixedLengthDatePeriodField.Add(LocalDate localDate, Int32 value)
at Npgsql.NodaTime.DateHandler.Read(NpgsqlReadBuffer buf, Int32 len, FieldDescription fieldDescription)
at Npgsql.TypeHandling.NpgsqlTypeHandler`1.ReadAsObject(NpgsqlReadBuffer buf, Int32 len, FieldDescription fieldDescription)
at Npgsql.NpgsqlDataReader.GetValue(Int32 ordinal)
at Npgsql.NpgsqlDataReader.GetValues(Object[] values)
... and then our application stack, which you probably don't care about
Steps to reproduce
CREATE TABLE test_date (foo DATE);
INSERT INTO test_date VALUES ('1970-01-01'::DATE + 4000000);
SELECT * FROM test_date;
-- verify you have a single column, with a single row, with the value 12921-08-18
Then try to connect to read values from this table with Npgsql using NodaTime type bindings.
Back when I looked at this, I think there may have been other types whose ranges were better in NodaTime than they were in the BCL types - but indeed it seems that the upper bound on dates isn't.
If the point here is simply to represent an infinite point in the future, then PostgreSQL also has the notion of infinity and -infinity, which may be more suitable. You can pass Convert Infinity DateTime to make Npgsql return these as DateTime.MaxValue/MinValue (or LocalDate.MaxIsoValue/MinIsoValue). Technically Npgsql also has an NpgsqlDateTime which really should represent anything PostgreSQL can, but that type is slow and somewhat obsolete - I would not recommend using it.
Aside from that I can't really think of anything - if there's a valid, reasonable use case for needing dates beyond 9999, I'd certainly be interested in hearing about it :)
Yeah, our customer ended up just changing the date in their database to work around this. The code that I'm working on gets connected to database outside of my control. So I don't really have a say in what data gets thrown at us. I think my original change to Noda was motivated by some dates smaller than 1AD.
If I wanted to use NpgsqlDateTime are their some docs you can point me to to set that up?
Not sure there is much more to say on this issue. Maybe there are some docs to update? Other than that I think we can close this out. I just wanted to make sure I wasn't misunderstanding the limitations and what options were available to me.
NpgsqlDateTime is a driver specific type which should not be used in any public API, but it's okay to use it in internals. This type is handled only by the standard handler, so if you set up the Noda plugin it 's unavailable for now.
We have some documentation, but it's very poor, but the type has the same features as DateTime.
Note that we're considering dropping the custom date/time types - #2009. Cases like this, where values are out of range of both the BCL and NodaTime types, could be a reason to keep these types.
Aside from that yeah, as @YohDeadfall wrote, these types aren't well-documented. Am repurposing this issue to track that.
Activity
acolombi commentedon May 21, 2020
The error msg clearly indicates the range that's allowed. If I add those many days,
returns
9999-12-31When I switched to Noda I was hoping it would help us with these larger dates, per the comments in the documentation:
I guess maybe the only limit that is improved is the lower bound? Thanks in advance for your help!
roji commentedon May 22, 2020
Back when I looked at this, I think there may have been other types whose ranges were better in NodaTime than they were in the BCL types - but indeed it seems that the upper bound on dates isn't.
If the point here is simply to represent an infinite point in the future, then PostgreSQL also has the notion of
infinityand-infinity, which may be more suitable. You can passConvert Infinity DateTimeto make Npgsql return these as DateTime.MaxValue/MinValue (or LocalDate.MaxIsoValue/MinIsoValue). Technically Npgsql also has an NpgsqlDateTime which really should represent anything PostgreSQL can, but that type is slow and somewhat obsolete - I would not recommend using it.Aside from that I can't really think of anything - if there's a valid, reasonable use case for needing dates beyond 9999, I'd certainly be interested in hearing about it :)
acolombi commentedon May 26, 2020
Yeah, our customer ended up just changing the date in their database to work around this. The code that I'm working on gets connected to database outside of my control. So I don't really have a say in what data gets thrown at us. I think my original change to Noda was motivated by some dates smaller than 1AD.
If I wanted to use NpgsqlDateTime are their some docs you can point me to to set that up?
Not sure there is much more to say on this issue. Maybe there are some docs to update? Other than that I think we can close this out. I just wanted to make sure I wasn't misunderstanding the limitations and what options were available to me.
YohDeadfall commentedon May 26, 2020
NpgsqlDateTimeis a driver specific type which should not be used in any public API, but it's okay to use it in internals. This type is handled only by the standard handler, so if you set up the Noda plugin it 's unavailable for now.We have some documentation, but it's very poor, but the type has the same features as
DateTime.roji commentedon May 27, 2020
Note that we're considering dropping the custom date/time types - #2009. Cases like this, where values are out of range of both the BCL and NodaTime types, could be a reason to keep these types.
Aside from that yeah, as @YohDeadfall wrote, these types aren't well-documented. Am repurposing this issue to track that.
[-]Dates in Postgres exceed the range available in NodaTime[/-][+]Document the provider-specific date/time types[/+]NinoFloris commentedon Nov 20, 2025
These types have been dropped in #4138