Being proper developers, we stored UTC value, got back unspecified, performed the conversion. Now imagine DateTime was stored in the database, which returns all values as unspecified. ToUniversalTime will work fine if the value was either UTC or Local, but will treat Unspecified values as Local.One may always call ToUniversalTime() method or validate input to have Kind=UTC, but both approaches have their limitations: Net's DateTime may contain both units - the local time, the UTC time, and most troublesome, the Unspecified time.īy accident, one may pass a local or unspecified time into the code where UTC is expected, causing incorrect trading behavior in financial applications, errors in the stored data, and many other, more subtle errors. In our code, we try to keep all the DateTime values in Coordinated Universal Time (UTC - Temps Universel Coordonné) so that location is just a user interface setting, and has no affect on the internal program state. Compilers were designed to catch such errors early, but one must help compiler to find such errors.Įnter the world where Time is no longer an entity by itself, but always tied to a location. Some of us remember the big disaster with the Mars climate orbiter - due to a simple unit conversion error, hundred's of millions of dollars quickly evaporated in the Mars thin atmosphere.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |