Reputation: 25
From Jon Skeet's NodaTime documentation:
The time that we add is effectively "experienced" time - as if we'd simply waited twenty minutes. However, at 1am on that day, the clocks in the Europe/London time zone go forward by an hour - so we end up with a local time of 2:05am, not the 1:05am you might have expected
However, when I try this code, effectively copying and pasting most of it from NodaCode documentation into the application, the after
variable has 01:05:00, instead of 02:05:00. Why isn't it accounting for the time zone?
DateTimeZone london = DateTimeZoneProviders.Tzdb["Europe/London"];
LocalDateTime local = new LocalDateTime(2012, 3, 27, 0, 45, 00);
ZonedDateTime before = london.AtStrictly(local);
ZonedDateTime after = before + Duration.FromMinutes(20);
Debug.WriteLine("local = {0}",local);
Debug.WriteLine("before adding 20 minutes = {0}", before);
Debug.WriteLine("after adding 20 minutes= {0}", after);
Output:
local = 03/27/2012 00:45:00
before adding 20 minutes = 2012-03-27T00:45:00 Europe/London (+01)
after adding 20 minutes= 2012-03-27T01:05:00 Europe/London (+01)
Update:
based on Dean Ward's answer below I tried with 26th instead , still it doesn't realize daylight saving change. :(
DateTimeZone london = DateTimeZoneProviders.Tzdb["Europe/London"];
LocalDateTime local = new LocalDateTime(2012, 3, 26, 0, 45, 00);
ZonedDateTime before = london.AtStrictly(local);
ZonedDateTime after = before + Duration.FromMinutes(20);
output:
local = 03/26/2012 00:45:00
before adding 20 minutes = 2012-03-26T00:45:00 Europe/London (+01)
after adding 20 minutes= 2012-03-26T01:05:00 Europe/London (+01)
Upvotes: 1
Views: 203
Reputation: 4793
DST in Europe/London in 2012 changed on 2012-03-25. Try changing your initial value to that date...
Upvotes: 1