Skip to content

.NET TimeZoneInfo fails to recognize historical invalid times after 2025 tzdb update for America/Asuncion #114476

Closed

Description

@michaelamaura

Description

After updating the OS-level time zone database (tzdb) to reflect Paraguay’s permanent switch to UTC-3, .NET TimeZoneInfo incorrectly treats historically invalid times as valid and returns conflicting UTC offsets.

Paraguay switched to DST exactly "before midnight", thus skipping midnight:

  • Prior to the tz db update, tz.IsInvalidTime(new DateTime(2024, 10, 6, 0, 0, 0)) was true.
  • After the tz db update, tz.IsInvalidTime(new DateTime(2024, 10, 6, 0, 0, 0)) is false.

Also for historical dates tz.IsInvalidTime should return correct results to ensure correctness. Since there are also discussions about abolishing DST in the US and EU, we should also ensure that historical calculations there won't be affected by future timezone updates.

Impact:

  • Data Integrity: Historical dates are incorrectly validated, leading to errors in scheduling, auditing, or compliance.
  • Offset Mismatches: DateTime and DateTimeOffset yield conflicting UTC offsets for the same logical time. (Edit: not reproducible)

Reproduction Steps

using System;
					
public class Program
{
	public static void Main()
	{
		var tz = TimeZoneInfo.FindSystemTimeZoneById("America/Asuncion");
		var shouldBeInvalid = new DateTime(2024, 10, 6, 0, 0, 0);
		
                // as a bonus show how offsets are handled incorrectly when passing invalid dates to tz.GetUtcOffset
		var utcOffsetFromDateTime = tz.GetUtcOffset(shouldBeInvalid);
		var dateTimeOffset = new DateTimeOffset(shouldBeInvalid, utcOffsetFromDateTime);
		var utcOffsetFromDateTimeOffset = tz.GetUtcOffset(shouldBeInvalid);
		
		Console.WriteLine($"Invalid: {tz.IsInvalidTime(shouldBeInvalid)}");
		Console.WriteLine($"UtcOffset: {utcOffsetFromDateTime}");
		Console.WriteLine($"UtcOffset: {utcOffsetFromDateTimeOffset}");
	}
}

Expected behavior

Should print (still does no .NET fiddle as of writing this issue https://dotnetfiddle.net/Ws9LR7):

Invalid: True
UtcOffset: -04:00:00
UtcOffset: -04:00:00

Actual behavior

On azure build agent with ubuntu-latest (agent version '4.253.0' , i.e. Ubuntu 24.04 with tzdata=2025b-0ubuntu0.24.04) it will print:

Invalid: True
UtcOffset: -04:00:00
UtcOffset: -03:00:00

Regression?

Works still on .NET fiddle and did work on Azure build agent version 20250323.1.0 (i.e. Ubuntu 24.04 with tzdata=2024a-2ubuntu1)

Known Workarounds

  • use NodaTime
  • use the inconsistency between GetUtcOffset(DateTime) and GetUtcOffset(DateTimeOffset) to determine whether a time is invalid

Configuration

Reproducible on Azure build agents "ubuntu-latest", agent version "4.253.0".

Other information

Changes to tzdb probably affecting this: eggert/tz@486e1e8

Activity

  1. added
    untriaged
    on Apr 10, 2025
  2. dotnet-policy-service commented on Apr 10, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-datetime
    See info in area-owners.md if you want to be subscribed.

  3. added this to the 10.0.0 milestone on Apr 10, 2025
  4. removed
    untriaged
    on Apr 10, 2025
  5. self-assigned this
    on Apr 10, 2025
  6. tarekgh commented on Apr 10, 2025

    @tarekgh
    Member

    @michaelamaura I have tried running the code on Ubuntu 25.04 using the latest tzdata package version 2025 and I am seeing the result.

    dpkg -l | grep tzdata
    ii  tzdata                              2025b-1ubuntu1                             all          time zone and daylight-saving time data
    
    ~/test# dotnet run
    Invalid: False
    UtcOffset: -03:00:00
    UtcOffset: -03:00:00
    

    Invalid: False Looks wrong and will be interesting to investigate.

    ~/test# zdump -v America/Asuncion
    
    America/Asuncion  Sun Mar 24 02:59:59 2024 UT = Sat Mar 23 23:59:59 2024 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 24 03:00:00 2024 UT = Sat Mar 23 23:00:00 2024 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  6 03:59:59 2024 UT = Sat Oct  5 23:59:59 2024 -04 isdst=0 gmtoff=-14400   <<<<<< When the transition starts  
    America/Asuncion  Sun Oct  6 04:00:00 2024 UT = Sun Oct  6 01:00:00 2024 -03 isdst=1 gmtoff=-10800   <<<<<< 
    America/Asuncion  Tue Oct 15 02:59:59 2024 UT = Mon Oct 14 23:59:59 2024 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Tue Oct 15 03:00:00 2024 UT = Tue Oct 15 00:00:00 2024 -03 isdst=0 gmtoff=-10800
    

    For GetUtcOffset() we don't throw on invalid time there, instead we just return the value of the BaseUtcOffset which is -3:00:00.

    Could you please run the following commands on your machine that show the problem and send the results to know what is going on there?

    dpkg -l | grep tzdata
    
    zdump -v America/Asuncion
    

    I guess somehow you have wrong installed tzdata package.

  7. modified the milestones: 10.0.0, Future on Apr 10, 2025
  8. added
    needs-author-action
    on Apr 10, 2025
  9. dotnet-policy-service commented on Apr 10, 2025

    @dotnet-policy-service
    Contributor

    This issue has been marked needs-author-action and may be missing some important information.

  10. removed
    needs-author-action
    on Apr 10, 2025
  11. michaelamaura commented on Apr 11, 2025

    @michaelamaura
    Author

    Regarding the offset inconsistency, I was not able to reproduce it any more. Sorry for that.

    The issue with IsInvalidTime persists however.

    I ran the commands anyway. The build agent is a Ubuntu 24.04.2:

    ~/# dpkg -l | grep tzdata
    ii  tzdata                             2025b-0ubuntu0.24.04                          all          time zone and daylight-saving time data
    ii  tzdata-legacy                      2025b-0ubuntu0.24.04                          all          time zone data for TAI minus ten seconds
    
    ~/# zdump -v America/Asuncion
    America/Asuncion  -9223372036854775808 = NULL
    America/Asuncion  -9223372036854689408 = NULL
    America/Asuncion  Sun Oct  7 03:59:59 2012 UT = Sat Oct  6 23:59:59 2012 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  7 04:00:00 2012 UT = Sun Oct  7 01:00:00 2012 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 24 02:59:59 2013 UT = Sat Mar 23 23:59:59 2013 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 24 03:00:00 2013 UT = Sat Mar 23 23:00:00 2013 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  6 03:59:59 2013 UT = Sat Oct  5 23:59:59 2013 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  6 04:00:00 2013 UT = Sun Oct  6 01:00:00 2013 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 23 02:59:59 2014 UT = Sat Mar 22 23:59:59 2014 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 23 03:00:00 2014 UT = Sat Mar 22 23:00:00 2014 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  5 03:59:59 2014 UT = Sat Oct  4 23:59:59 2014 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  5 04:00:00 2014 UT = Sun Oct  5 01:00:00 2014 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 22 02:59:59 2015 UT = Sat Mar 21 23:59:59 2015 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 22 03:00:00 2015 UT = Sat Mar 21 23:00:00 2015 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  4 03:59:59 2015 UT = Sat Oct  3 23:59:59 2015 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  4 04:00:00 2015 UT = Sun Oct  4 01:00:00 2015 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 27 02:59:59 2016 UT = Sat Mar 26 23:59:59 2016 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 27 03:00:00 2016 UT = Sat Mar 26 23:00:00 2016 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  2 03:59:59 2016 UT = Sat Oct  1 23:59:59 2016 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  2 04:00:00 2016 UT = Sun Oct  2 01:00:00 2016 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 26 02:59:59 2017 UT = Sat Mar 25 23:59:59 2017 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 26 03:00:00 2017 UT = Sat Mar 25 23:00:00 2017 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  1 03:59:59 2017 UT = Sat Sep 30 23:59:59 2017 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  1 04:00:00 2017 UT = Sun Oct  1 01:00:00 2017 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 25 02:59:59 2018 UT = Sat Mar 24 23:59:59 2018 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 25 03:00:00 2018 UT = Sat Mar 24 23:00:00 2018 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  7 03:59:59 2018 UT = Sat Oct  6 23:59:59 2018 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  7 04:00:00 2018 UT = Sun Oct  7 01:00:00 2018 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 24 02:59:59 2019 UT = Sat Mar 23 23:59:59 2019 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 24 03:00:00 2019 UT = Sat Mar 23 23:00:00 2019 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  6 03:59:59 2019 UT = Sat Oct  5 23:59:59 2019 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  6 04:00:00 2019 UT = Sun Oct  6 01:00:00 2019 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 22 02:59:59 2020 UT = Sat Mar 21 23:59:59 2020 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 22 03:00:00 2020 UT = Sat Mar 21 23:00:00 2020 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  4 03:59:59 2020 UT = Sat Oct  3 23:59:59 2020 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  4 04:00:00 2020 UT = Sun Oct  4 01:00:00 2020 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 28 02:59:59 2021 UT = Sat Mar 27 23:59:59 2021 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 28 03:00:00 2021 UT = Sat Mar 27 23:00:00 2021 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  3 03:59:59 2021 UT = Sat Oct  2 23:59:59 2021 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  3 04:00:00 2021 UT = Sun Oct  3 01:00:00 2021 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 27 02:59:59 2022 UT = Sat Mar 26 23:59:59 2022 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 27 03:00:00 2022 UT = Sat Mar 26 23:00:00 2022 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  2 03:59:59 2022 UT = Sat Oct  1 23:59:59 2022 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  2 04:00:00 2022 UT = Sun Oct  2 01:00:00 2022 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 26 02:59:59 2023 UT = Sat Mar 25 23:59:59 2023 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 26 03:00:00 2023 UT = Sat Mar 25 23:00:00 2023 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  1 03:59:59 2023 UT = Sat Sep 30 23:59:59 2023 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  1 04:00:00 2023 UT = Sun Oct  1 01:00:00 2023 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 24 02:59:59 2024 UT = Sat Mar 23 23:59:59 2024 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 24 03:00:00 2024 UT = Sat Mar 23 23:00:00 2024 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  6 03:59:59 2024 UT = Sat Oct  5 23:59:59 2024 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  6 04:00:00 2024 UT = Sun Oct  6 01:00:00 2024 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Tue Oct 15 02:59:59 2024 UT = Mon Oct 14 23:59:59 2024 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Tue Oct 15 03:00:00 2024 UT = Tue Oct 15 00:00:00 2024 -03 isdst=0 gmtoff=-10800
    America/Asuncion  9223372036854689407 = NULL
    America/Asuncion  9223372036854775807 = NULL
    
  12. michaelamaura commented on Apr 11, 2025

    @michaelamaura
    Author

    Running with tzdata=2024a-2ubuntu1: works as it should

    Just downgraded the tzdata

    sudo apt install -y tzdata=2024a-2ubuntu1 --allow-downgrades
    

    And ran the program again:

    Invalid: True
    UtcOffset: -04:00:00
    UtcOffset: -04:00:00
    

    So I can confirm it's working as it should with 2024a-2ubuntu1

    zdump -v  America/Asuncion
    
    ...
    America/Asuncion  Sun Mar 26 03:00:00 2023 UT = Sat Mar 25 23:00:00 2023 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  1 03:59:59 2023 UT = Sat Sep 30 23:59:59 2023 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  1 04:00:00 2023 UT = Sun Oct  1 01:00:00 2023 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 24 02:59:59 2024 UT = Sat Mar 23 23:59:59 2024 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 24 03:00:00 2024 UT = Sat Mar 23 23:00:00 2024 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  6 03:59:59 2024 UT = Sat Oct  5 23:59:59 2024 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  6 04:00:00 2024 UT = Sun Oct  6 01:00:00 2024 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 23 02:59:59 2025 UT = Sat Mar 22 23:59:59 2025 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Sun Mar 23 03:00:00 2025 UT = Sat Mar 22 23:00:00 2025 -04 isdst=0 gmtoff=-14400
    America/Asuncion  Sun Oct  5 03:59:59 2025 UT = Sat Oct  4 23:59:59 2025 -04 isdst=0 gmtoff=-14400
    ...
    
  13. tarekgh commented on Apr 11, 2025

    @tarekgh
    Member

    Thanks @michaelamaura for the info.

    The issue with IsInvalidTime persists however.

    Yes, looks it is corner case showing a bug in the calculation done in

    AdjustmentRule previousRule = GetPreviousAdjustmentRule(rule, ruleIndex);
    . Comparing 2024a-2ubuntu1 to 2025b-0ubuntu0 looks the following two rules causing the difference. The other rules in the same year are similar. Anyway, this needs to be investigated.

    America/Asuncion  Tue Oct 15 02:59:59 2024 UT = Mon Oct 14 23:59:59 2024 -03 isdst=1 gmtoff=-10800
    America/Asuncion  Tue Oct 15 03:00:00 2024 UT = Tue Oct 15 00:00:00 2024 -03 isdst=0 gmtoff=-10800
    
  14. michaelamaura commented on Apr 18, 2025

    @michaelamaura
    Author

    Cause of issue in GetIsInvalidTime?

    To me it seems like an issue here:

    // if at DST start we transition forward in time then there is an ambiguous time range at the DST end
    if (rule.DaylightDelta < TimeSpan.Zero)
    {
    // if the year ends with daylight saving on then there cannot be any time-hole's in that year.
    if (rule.IsEndDateMarkerForEndOfYear())
    return false;
    startInvalidTime = daylightTime.End;
    endInvalidTime = daylightTime.End - rule.DaylightDelta; /* FUTURE: + rule.StandardDelta; */
    }
    else
    {
    // if the year starts with daylight saving on then there cannot be any time-hole's in that year.
    if (rule.IsStartDateMarkerForBeginningOfYear())
    return false;
    startInvalidTime = daylightTime.Start;
    endInvalidTime = daylightTime.Start + rule.DaylightDelta; /* FUTURE: - rule.StandardDelta; */
    }

    The comments /* FUTURE: + rule.StandardDelta; */ and /* FUTURE: - rule.StandardDelta; */ are a giveaway (and have there been since ages). Because these are exactly the places that would need to be adjusted - additional to a few other ones.

    At the moment GetIsInvalidTime just is ignoring changes of BaseUtcOffset.

    To me it also looks like we would need to know the BaseUtcOffset from the next and/or previous AdjustmentRule in this place to decide whether there is an invalid time.

    Analyzation of Differences between 2025b-0ubuntu0.24.04 and 2024a-2ubuntu1

    I also had a look at how .NET is interpreting the timezone data, as to exclude we have an issue there. So I just wrote a simple program to output the AdjustmentRules:

    public static class AdjustmentRuleExtensions
    {
        [UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_noDaylightTransitions")]
        public static extern ref bool NoDaylightTransitions(this TimeZoneInfo.AdjustmentRule @this);
    
        public static string ToFormattedString(this TimeZoneInfo.AdjustmentRule rule)
        {
            return $"DateStart: {rule.DateStart:yyyy-MM-dd}, " +
                   $"DateEnd: {rule.DateEnd:yyyy-MM-dd}, " +
                   $"DaylightDelta: {rule.DaylightDelta}, " +
                   $"BaseUtcOffsetDelta: {rule.BaseUtcOffsetDelta}, " +
                   $"NoDaylightTransitions: {NoDaylightTransitions(rule)}, " +
                   $"DaylightTransitionStart: {TransitionTimeToString(rule.DaylightTransitionStart)}, " +
                   $"DaylightTransitionEnd: {TransitionTimeToString(rule.DaylightTransitionEnd)}";
        }
    
        private static string TransitionTimeToString(this TimeZoneInfo.TransitionTime tt)
        {
            // For fixed-date rules
            if (tt.IsFixedDateRule)
            {
                // Example: "Month: 3, Day: 15, TimeOfDay: 02:00:00"
                return $"Month: {tt.Month:00}, Day: {tt.Day:00}, TimeOfDay: {tt.TimeOfDay:HH:mm:ss.FFF}";
            }
            else
            {
                // Example: "Month: 3, Week: 2, DayOfWeek: Sunday, TimeOfDay: 02:00:00"
                return $"Month: {tt.Month:00}, Week: {tt.Week}, DayOfWeek: {tt.DayOfWeek}, TimeOfDay: {tt.TimeOfDay:HH:mm:ss.FFF}";
            }
        }
    }
    foreach (var rule in TimeZoneInfo.FindSystemTimeZoneById("America/Asuncion").GetAdjustmentRules()
                 .Where(r => r.DateStart.Year is >= 2023 and <= 2025))
    {
        Console.WriteLine(rule.ToFormattedString());
    }

    The output with 2025b-0ubuntu0.24.04 will be:

    DateStart: 2023-01-01, DateEnd: 2023-03-25, DaylightDelta: 00:00:00, BaseUtcOffsetDelta: 00:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 01, Day: 01, TimeOfDay: 00:00:00, DaylightTransitionEnd: Month: 03, Day: 25, TimeOfDay: 23:59:59.999
    DateStart: 2023-03-26, DateEnd: 2023-10-01, DaylightDelta: 00:00:00, BaseUtcOffsetDelta: -01:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 03, Day: 26, TimeOfDay: 00:00:00, DaylightTransitionEnd: Month: 10, Day: 01, TimeOfDay: 00:59:59.999
    DateStart: 2023-10-01, DateEnd: 2023-12-31, DaylightDelta: 00:00:00, BaseUtcOffsetDelta: 00:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 10, Day: 01, TimeOfDay: 01:00:00, DaylightTransitionEnd: Month: 12, Day: 31, TimeOfDay: 23:59:59.999
    DateStart: 2024-01-01, DateEnd: 2024-03-23, DaylightDelta: 00:00:00, BaseUtcOffsetDelta: 00:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 01, Day: 01, TimeOfDay: 00:00:00, DaylightTransitionEnd: Month: 03, Day: 23, TimeOfDay: 23:59:59.999
    DateStart: 2024-03-24, DateEnd: 2024-10-06, DaylightDelta: 00:00:00, BaseUtcOffsetDelta: -01:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 03, Day: 24, TimeOfDay: 00:00:00, DaylightTransitionEnd: Month: 10, Day: 06, TimeOfDay: 00:59:59.999
    DateStart: 2024-10-06, DateEnd: 2024-10-14, DaylightDelta: 00:00:00, BaseUtcOffsetDelta: 00:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 10, Day: 06, TimeOfDay: 01:00:00, DaylightTransitionEnd: Month: 10, Day: 14, TimeOfDay: 23:59:59.999
    

    With 2024a-2ubuntu1 it will be:

    DateStart: 2023-01-01, DateEnd: 2023-03-25, DaylightDelta: 01:00:00, BaseUtcOffsetDelta: 00:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 01, Day: 01, TimeOfDay: 00:00:00, DaylightTransitionEnd: Month: 03, Day: 25, TimeOfDay: 23:59:59.999
    DateStart: 2023-10-01, DateEnd: 2023-12-31, DaylightDelta: 01:00:00, BaseUtcOffsetDelta: 00:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 10, Day: 01, TimeOfDay: 00:00:00, DaylightTransitionEnd: Month: 12, Day: 31, TimeOfDay: 23:59:59.999
    DateStart: 2024-01-01, DateEnd: 2024-03-23, DaylightDelta: 01:00:00, BaseUtcOffsetDelta: 00:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 01, Day: 01, TimeOfDay: 00:00:00, DaylightTransitionEnd: Month: 03, Day: 23, TimeOfDay: 23:59:59.999
    DateStart: 2024-10-06, DateEnd: 2024-12-31, DaylightDelta: 01:00:00, BaseUtcOffsetDelta: 00:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 10, Day: 06, TimeOfDay: 00:00:00, DaylightTransitionEnd: Month: 12, Day: 31, TimeOfDay: 23:59:59.999
    DateStart: 2025-01-01, DateEnd: 2025-03-22, DaylightDelta: 01:00:00, BaseUtcOffsetDelta: 00:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 01, Day: 01, TimeOfDay: 00:00:00, DaylightTransitionEnd: Month: 03, Day: 22, TimeOfDay: 23:59:59.999
    DateStart: 2025-10-05, DateEnd: 2025-12-31, DaylightDelta: 01:00:00, BaseUtcOffsetDelta: 00:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 10, Day: 05, TimeOfDay: 00:00:00, DaylightTransitionEnd: Month: 12, Day: 31, TimeOfDay: 23:59:59.999
    

    So, with the old tzdata we will not have any BaseUtcOffsetDelta changes. With the new tzdata, all clock changes are handled using the BaseUtcOffsetDelta - which is ignored by the code in TimeZoneInfo.

    Investigating the time change in Portugal 1995

    The following program:

    var portugalChange1995At1 = new DateTime(1995, 3, 26, 1, 0, 0);
    Console.WriteLine(
        $"IsInvalidTime({portugalChange1995At1:yyyy-MM-dd'T'HH:mm:ss}): {portugalTz.IsInvalidTime(portugalChange1995At1)}");
    var portugalChange1995At2 = new DateTime(1995, 3, 26, 2, 0, 0);
    Console.WriteLine(
        $"IsInvalidTime({portugalChange1995At2:yyyy-MM-dd'T'HH:mm:ss}): {portugalTz.IsInvalidTime(portugalChange1995At2)}");
    var portugalChange1995At3 = new DateTime(1995, 3, 26, 3, 0, 0);
    Console.WriteLine(
        $"IsInvalidTime({portugalChange1995At3:yyyy-MM-dd'T'HH:mm:ss}): {portugalTz.IsInvalidTime(portugalChange1995At3)}");

    Will print:

    IsInvalidTime(1995-03-26T01:00:00): False
    IsInvalidTime(1995-03-26T02:00:00): True
    IsInvalidTime(1995-03-26T03:00:00): True
    

    The latter one is wrong, since the clocks were set forward for only one hour: https://www.timeanddate.com/time/change/portugal?year=1995

    The issue is similar to Paraguay, since Portugal switched from UTC+1 to UTC+0 as default offset in 1996 (after having switch the reverse way in 1992). Thus the daylightDelta alone is not enough to determine whether a time is invalid.

    The following program:

    var portugalTz = TimeZoneInfo.FindSystemTimeZoneById("Europe/Lisbon");
    
    foreach (var rule in portugalTz.GetAdjustmentRules()
                 .Where(r => r.DateStart.Year is >= 1995 and <= 1997))
    {
        Console.WriteLine(rule.ToFormattedString());
    }

    will print:

    DateStart: 1995-01-01, DateEnd: 1995-03-26, DaylightDelta: 00:00:00, BaseUtcOffsetDelta: 01:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 01, Day: 01, TimeOfDay: 00:00:00, DaylightTransitionEnd: Month: 03, Day: 26, TimeOfDay: 00:59:59.999
    DateStart: 1995-03-26, DateEnd: 1995-09-24, DaylightDelta: 02:00:00, BaseUtcOffsetDelta: 00:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 03, Day: 26, TimeOfDay: 01:00:00, DaylightTransitionEnd: Month: 09, Day: 24, TimeOfDay: 02:59:59.999
    DateStart: 1995-09-24, DateEnd: 1995-12-31, DaylightDelta: 00:00:00, BaseUtcOffsetDelta: 01:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 09, Day: 24, TimeOfDay: 01:00:00, DaylightTransitionEnd: Month: 12, Day: 31, TimeOfDay: 23:59:59.999
    DateStart: 1996-01-01, DateEnd: 1996-03-31, DaylightDelta: 00:00:00, BaseUtcOffsetDelta: 01:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 01, Day: 01, TimeOfDay: 00:00:00, DaylightTransitionEnd: Month: 03, Day: 31, TimeOfDay: 00:59:59.999
    DateStart: 1996-03-31, DateEnd: 1996-10-27, DaylightDelta: 01:00:00, BaseUtcOffsetDelta: 00:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 03, Day: 31, TimeOfDay: 01:00:00, DaylightTransitionEnd: Month: 10, Day: 27, TimeOfDay: 01:59:59.999
    DateStart: 1997-03-30, DateEnd: 1997-10-26, DaylightDelta: 01:00:00, BaseUtcOffsetDelta: 00:00:00, NoDaylightTransitions: False, DaylightTransitionStart: Month: 03, Day: 30, TimeOfDay: 01:00:00, DaylightTransitionEnd: Month: 10, Day: 26, TimeOfDay: 01:59:59.999
    

    It's a bit funny though, that .NET defines DaylightDelta as 02:00 for the DST time in 1995, but the BaseUtcOffsetDelta as 00:00. You could argue that this is clearly wrong for this time since the DaylightDelta has always been 01:00 in Portugal, but the UTC offset has changed.

    I did not investigate the parsing of the tzdate so far - but since the BaseUtcOffsetDelta would need to be taken into account anyway this also seems unnecessary for the bug regarding the IsInvalidTIme.

  15. michaelamaura commented on Apr 19, 2025

    @michaelamaura
    Author

    Similar issue in TimeZoneInfo.IsAmbiguousTime

    Portugal has switched its UTC offset twice in the 1990ies:

    • in 1992 from UTC+0 to UTC+1 (WET to CET)
    • in 1996 back from UTC+1 to UTC+0 (CET to WET)

    So, additional to the example above, the following snippet should print false, but it does print true:

    var portugalChangeIn1992 = new DateTime(1992, 9, 27, 1, 30, 0);
    Console.WriteLine(
        $"IsAmbiguousTime({portugalChangeIn1992:yyyy-MM-dd'T'HH:mm:ss}): {portugalTz.IsAmbiguousTime(portugalChangeIn1992)}");

    I created a repository with Unit test cases here: https://github.com/michaelamaura/dotnet-timezoneinfo-fix

  16. tarekgh commented on Oct 5, 2025

    @tarekgh
    Member

    Should be addressed by #119662

  17. locked and limited conversation to collaborators on Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions