Umbraco-CMS
Umbraco-CMS copied to clipboard
Time Zone issue on built in DateTime fields (CreateDate, UpdateDate etc...)
Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)
13.2.2
Bug summary
Built in DateTime properties like CreateDate
and UpdateDate
, return a DateTime with incorrect TimeZone and Daylight Savings information, when using a SQL Server database, which causes UTC conversions to be incorrect.
Specifics
I ran into this issue in v13.2.2, I have some code that shows the elapsed time since a Node has been Published, by converting the UpdateDate to UTC and subtracting it's Ticks from DateTime.UtcNow.Ticks, to get the time difference in seconds.
This logic all works fine, but the CreateDate and UpdateDate that Umbraco returns, is different depending on if I run SQLite or SQL Server Express.
Discord thread on this issue: https://discord.com/channels/869656431308189746/1232004629441679391 Public mirror: https://discord-chats.umbraco.com/t/18468992/v13-weird-timezone-issue-on-sql-server-express-vs-sqlite
Steps to reproduce
Here's a .zip of a demo project which demonstrates the issue. Umbraco-13-timezone-issue.zip
As you can see here, when running this project with a SQLite database, the DateTime returned is properly set as a Daylight Savings time (as I'm in BST), and when converting to UTC it correctly minuses an hour:
But when you run the project with a SQL Server Express database, the DateTime returned is not set as Daylight Savings, and therefore does NOT minus an hour when converting to UTC, which messes up the elapsed time calculation:
According to a comment on this closed issue: https://github.com/umbraco/Umbraco-CMS/issues/7078#issuecomment-551600622
NPoco assumes that all DateTime columns are UTC unless told otherwise in the column attributes
Which i understand, we can assume that CreateDate and UpdateDate are stored as server local time (although I imagine if you load balance across time zones, this could be annoying no? Shouldn't these be DateTimeOffset?), so this must indicate that the SQLite and SQL Server database providers are doing different things when reading DateTime columns; it seems like the SQLite provider converts them to local, whilst the SQL Server provider does not?
I also changed my Windows Time Zone to Brisbane (UTC+10) and, as expected, I get the exact same issue; the CreateDate and UpdateDate properties don't convert to UTC correctly when using SQL Server. (they stay 10 hours ahead)
Expected result / actual result
No response
Hi there @OwainJ!
Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.
We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.
- We'll assess whether this issue relates to something that has already been fixed in a later version of the release that it has been raised for.
- If it's a bug, is it related to a release that we are actively supporting or is it related to a release that's in the end-of-life or security-only phase?
- We'll replicate the issue to ensure that the problem is as described.
- We'll decide whether the behavior is an issue or if the behavior is intended.
We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.
Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:
Just sharing a link here, as your issue might be related to this old timer: https://github.com/umbraco/Umbraco-CMS/issues/11948
Just sharing a link here, as your issue might be related to this old timer: #11948
Cheers, it does defo seem related to that one, but my issue is with the built in DateTime fields rather than custom properties (although that issue mentions them too) :)
Hey Owain, thank you for the detailed report. I will try and replicate this asap with integration tests.
Hi @Migaroez, just checking if you had a chance to try and replicate this issue?
Hi @JasonElkin, I just want to confirm that, according to your comment here: https://github.com/umbraco/Umbraco-CMS/pull/16833#issuecomment-2299303874, the current suggested workaround for this issue is to set the server timezone to UTC?