Codility – nice tool to test programming skill

Current month’s featured task is challenging.

Unfortunately failed one test, so my score is 92 of 100 (details), ended up with silver certificate. Codility badge.


DateTime time zone doesn’t change (cached) for process during runtime

If your application uses clients time for some processing, it should be taken into account that time zone may be cached. You should expect the following code to return first (cached) time zone after you change it during application runtime, not the freshly applied one:

var str = DateTime.Now.ToString("HH:mm:ss.ffff zzz");

So on first call of this code value for time zone will be cached and you should manually reset cache. You would have to call System.Globalization.CultureInfo.CurrentCulture.ClearCachedData() to reset it. For .NET 3.5 TimeZoneInfo class there’s its own ClearCachedData() method.

Also culture data is cached for a reason and you shouldn’t clear it too frequently, so you can find appropriate event for it. As long as actual time zone is critical for my application I’m subscribing to SystemEvents.TimeChanged event on application start:

SystemEvents.TimeChanged += (sender, args) =>