diff --git a/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/DateStart1.fs b/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/DateStart1.fs new file mode 100644 index 00000000000..1bc77201770 --- /dev/null +++ b/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/DateStart1.fs @@ -0,0 +1,83 @@ +// +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 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 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. +// \ No newline at end of file diff --git a/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/fs.fsproj b/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/fs.fsproj new file mode 100644 index 00000000000..fd81f6b202f --- /dev/null +++ b/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/xml/System/TimeZoneInfo+AdjustmentRule.xml b/xml/System/TimeZoneInfo+AdjustmentRule.xml index 3e635f98b70..903709b6861 100644 --- a/xml/System/TimeZoneInfo+AdjustmentRule.xml +++ b/xml/System/TimeZoneInfo+AdjustmentRule.xml @@ -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. @@ -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 object whose elements are then copied to a array. This array is then used in the call to the 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"::: ]]> @@ -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"::: ]]> @@ -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"::: ]]> @@ -704,6 +708,7 @@ TimeZoneTime = BaseUtcOffset + DaylightDelta + UtcTime The following example calls the 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: