未验证 提交 ef2e4542 编写于 作者: T Tarek Mahmoud Sayed 提交者: GitHub

Expose Adjustment Rule BaseUtcOffsetDelta (#51055)

Co-authored-by: NGenevieve Warren <24882762+gewarren@users.noreply.github.com>
上级 bbea5516
......@@ -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 base UTC offset for the time zone during the adjustment-rule period.
/// </summary>
public TimeSpan BaseUtcOffsetDelta => _baseUtcOffsetDelta;
/// <summary>
/// Gets a value indicating that this AdjustmentRule fixes the time zone offset
......@@ -76,7 +79,17 @@ public sealed class AdjustmentRule : IEquatable<AdjustmentRule?>, ISerializable,
_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 is <c>DateTime.MinValue.Date</c>, this is the first adjustment rule in effect for a time zone.</param>
/// <param name="dateEnd">The last date that the adjustment rule is in force. If the value is <c>DateTime.MaxValue.Date</c>, the adjustment rule has no end date.</param>
/// <param name="daylightDelta">The time change that results from the adjustment. This value is added to the time zone's <see cref="P:System.TimeZoneInfo.BaseUtcOffset" /> and <see cref="P:System.TimeZoneInfo.BaseUtcOffsetDelta" /> properties to obtain the correct daylight offset from Coordinated Universal Time (UTC). This value can range from -14 to 14.</param>
/// <param name="daylightTransitionStart">The start of daylight saving time.</param>
/// <param name="daylightTransitionEnd">The end of daylight saving time.</param>
/// <param name="baseUtcOffsetDelta">The time difference with the base UTC offset for the time zone during the adjustment-rule period.</param>
/// <returns>The new adjustment rule.</returns>
public static AdjustmentRule CreateAdjustmentRule(
DateTime dateStart,
DateTime dateEnd,
TimeSpan daylightDelta,
......
......@@ -3898,9 +3898,11 @@ public sealed partial class AdjustmentRule : System.IEquatable<System.TimeZoneIn
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) { }
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册