-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TimeZoneInfo.ToSerializedString/FromSerializedString do not round trip on Unix #19794
Comments
I moved this to the future release because fixing this will need some major changes how we read and handle the adjustment rules in Linux which will be risky for v2. We should have a better story for time zones in general in the future. |
Bumping to see if there are any plans to get this fixed. This bug means that users who create custom time zones via microsoft's documentation will not be able to use GetAdjustmentRules() to see the correct definitions, namely the Transition Rules Start/End are not returned correctly. |
@SUPERSC0TT there is no plan to address this very soon but we may get into that in the near future. the reason is we need to look at the whole TZ support and address the issues in more better designed way. Could you please share some more information about your TZ usage? like do you use custom TZ? why? what is your scenarios you are using with? We appreciate your feedback. |
Guys, timezones are basic, we've got into this as well, and issues such this are a show-stopper if we need to move 2 the Linux (( |
@yahorsi could you please tell more about your scenario? why you want serialize TZI at all? are you creating your own custom TZ? |
We're actually hit by aa bit another issue, the one that is described here: https://github.com/dotnet/corefx/issues/17120 And caused by the following:
Our scenario is simple, we have a 'constant' custom Timezone that is parsed using TimeZoneInfo.FromSerializedString. In some parts of the code we just need to read transition start and end info, and it works on Windows and fails on Linux. As I see in the code it should be very easy to fix. The question is why it was made in the first place. |
Internally the data stored inside adjustment rules in Linux is different than what we have in Windows. We have another issues (like the one you pointed at) tracking fixing exposing the rules correctly on Linux too. That is why you are seeing this issue. Will try to look at that in the next few weeks. I marked this issue for 5.0 release. |
What people usually expect is that code just works the same way on the different operating systems. And we're hurt even if we didn't deploy on Linux as many today's build servers are using Linux and so, tests are just failing ( Is there any option to have the fix for the 2.2.* branch? |
@danmosemsft @ericstj to advise regarding servicing this in previous releases. We don't have the fix yet and depend on the fix we can evaluate the risk. meanwhile, we may try to find you a workaround which may help parsing the Linux serialized TZ. |
Sorry, do you mean it should be serialized in different way for linux and windows? Just FYI, this is how our serialized string looks now: public const string TimeZoneZrhSerialized = "Central European Standard Time;60;(UTC+01:00) Sarajevo, Skopje, Warsaw, Zagreb;Central European Standard Time;Central European Daylight Time;[01:01:0001;12:31:9999;60;[0;02:00:00;3;5;0;];[0;03:00:00;10;5;0;];];"; |
No. what I meant, if there is a way to detect the string is serialized on Linux and interpret the serialized data differently to get the original intended information. I don't know yet if this is possible. I just wanted to say, if there is any reasonable workaround can be used here. |
We do not accept servicing requests for past releases through Github, please see https://dotnet.microsoft.com/platform/support/policy/dotnet-core, https://github.com/dotnet/core/blob/master/microsoft-support.md for details around backporting to past releases. The short answer is: if you need this for .NETCore 2.1, please open a support request, .NETCore 2.2 is no longer recieving hotfixes (only security fixes). |
Thank you, we will have a look at possible workarounds and if needed I will create a proper fix request. BTW there is still time before 3.1 release, I'm afraid 5.0 is too far in the future |
There is still time for 3.1 but that window is closing quickly, we're already in "Ask mode" where we are scrutinizing risk of all fixes going into 3.1. If we can come up with a low risk fix in the next week it has a chance at getting in. |
My use case for calling GetAdjustmentRules is for me to send down the month, week and hour of start/end transitions to an iot device so it can observe daylight saving time. Here is another issue that is affected by this: #26278 (comment) |
@ralsu091 - I'm assuming you're listing a subset of the fields, because month+week+hour(+year, assumedly) isn't sufficient. A DST transition isn't guaranteed to be on any particular day-of-week. For that matter, although unlikely, it's perfectly possible to have multiple transitions of various sorts in any given week. You don't list what device you're using, but if it's something Linux-based, why not just update the actual timezone file (not necessarily through |
@tarekgh, let me describe how we use timezones. We are cross-platform and we are also facing the exception
It looks like .net core poorly supports timezones in Linux, and it seems like it is something that careful attention should be given to from your side.
We would like to leave that code cross-platform but we can't do that as of yet, since CreateCustomTimeZone raises the exception on Linux. |
@ademchenko - Frankly, if you're doing a lot of work with timezones, especially crossplatform, I'd really recommend you use |
Ran into this ourselves because we had a test which made assumptions that the UTC time zone (works correctly on both Linux and Windows)[Test]
public void UTC_test() {
var tz = TimeZoneInfo.Utc;
// Works correctly on both Linux and Windows
var serialized = tz.ToSerializedString();
var roundTrippedTimezone = TimeZoneInfo.FromSerializedString(serialized);
roundTrippedTimezone.Should()
.Be(tz);
} Local time zone (fails on Linux)[Test]
public void Stockholm_test() {
var tz = TimeZoneInfo.FindSystemTimeZoneById("Europe/Stockholm");
// The FromSerializedString() call fails on Linux
var serialized = tz.ToSerializedString();
var roundTrippedTimezone = TimeZoneInfo.FromSerializedString(serialized);
roundTrippedTimezone.Should()
.Be(tz);
} |
The following test passes on Windows but fails on Unix:
I believe it's due to how
GetAdjustmentRules
is implemented on Unix: https://github.com/dotnet/coreclr/blob/0a11492d52faa85c551761f8390be5de9d74e5ec/src/mscorlib/src/System/TimeZoneInfo.Unix.cs#L131-L153vs. on Windows: https://github.com/dotnet/coreclr/blob/0a11492d52faa85c551761f8390be5de9d74e5ec/src/mscorlib/src/System/TimeZoneInfo.Win32.cs#L87
See dotnet/corefx#14795
Also, when you pass an
AdjustmentRule[]
array toTimeZoneInfo.CreateCustomTimeZone
to create a custom instance ofTimeZoneInfo
, callingGetAdjustmentRules
on Windows will always give you a cloned copy of the same adjustment rules, whereas on Unix it looks like it will modify the adjustment rules that are returned.The text was updated successfully, but these errors were encountered: