Closed sagarveer444 closed 1 year ago
Can you provide an example in code please?
public static async Task<string> GetConvertedDateTime(UserInfo userDetails, DateTime AppointmentDateTime)
{
string response = string.Empty;
string StandardUserTimeZone = string.Empty;
string userTimeZone = await new api.kolabtree.Models.DAL.Profile().GetProfileCurrentTimeZone(userDetails.ProfileId);
if (!string.IsNullOrEmpty(userTimeZone))
{
var abbreviations = TimeZoneNames.TZNames.GetAbbreviationsForTimeZone(userTimeZone, "en-US");
StandardUserTimeZone = TimeZoneConverter.TZConvert.IanaToWindows(userTimeZone);
TimeZoneInfo Hosttimelocal = TimeZoneInfo.FindSystemTimeZoneById(StandardUserTimeZone);
DateTime convertedDatetime = TimeZoneInfo.ConvertTimeFromUtc(AppointmentDateTime, Hosttimelocal);
string strabbreviations = Hosttimelocal.IsDaylightSavingTime(convertedDatetime) ? abbreviations.Daylight : abbreviations.Standard;
response = $"{TimeZoneInfo.ConvertTimeFromUtc(AppointmentDateTime, Hosttimelocal).ToString("ddd dd MMM yyyy, hh:mm tt")} {strabbreviations}";
}
else
{
//TimeZoneInfo Hosttimelocal = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
//response = $"{TimeZoneInfo.ConvertTimeFromUtc(AppointmentDateTime, Hosttimelocal).ToString("ddd dd MMM yyyy, hh:mm tt")} GMT. Time shown is in GMT as you have not set your Timezone as part of the Account Settings.";
response = $"{AppointmentDateTime.ToString("ddd dd MMM yyyy, hh:mm tt")} GMT (system assigned time zone)";
}
return response;
}
@mattjohnsonpint From above code abbreviations.Standard is assigned to strabbreviations variable, which is null. on other hand abbreviations.Daylight returning timezone as "COST" and Hosttimelocal.IsDaylightSavingTime(convertedDatetime) is returning FALSE userTimezone = "America/Bogota" i.e. Colombia (America/Bogota) UTC -05:00
This is an issue with abbreviations only. The following is a minimal repro:
var abbreviations = TZNames.GetAbbreviationsForTimeZone("America/Bogota", "en-US");
Console.WriteLine("Generic: " + abbreviations.Generic);
Console.WriteLine("Standard: " + abbreviations.Standard);
Console.WriteLine("Daylight: " + abbreviations.Daylight);
Output:
Generic:
Standard:
Daylight: COST
Works fine for names though:
var names = TZNames.GetNamesForTimeZone("America/Bogota", "en-US");
Console.WriteLine("Generic: " + names.Generic);
Console.WriteLine("Standard: " + names.Standard);
Console.WriteLine("Daylight: " + names.Daylight);
Output:
Generic: Colombia Time
Standard: Colombia Standard Time
Daylight: Colombia Summer Time
A big part of the problem is that time zone abbreviations are unreliable in the CLDR data.
In the example case, the cause is that CLDR only has one English abbreviation for Colombia, and it's for daylight time.
https://github.com/unicode-org/cldr/blob/main/common/main/en_CA.xml#L4629
I need to rethink how time zone abbreviations work in general. We have plenty of other issues with them. I haven't decided yet, but I may just remove them completely.
This is an issue with abbreviations only. The following is a minimal repro:
var abbreviations = TZNames.GetAbbreviationsForTimeZone("America/Bogota", "en-US"); Console.WriteLine("Generic: " + abbreviations.Generic); Console.WriteLine("Standard: " + abbreviations.Standard); Console.WriteLine("Daylight: " + abbreviations.Daylight);
Output:
Generic: Standard: Daylight: COST
Works fine for names though:
var names = TZNames.GetNamesForTimeZone("America/Bogota", "en-US"); Console.WriteLine("Generic: " + names.Generic); Console.WriteLine("Standard: " + names.Standard); Console.WriteLine("Daylight: " + names.Daylight);
Output:
Generic: Colombia Time Standard: Colombia Standard Time Daylight: Colombia Summer Time
@mattjohnsonpint Thanks its worked for me..👍
Closing. Will track abbreviations issue in #91. Thanks.
We are facing daylight issues for some countries (Colombia, and Brazil Sao/Paulo) where the library is returning standard timezone as 'null' and daylight value as true.
Used Version: 6.0.0