Skip to content

Commit c026fa2

Browse files
Crown0815BillWagner
authored andcommitted
Clarify DateTime implicit conversion example (#850)
* Clarify DateTime implicit conversion example It took some time for me to understand why the last example has -08:00 as offset. Since the example seemed to be about the addition of a TimeSpan the change in offset was quite confusing. Therefore, I split the example into two parts, one only focusing on the addition of a TimeSpan and the second on the adaption of the daylight time specific time zone. I also fixed a typo in the year given in line 84. * Clarify DateTime implicit conversion VB example Adaption of changes made to the C# example in commit e1833f1 to the Visual Basic sample base. This change was made based on the feedback received to [PR #850](#850 (comment))
1 parent 70a6f01 commit c026fa2

File tree

2 files changed

+20
-6
lines changed
  • snippets
    • csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/cs
    • visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb

2 files changed

+20
-6
lines changed

snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/cs/Operators.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private static void ShowImplicitConversions()
8181
{
8282
// <Snippet7>
8383
DateTimeOffset timeWithOffset;
84-
timeWithOffset = new DateTime(1008, 7, 3, 18, 45, 0);
84+
timeWithOffset = new DateTime(2008, 7, 3, 18, 45, 0);
8585
Console.WriteLine(timeWithOffset.ToString());
8686

8787
timeWithOffset = DateTime.UtcNow;
@@ -91,15 +91,22 @@ private static void ShowImplicitConversions()
9191
DateTimeKind.Unspecified);
9292
Console.WriteLine(timeWithOffset.ToString());
9393

94-
timeWithOffset = new DateTime(2008, 1, 1, 2, 30, 0) +
95-
new TimeSpan(1, 0, 0, 0);
94+
timeWithOffset = new DateTime(2008, 7, 1, 2, 30, 0) +
95+
new TimeSpan(1, 0, 0, 0);
96+
Console.WriteLine(timeWithOffset.ToString());
97+
98+
timeWithOffset = new DateTime(2008, 1, 1, 2, 30, 0)
9699
Console.WriteLine(timeWithOffset.ToString());
97100
// The example produces the following output if run on 3/20/2007
98101
// at 6:25 PM on a computer in the U.S. Pacific Daylight Time zone:
99102
// 7/3/2008 6:45:00 PM -07:00
100103
// 3/21/2007 1:25:52 AM +00:00
101104
// 3/20/2007 6:25:52 PM -07:00
102-
// 1/2/2008 2:30:00 AM -08:00
105+
// 7/2/2008 2:30:00 AM -07:00
106+
// 1/1/2008 2:30:00 AM -08:00
107+
//
108+
// The last example shows automatic adaption to the U.S. Pacific Time
109+
// for winter dates.
103110
// </Snippet7>
104111
}
105112

snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,21 @@ Module modMain
121121
timeWithOffset = Date.SpecifyKind(Date.Now, DateTimeKind.Unspecified)
122122
Console.WriteLine(timeWithOffset.ToString())
123123

124-
timeWithOffset = #1/1/2008 2:30AM# + New TimeSpan(1, 0, 0, 0)
124+
timeWithOffset = #07/01/2008 2:30AM# + New TimeSpan(1, 0, 0, 0)
125+
Console.WriteLine(timeWithOffset.ToString())
126+
127+
timeWithOffset = #01/01/2008 2:30AM#
125128
Console.WriteLine(timeWithOffset.ToString())
126129
' The example produces the following output if run on 3/20/2007
127130
' at 6:25 PM on a computer in the U.S. Pacific Daylight Time zone:
128131
' 7/3/2008 6:45:00 PM -07:00
129132
' 3/21/2007 1:25:52 AM +00:00
130133
' 3/20/2007 6:25:52 PM -07:00
131-
' 1/2/2008 2:30:00 AM -08:00
134+
' 7/2/2008 2:30:00 AM -07:00
135+
' 1/1/2008 2:30:00 AM -08:00
136+
'
137+
' The last example shows automatic adaption to the U.S. Pacific Time
138+
' for winter dates.
132139
' </Snippet7>
133140
End Sub
134141

0 commit comments

Comments
 (0)