DateTime vs DateTimeOffset
DateTime vs DateTimeOffset
DateTime vs DateTimeOffset
Re: DateTime vs DateTimeOffset
`DateTimeOffset` is a representation of *instantaneous time* (also known as *absolute time*). By that, I mean a moment in time that is universal for everyone (not accounting for [leap seconds](https://en.wikipedia.org/wiki/Leap_second), or the relativistic effects of [time dilation](https://en.wikipedia.org/wiki/Time_dilation)). Another way to represent instantaneous time is with a `DateTime` where `.Kind` is `DateTimeKind.Utc`.
This is distinct from *calendar time* (also known as *civil time*), which is a position on someone's calendar, and there are many different calendars all over the globe. We call these calendars *time zones*. Calendar time is represented by a `DateTime` where `.Kind` is `DateTimeKind.Unspecified`, or `DateTimeKind.Local`. And `.Local` is only meaningful in scenarios where you have an implied understanding of where the computer that is using the result is positioned. (For example, a user's workstation)
So then, why `DateTimeOffset` instead of a UTC `DateTime`? **It's all about perspective.** Let's use an analogy - we'll pretend to be photographers.
Imagine you are standing on a calendar timeline, pointing a camera at a person on the instantaneous timeline laid out in front of you. You line up your camera according to the rules of your timezone - which change periodically due to daylight saving time, or due to other changes to the legal definition of your time zone. (You don't have a steady hand, so your camera is shaky.)
The person standing in the photo would see the angle at which your camera came from. If others were taking pictures, they could be from different angles. This is what the `Offset` part of the `DateTimeOffset` represents.
So if you label your camera "Eastern Time", sometimes you are pointing from -5, and sometimes you are pointing from -4. There are cameras all over the world, all labeled different things, and all pointing at the same instantaneous timeline from different angles. Some of them are right next t
*(Réponse tronquée)*
This is distinct from *calendar time* (also known as *civil time*), which is a position on someone's calendar, and there are many different calendars all over the globe. We call these calendars *time zones*. Calendar time is represented by a `DateTime` where `.Kind` is `DateTimeKind.Unspecified`, or `DateTimeKind.Local`. And `.Local` is only meaningful in scenarios where you have an implied understanding of where the computer that is using the result is positioned. (For example, a user's workstation)
So then, why `DateTimeOffset` instead of a UTC `DateTime`? **It's all about perspective.** Let's use an analogy - we'll pretend to be photographers.
Imagine you are standing on a calendar timeline, pointing a camera at a person on the instantaneous timeline laid out in front of you. You line up your camera according to the rules of your timezone - which change periodically due to daylight saving time, or due to other changes to the legal definition of your time zone. (You don't have a steady hand, so your camera is shaky.)
The person standing in the photo would see the angle at which your camera came from. If others were taking pictures, they could be from different angles. This is what the `Offset` part of the `DateTimeOffset` represents.
So if you label your camera "Eastern Time", sometimes you are pointing from -5, and sometimes you are pointing from -4. There are cameras all over the world, all labeled different things, and all pointing at the same instantaneous timeline from different angles. Some of them are right next t
*(Réponse tronquée)*