This blog is hosted on WordPress and it would cost me money if I would buy a certificate through WordPress. To add HTTPS to my blog, I route it through the free service CloudFlare. I never found a decent blog post how to do it, so I’ll detail what I know in this post.
A year, maybe two ago, I saw a talk of a colleague about performance. He compared
await/async with more traditional threading options, demonstrated how slow reflection is and compared the three string concatenation options: sum notation,
StringBuilder. Now that
string interpolation is here, I was curious how fast is it compared to the other methods.
A little while ago I learned an important lesson: lack of goals in a project can lead to stress. Yes, not only can goals cause stress, apparently, they can take a part of it away too.
On my current work project, the system receives a document with dates and times in the local format (all Belgian local time). In the metadata however, we receive them in the UTC format. After a bit of processing, nobody knew which date was in what format anymore. Was the UTC time changed to local before saving it to the database? Or did we save the dates from the document as UTC. Why is it displayed differently on one part of the page compared to the next.
A solution was required and unfortunately we couldn’t use the excellent NodaTime package from Jon Skeet due to our employer not trusting it. Sigh
After a bit of searching, I stumbled upon the
<a href="https://msdn.microsoft.com/en-us/library/system.datetimeoffset(v=vs.110).aspx" target="_blank">DateTimeOffset</a> class. Microsoft should learn to name things correctly. When I first read the name
DateTimeOffset, I thought this object stored only the offset for a
DateTime object. Apparently it handles everything from dates and times with an offset according to the UTC standard. And it is native to the .NET framework. Basically how you expect the
DateTime class to behave.
So we replaced most of the
DateTime classes by the
DateTimeOffset and all of our problems went away. The dates are now stored in the database as UTC time and when they are loaded, we can update them easily to the local time. The out of the box serialization includes the time offset (which the
In future projects, I will use
DateTimeOffset for all my date and time needs instead of the
DateTime class. Microsoft themselves even encourage it. So I urge you to do the same.