Skip to content
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

Expose Adjustment Rule BaseUtcOffsetDelta #51055

Merged
merged 3 commits into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public sealed class AdjustmentRule : IEquatable<AdjustmentRule?>, ISerializable,

public TransitionTime DaylightTransitionEnd => _daylightTransitionEnd;

internal TimeSpan BaseUtcOffsetDelta => _baseUtcOffsetDelta;
/// <summary>
/// Gets the time difference with the particular time zone base Utc offset during the adjustment rule period.
tarekgh marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public TimeSpan BaseUtcOffsetDelta => _baseUtcOffsetDelta;

/// <summary>
/// Gets a value indicating that this AdjustmentRule fixes the time zone offset
Expand Down Expand Up @@ -76,7 +79,17 @@ private AdjustmentRule(
_noDaylightTransitions = noDaylightTransitions;
}

internal static AdjustmentRule CreateAdjustmentRule(
/// <summary>
/// Creates a new adjustment rule for a particular time zone.
/// </summary>
/// <param name="dateStart">The effective date of the adjustment rule. If the value of the dateStart parameter is DateTime.MinValue.Date, this is the first adjustment rule in effect for a time zone.</param>
tarekgh marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="dateEnd">The last date that the adjustment rule is in force. If the value of the dateEnd parameter is DateTime.MaxValue.Date, the adjustment rule has no end date.</param>
tarekgh marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="daylightDelta">The time change that results from the adjustment. This value is added to the time zone's BaseUtcOffset+BaseUtcOffsetDelta properties to obtain the correct daylight offset from Coordinated Universal Time (UTC). This value can range from -14 to 14.</param>
tarekgh marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="daylightTransitionStart">An object that defines the start of daylight saving time.</param>
tarekgh marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="daylightTransitionEnd">An object that defines the end of daylight saving time.</param>
tarekgh marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="baseUtcOffsetDelta">The time difference with the particular time zone base Utc offset during this adjustment rule period.</param>
tarekgh marked this conversation as resolved.
Show resolved Hide resolved
/// <returns>An object that represents the new adjustment rule.</returns>
tarekgh marked this conversation as resolved.
Show resolved Hide resolved
public static AdjustmentRule CreateAdjustmentRule(
DateTime dateStart,
DateTime dateEnd,
TimeSpan daylightDelta,
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3896,9 +3896,11 @@ internal AdjustmentRule() { }
public System.DateTime DateEnd { get { throw null; } }
public System.DateTime DateStart { get { throw null; } }
public System.TimeSpan DaylightDelta { get { throw null; } }
public System.TimeSpan BaseUtcOffsetDelta { get { throw null; } }
public System.TimeZoneInfo.TransitionTime DaylightTransitionEnd { get { throw null; } }
public System.TimeZoneInfo.TransitionTime DaylightTransitionStart { get { throw null; } }
public static System.TimeZoneInfo.AdjustmentRule CreateAdjustmentRule(System.DateTime dateStart, System.DateTime dateEnd, System.TimeSpan daylightDelta, System.TimeZoneInfo.TransitionTime daylightTransitionStart, System.TimeZoneInfo.TransitionTime daylightTransitionEnd) { throw null; }
public static System.TimeZoneInfo.AdjustmentRule CreateAdjustmentRule(System.DateTime dateStart, System.DateTime dateEnd, System.TimeSpan daylightDelta, System.TimeZoneInfo.TransitionTime daylightTransitionStart, System.TimeZoneInfo.TransitionTime daylightTransitionEnd, System.TimeSpan baseUtcOffsetDelta) { throw null; }
public bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] System.TimeZoneInfo.AdjustmentRule? other) { throw null; }
public override int GetHashCode() { throw null; }
void System.Runtime.Serialization.IDeserializationCallback.OnDeserialization(object? sender) { }
Expand Down
28 changes: 27 additions & 1 deletion src/libraries/System.Runtime/tests/System/TimeZoneInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2314,7 +2314,7 @@ public static IEnumerable<object[]> SystemTimeZonesTestData()
for (int i = -14; i <= 12; i++)
{
TimeZoneInfo tz = null;

try
{
string id = $"Etc/GMT{i:+0;-0}";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This formatting is going to be subject to the current culture, which could impact the negative sign used. Is that going to be an issue for someone running the tests in, say, Sweden?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to fail. As this is not related to this PR, we can address that in another PR.


In reply to: 611643769 [](ancestors = 611643769)

Expand Down Expand Up @@ -2706,6 +2706,32 @@ public static void ChangeLocalTimeZone(string id)
}
}

[Fact]
public static void AdjustmentRuleBaseUtcOffsetDeltaTest()
{
TimeZoneInfo.TransitionTime start = TimeZoneInfo.TransitionTime.CreateFixedDateRule(timeOfDay: new DateTime(1, 1, 1, 2, 0, 0), month: 3, day: 7);
TimeZoneInfo.TransitionTime end = TimeZoneInfo.TransitionTime.CreateFixedDateRule(timeOfDay: new DateTime(1, 1, 1, 1, 0, 0), month: 11, day: 7);
TimeZoneInfo.AdjustmentRule rule = TimeZoneInfo.AdjustmentRule.CreateAdjustmentRule(DateTime.MinValue.Date, DateTime.MaxValue.Date, new TimeSpan(1, 0, 0), start, end, baseUtcOffsetDelta: new TimeSpan(1, 0, 0));
TimeZoneInfo customTimeZone = TimeZoneInfo.CreateCustomTimeZone(
id: "Fake Time Zone",
baseUtcOffset: new TimeSpan(0),
displayName: "Fake Time Zone",
standardDisplayName: "Standard Fake Time Zone",
daylightDisplayName: "British Summer Time",
new TimeZoneInfo.AdjustmentRule[] { rule });

TimeZoneInfo.AdjustmentRule[] rules = customTimeZone.GetAdjustmentRules();

Assert.Equal(1, rules.Length);
Assert.Equal(new TimeSpan(1, 0, 0), rules[0].BaseUtcOffsetDelta);

// BaseUtcOffsetDelta should be counted to the returned offset during the standard time.
Assert.Equal(new TimeSpan(1, 0, 0), customTimeZone.GetUtcOffset(new DateTime(2021, 1, 1, 2, 0, 0)));

// BaseUtcOffsetDelta should be counted to the returned offset during the daylight time.
Assert.Equal(new TimeSpan(2, 0, 0), customTimeZone.GetUtcOffset(new DateTime(2021, 3, 10, 2, 0, 0)));
}

private static bool IsEnglishUILanguage => CultureInfo.CurrentUICulture.Name.Length == 0 || CultureInfo.CurrentUICulture.TwoLetterISOLanguageName == "en";

private static bool IsEnglishUILanguageAndRemoteExecutorSupported => IsEnglishUILanguage && RemoteExecutor.IsSupported;
Expand Down