How does DateTimeOffset deal with daylight saving time?

I know that DateTimeOffset stores UTC date / time and offset. I also know from this MSDN blog post that DateTimeOffset should be used for "Working with the summer days."

What I'm trying to understand is exactly the same as DateTimeOffset "works with daylight saving time." My understanding, not only is there, that daylight saving time is a political decision and cannot be removed from a pure bias. How can it be that this structure is DST friendly if it only stores offset?

I am going to use the TimeZoneInfo method in combination with DateTimeOffset. How should I do it?

Finally, are there any better ways I could achieve the following?

(I saw several posts from Jon Skeet about Noda-Time , but I don’t know if this is ready, but I don’t know if it will integrate well into our existing solution).

Here is our script. The server for unsuccessful inherited reasons works in the UK. We have clients who are starting to enter the stream from Australia with several time zones. Other countries may be operational at any time.

We have a scheduler based on the hard disk scheduler (uses DateTimeOffset). It works very well. However, in our database we store enough data to create a DateTime object (see below), and in our subclass and plumbing code we just use DateTime, since initially we only supported users from the UK.

This planner is responsible for the immobilization and mobilization of plant equipment. Therefore, it is vital that scheduled events run in local time configured by the DST user.

A user enters a schedule on our website; it is currently stored in the database as the day of the week, hour and minute. When the data is read, we create a DateTime object for the next occurrence of this day, hour and minute. I can change the structure of db to further preserve the offset or time zone.

When this date and time is reached, the scheduler sends a command (and retries for a while). Then it starts again on the same day and next week (although the service will actually be redesigned by then and the code will start again).

All I need to achieve is to run the scheduled events at the local date and time set by the time zone for this user, using the scheduler, which subclasses from Hardcodet. If DateTimeOffset really supports DST, maybe all I have to do is save the offset and change our plumbing code to use this structure, but I get the impression that it's not so simple. (We can get the current time zone from the GPS installation position, but this is a discussion for another day :)).

+15
c # nodatime datetimeoffset sql-server-2008 scheduling
Sep 26 '11 at 10:53
source share
1 answer

DateTimeOffset itself does not know DST, but there is TimeZoneInfo . A DateTimeOffset is a fixed point in time, so you get a DateTimeOffset through what the time zone knows. In other words, if I asked for DateTimeOffset now in the UK, I would get something with a +1 hour offset from UTC. If I asked for DateTimeOffset for some time in December in the UK, I would get something with a 0 hour offset from UTC.

If you modify your database to include an offset, and you create a DateTimeOffset from the user-selected DateTime (which should be solid “unspecified”) and their time zone, then this should give you the correct DST offset.

One thing you need to know about: if I plan something now for “two years,” and now you determine the bias, this bias may not be correct in the future — for example, the government may change when DST is applied, and obviously that is not going to change what is stored in your database.

+23
Sep 26 '11 at 10:57
source share



All Articles