Thanks to visit codestin.com
Credit goes to github.com

Skip to content

System.TimeZoneInfo.AdjustmentRule F# snippets #7915

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

Merged
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,83 @@
// <Snippet1>
open System
open System.Globalization

let timeZones = TimeZoneInfo.GetSystemTimeZones()
let dateInfo = CultureInfo.CurrentCulture.DateTimeFormat

type WeekOfMonth =
| First = 1
| Second = 2
| Third = 3
| Fourth = 4
| Last = 5

for zone in timeZones do
printfn $"{zone.StandardName} transition time information:"
printfn " Time zone information: "
printfn $" Base UTC Offset: {zone.BaseUtcOffset}"
printfn $" Supports DST: {zone.SupportsDaylightSavingTime}"

let adjustmentRules= zone.GetAdjustmentRules()

// Indicate that time zone has no adjustment rules
if adjustmentRules.Length = 0 then
printfn " No adjustment rules defined."
else
printfn $" Adjustment Rules: {adjustmentRules.Length}"
// Iterate adjustment rules
for adjustmentRule in adjustmentRules do
printfn $" Adjustment rule from {adjustmentRule.DateStart:d} to {adjustmentRule.DateEnd:d}:"
printfn $" Delta: {adjustmentRule.DaylightDelta}"
// Get start of transition
let daylightStart = adjustmentRule.DaylightTransitionStart
// Display information on floating date rule
if not daylightStart.IsFixedDateRule then
printfn $" Begins at {daylightStart.TimeOfDay:t} on the {enum<WeekOfMonth> daylightStart.Week} {daylightStart.DayOfWeek} of {dateInfo.GetMonthName daylightStart.Month}"
// Display information on fixed date rule
else
printfn $" Begins at {daylightStart.TimeOfDay:t} on {dateInfo.GetMonthName daylightStart.Month} {daylightStart.Day}"

// Get end of transition.
let daylightEnd = adjustmentRule.DaylightTransitionEnd
// Display information on floating date rule.
if not daylightEnd.IsFixedDateRule then
printfn $" Ends at {daylightEnd.TimeOfDay:t} on the {enum<WeekOfMonth> daylightEnd.Week} {daylightEnd.DayOfWeek} of {dateInfo.GetMonthName daylightEnd.Month}"

// Display information on fixed date rule.
else
printfn $" Ends at {daylightEnd.TimeOfDay:t} on {dateInfo.GetMonthName daylightEnd.Month} {daylightEnd.Day}"

// A portion of the output from the example might appear as follows:
// Tonga Standard Time transition time information:
// Time zone information:
// Base UTC Offset: 13:00:00
// Supports DST: False
// No adjustment rules defined.
// Samoa Standard Time transition time information:
// Time zone information:
// Base UTC Offset: 13:00:00
// Supports DST: True
// Adjustment Rules: 4
// Adjustment rule from 1/1/0001 to 12/31/2009:
// Delta: 00:00:00
// Begins at 12:00 AM on January 1
// Ends at 12:00 AM on January 1
// Adjustment rule from 1/1/2010 to 12/31/2010:
// Delta: 01:00:00
// Begins at 11:59 PM on the Last Saturday of September
// Ends at 12:00 AM on the First Friday of January
// Adjustment rule from 1/1/2011 to 12/31/2011:
// Delta: 01:00:00
// Begins at 3:00 AM on the Fourth Saturday of September
// Ends at 4:00 AM on the First Saturday of April
// Adjustment rule from 1/1/2012 to 12/31/9999:
// Delta: 01:00:00
// Begins at 12:00 AM on the Last Sunday of September
// Ends at 1:00 AM on the First Sunday of April
// Line Islands Standard Time transition time information:
// Time zone information:
// Base UTC Offset: 14:00:00
// Supports DST: False
// No adjustment rules defined.
// </Snippet1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="DateStart1.fs" />
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions xml/System/TimeZoneInfo+AdjustmentRule.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
The following example retrieves all time zones defined on the local system and displays complete information about their adjustment rules.

:::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.cs" id="Snippet3":::
:::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.fs" id="Snippet3":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.AdjustmentRule.Class/vb/System.TimeZone2.AdjustmentRule.Class.vb" id="Snippet3":::

The following is a small portion of the output that is generated by the example. The exact output will vary depending on the operating system and the date on which the example is run.
Expand Down Expand Up @@ -253,6 +254,7 @@ dateVariable.Date
The following example creates an alternate Central Standard Time zone and defines three adjustment rules for the periods 1976-1986, 1987-2006, and 2007 and beyond. These rules are added to a generic <xref:System.Collections.Generic.List%601> object whose elements are then copied to a <xref:System.TimeZoneInfo.AdjustmentRule> array. This array is then used in the call to the <xref:System.TimeZoneInfo.CreateCustomTimeZone%28System.String%2CSystem.TimeSpan%2CSystem.String%2CSystem.String%2CSystem.String%2CSystem.TimeZoneInfo.AdjustmentRule%5B%5D%29?displayProperty=nameWithType> method.

:::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.AdjustmentRule.Class/vb/System.TimeZone2.AdjustmentRule.Class.vb" id="Snippet1":::

]]></format>
Expand Down Expand Up @@ -380,6 +382,7 @@ dateVariable.Date
The following example displays information about all of the time zones defined in the local computer's system registry, including the starting and ending dates of their adjustment rules.

:::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/DateStart1.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/DateStart1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TimeZoneInfo.AdjustmentRule.DateStart/vb/DateStart1.vb" id="Snippet1":::

]]></format>
Expand Down Expand Up @@ -448,6 +451,7 @@ dateVariable.Date
The following example displays information about all of the time zones defined in the local computer's system registry, including the starting and ending dates of their adjustment rules.

:::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/DateStart1.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/DateStart1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TimeZoneInfo.AdjustmentRule.DateStart/vb/DateStart1.vb" id="Snippet1":::

]]></format>
Expand Down Expand Up @@ -704,6 +708,7 @@ TimeZoneTime = BaseUtcOffset + DaylightDelta + UtcTime
The following example calls the <xref:System.TimeZoneInfo.AdjustmentRule.Equals%28System.TimeZoneInfo.AdjustmentRule%29?displayProperty=nameWithType> method to compare the adjustment rules for Central Standard Time with those for Canada Central Standard Time and Mexico Standard Time.

:::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.cs" id="Snippet2":::
:::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.AdjustmentRule.Class/vb/System.TimeZone2.AdjustmentRule.Class.vb" id="Snippet2":::

This code displays the following output to the console:
Expand Down