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

Use DateTimeOffset #274

Closed
vbjay opened this issue Dec 6, 2021 · 4 comments · Fixed by #434
Closed

Use DateTimeOffset #274

vbjay opened this issue Dec 6, 2021 · 4 comments · Fixed by #434
Labels
help wanted Extra attention is needed

Comments

@vbjay
Copy link

vbjay commented Dec 6, 2021

public DateTime RegDate { get; set; }

Storing the full date and timezone allows us to support web farms and region servers and translation to show the user if desired in browser's timezone will just work. I know we can force utc time but with DatetimeOffset, it will automatically translate no matter how it was stored and sent.

@abergs
Copy link
Collaborator

abergs commented Dec 6, 2021

Hello @vbjay and thank you for the proposal. I've used DateTimeOffset with success in other large apps, but if I recall correctly, DateTimeOffset comes with tradeoffs. For example I think storing DateTimeOffset can be a bit cumbersome compared to a normal date? Running into conversion issues in popular ORM's or when storing that information in a sql datebase with type "Datetime". Or am I misstaken?

If we enforce UTC in all our usecases, we would not (?) introduce problems for servers in different timezones and we would not add Offset-related complexity to developers. For developer interested in localising the datetime it would still be possible to convert it outside the library. Correct?

@Sora2455
Copy link

Sora2455 commented Dec 7, 2021

Hello @vbjay and thank you for the proposal. I've used DateTimeOffset with success in other large apps, but if I recall correctly, DateTimeOffset comes with tradeoffs. For example I think storing DateTimeOffset can be a bit cumbersome compared to a normal date? Running into conversion issues in popular ORM's or when storing that information in a sql datebase with type "Datetime". Or am I misstaken?

SQL Server natively supports DateTimeOffsets, but other ORM's do not.

If we enforce UTC in all our usecases, we would not (?) introduce problems for servers in different timezones and we would not add Offset-related complexity to developers. For developer interested in localising the datetime it would still be possible to convert it outside the library. Correct?

DateTimeOffsets can be converted to UTC DateTimes with the UtcDateTime property, so it's really a toss-up. If you really want to stick with DateTimes in UTC format, I'd recommend making that explicitly clear by renaming the properties to have a postfix of UTC - e.g. RegDateUTC.

@vbjay
Copy link
Author

vbjay commented Dec 12, 2021

If you are using EF for stuff it automatically stores it correctly. Example create a model with a datetimeoffset and use sqlite.

@Sora2455 Thanks That is the confusion and issue I am trying to solve. Adding UTC to the end would be another solution to hint to the user to use an UTC date and not just any date but would not handle it automatically. Why I suggested the offset usage. Along with PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#819 (comment) showing it is possible. Yes I know EF is not the only orm but I am showing that it is not just sql server with ef that can support it.

So this library is geared to communication to servers that will most likely cross timezones. Why make it hard? If I get a 12/5/2021 12:30:00 -07:00 date stored in db I can always translate it to utc, other offset... The web browser can take the value and know how to translate to client time automatically like shown below.

image
No matter if I use a cloud solution that is region specific and get registered time as EST or PST or... I don't have to do the "oh is this datetime utc or not " work. All I do is get DateTimeOffset.Now and don't care. It will store correctly in the db and will translate correctly everywhere it travels whether api, on server, on client or anywhere else.

Sql server even has AT TIME ZONE https://docs.microsoft.com/en-us/sql/t-sql/queries/at-time-zone-transact-sql

@abergs
Copy link
Collaborator

abergs commented Dec 27, 2021

I'm onboard for DatetimeOffset. Let's make it happen.

@abergs abergs added the help wanted Extra attention is needed label Dec 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants