Is Npgsql.EnableLegacyTimestampBehavior going to be removed in a next version?

See original GitHub issue

The new behavior, frankly, makes no sense to me. We already use UTC everywhere for System.DateTime, and each date is always passed around as UTC, without any time zone modifications, until it’s necessary for a particular user in a particular time zone. The old Npgsql version also just took the date and sent it to the database as is. The new version does some weird arithmetics with the local time zone of the machine where the code’s running (UTC everywhere is used specifically not to think about this local time zone, which is irrelevant for web apps and such!) instead of just sending the date as is. And if the column still has timestamp without time zone type, the value sent by Npgsql, like 2021-12-28 10:00:00+10, gets truncated to just 2021-12-28 10:00:00, the value that appears nowhere in the .NET code that generated and processed the value 2021-12-28 00:00:00 UTC.

The only good part of the new behavior is probably exceptions thrown when Npgsql gets unexpected non-UTC dates, but in the context even that is bad, since it prevents using the new Npgsql so that dates are treated as UTC and they’re not modified when being written.

Is the old behavior going to be supported going forward, or the new behavior will be forced on us?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
monty241commented, Jan 5, 2022

Yes, there are many real-world situations; I prefer that UPS tells me by mail in my clock time when a package from Greece will arrive 😉

When tables are created using our engine, it is timestamp without timezone. For the rest we will probably make it work again and forward the real business decisions to end users.

1reaction
Brarcommented, Dec 29, 2021

I prefer my database to be dumb and reliable storage that just stores the data as is, and let the client app deal with such complex issues as time zones.

To me that really sounds like you’d want to set TimeZone to GMT. In effect this even removes the difference between timestamp without time zone and timestamp with time zone and renders your database to being just a dumb storage that just stores the data as they are passed without doing any implicit conversions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Date and Time Handling
In versions prior to 6.0 (or when Npgsql.EnableLegacyTimestampBehavior is enabled), DateTime is always written as timestamp without time zone . 2 In versions...
Read more >
Npgsql 6.0 Release Notes
The Npgsql.LegacyPostgis plugin, which mapped legacy Npgsql types to PostGIS, has been removed and no longer ships (#3962). Use Npgsql.
Read more >
Cannot write DateTime with Kind=UTC to PostgreSQL type ...
A. Solved by adding. AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); to the Startup Configure method.
Read more >
Datetime error with .NET 6 and PostgreSQL - Duong's Blog
NET 6, I ran into an datetime issue with the latest npgsql efcore provider. Today, we will look at the cause and try...
Read more >
Cannot write DateTime with Kind=Local to PostgreSQL ...
As a current workaround, Npgsql provides Npgsql.EnableLegacyTimestampBehavior switch which reverts back DateTime behaviour to previous version, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found