IUtilityService.GetSupportedTimeZones
Reference
List<API.Contracts.TimeZoneInformation> IUtilityService.GetSupportedTimeZones()
Use get all Supported Time Zones list supported by Protrak.
Parameters
None
Returns
List<TimeZoneInformation>: This method return List<TimeZoneInformation> .
Where TimeZoneInformation contains Name & DisplayName of TimeZone.
Example of Output
[
{
Name = "Asia/Kolkata",
DisplayName = "(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi"
},
{
Name = "America/New_York",
DisplayName = "(UTC-05:00) Eastern Time (US & Canada)"
},
{
Name = "Europe/London",
DisplayName = "(UTC+00:00) London"
}
]
Usage
var timeZoneDisplayName = IUtilityService.GetSupportedTimeZones()
.FirstOrDefault(tz => tz.Name == settings.timeZoneId).DisplayName;
Example
var timeZoneId = IUtilityService.GetSupportedTimeZones()
.FirstOrDefault(tz => tz.Name == settings.timeZoneId).Name;
var systemTimeZone = IUtilityService.GetSystemTimeZoneInfo(timeZoneId);
Why This ? -
This is replacement of TimeZoneInfo.GetSystemTimeZones() - this code is depeneds on System / OS. If Server OS changes then list of timezones is different.
Use IUtilityService.GetSupportedTimeZones() - this is independent of OS and will always return list of time zones supported by Protrak.
And if you want to get System.TimeZoneInfo Object then use - var systemTimeZone = IUtilityService.GetSystemTimeZoneInfo(timeZoneId);
Note:
- Do not use the
TimeZoneInfo.GetSystemTimeZones()code line. - Do not use the DisplayName property of
TimeZoneInformationobject for comparison, useNameproperty instead. As the DisplayName is for user display purpose and may not be unique or consistent or it may change.
Ex;
// Incorrect way - Do not use this - as DisplayName use for comparison / identifier
var timeZoneId = IUtilityService.GetSupportedTimeZones()
.FirstOrDefault(tz => tz.DisplayName == settings.timeZone).Name;
// Correct way - Use Name property for comparison
var timeZoneId = IUtilityService.GetSupportedTimeZones()
.FirstOrDefault(tz => tz.Name == settings.timeZoneId).Name;