TimeZoneNames standard, daylight, generic uses

While trying to differentiate between the Mountain time zone and Arizona (I realize they are both Mountain Time) I found that GetNamesForTimeZone("America/Phoenix", "en-us") returned a daylight name.

Should i be relying on external code(noda time) to figure out if the time is daylight for that timezone or is there a way to know just from TimeZoneNames functions if a zone doesn't have daylight savings?

On that same note, what the the use-case for using the "generic" name for a timezone name instead of standard vs daylight?

Jon Skeet
people
quotationmark

As far as I can tell, TimeZoneNames is all about just the time zone names themselves - it doesn't know anything about the time zone data itself.

If you want to know whether America/Phoenix is currently observing daylight savings, I'd definitely use Noda Time itself:

// Usually pass in System.Clock.Instance as the clock...
// or take an Instant instead.
public bool IsCurrentlyObservingDaylightSavings(string id, IClock clock)
{
    var zone = DateTimeZoneProviders.Tzdb[id];
    var now = clock.Now;
    var zoneInterval = zone.GetZoneInterval(now);
    return zoneInterval.Savings != Offset.Zero;
}

I may well add a DateTimeZone.InDaylightSaving(Instant) method to 2.0...

people

See more on this question at Stackoverflow