A record of doing a new thing every day in 2011
Technical post ahead - you have been warned!
I’ve been beta testing Bedside Clock v2.0 this week, and noticed there was a bug in my gratuitous sunrise/sunset feature.
Basically I realised the calculations were returning UTC times, rather than local times which was causing a problem (for me) of an hour now we’re on British Summer Time.
Anyway, I managed to fix it and learnt something new too - turns out the DateTime object has a SpecifyKind() method to help you define what type of time it is e.g. UTC, local or unspecified.
This means I can convert my DateTime to the correct local time with the following snippet:
DateTime thisDate = DateTime.SpecifyKind(new DateTime(original.Year, original.Month, original.Day, (int)hours, (int)minutes, (int)seconds), DateTimeKind.Utc); return thisDate.ToLocalTime();
As far as I can tell everything now works beautifully, so I can tell when the sun is setting without looking outside. Useful!