© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
57 replies
Kiel

❔ Converting my project to NodaTime

Hi there, after some conversation in my previous partially related thread #Accounting for Daylight Savings Time skips at runtime, I'm planning on converting existing functionality in my project (a Discord bot) to NodaTime's types instead of the BCL types, to avoid issues that might occur from constantly converting to and from different time-related types.

There are a lot of classes in NodaTime that can be used to represent a "moment in time" so to speak, so I'd like to know which ones I should use for different situations.
Disclaimer: I am using EFCore with PostgreSQL, and will now be using
Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime
Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime
for storing appropriate types.

- Most of my database entities utilize
DateTimeOffset
DateTimeOffset
for their creation date and time - always stored in UTC as I believe EFCore cannot store
DateTimeOffset
DateTimeOffset
s with a non-UTC offset. I'm unsure whether to use
OffsetDateTime
OffsetDateTime
,
ZonedDateTime
ZonedDateTime
, or
Instant
Instant
.
- Many classes implement a timer interface, and utilize a
DateTimeOffset
DateTimeOffset
for when the timer "expires". See the linked thread for issues related to Daylight Savings Time - I believe I will need to store a
LocalTime
LocalTime
or
Instant
Instant
and convert it to the user's timezone at runtime (see next point)
- Users can set their timezone via a command - allowing using https://github.com/robbell/nChronic.Core for natural date parsing in their local time, instead of using UTC for everything. I will likely store their timezone as
TimeZoneInfo
TimeZoneInfo
instead of
TimeSpan
TimeSpan
which I previously used.

Any suggestions for how to handle these types of situations? I'm trying to make sure I can make this transition as clean and bug-free as possible, since I have a lot of logic implemented that relies on the BCL time/date types.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

✅ Converting project
C#CC# / help
3y ago
✅ NodaTime JSON Serialization
C#CC# / help
2y ago
❔ DateTime help with NodaTime
C#CC# / help
4y ago
❔ Unable to resolve service for type 'NodaTime.IClock' while attempting to activate
C#CC# / help
3y ago