Skip to content

Document the provider-specific date/time types #2973

Closed as not planned
Closed as not planned

Description

@acolombi

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.

Activity

  1. acolombi commented on May 21, 2020

    @acolombi
    Author

    The error msg clearly indicates the range that's allowed. If I add those many days,

    SELECT '1970-01-01'::DATE + 2932896;
    

    returns 9999-12-31

    When I switched to Noda I was hoping it would help us with these larger dates, per the comments in the documentation:

    NodaTime types can fully represent PostgreSQL's microsecond precision, and can represent dates outside the BCL's date limit (1AD-9999AD).

    I guess maybe the only limit that is improved is the lower bound? Thanks in advance for your help!

  2. roji commented on May 22, 2020

    @roji
    Member

    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 :)

  3. acolombi commented on May 26, 2020

    @acolombi
    Author

    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.

  4. YohDeadfall commented on May 26, 2020

    @YohDeadfall
    Contributor

    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.

  5. roji commented on May 27, 2020

    @roji
    Member

    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.

  6. changed the title [-]Dates in Postgres exceed the range available in NodaTime[/-] [+]Document the provider-specific date/time types[/+] on May 27, 2020
  7. added this to the Backlog milestone on May 27, 2020
  8. NinoFloris commented on Nov 20, 2025

    @NinoFloris
    Member

    These types have been dropped in #4138

  9. removed this from the Backlog milestone on Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions