@@ -82,9 +82,12 @@ public enum DateTimeKind
82
82
#endif // NANOCLR_REFLECTION
83
83
public struct DateTime
84
84
{
85
- /// Our origin is at 1601/01/01:00:00:00.000
86
- /// While desktop CLR's origin is at 0001/01/01:00:00:00.000.
87
- /// There are 504911232000000000 ticks between them which we are subtracting.
85
+ // Our origin is at 1601/01/01:00:00:00.000
86
+ // While desktop CLR's origin is at 0001/01/01:00:00:00.000.
87
+ // There are 504911232000000000 ticks between them which we are subtracting.
88
+ //////////////////////////////////////////////////////////////////////////////////////////
89
+ /// Keep in sync with native define TICKS_AT_ORIGIN @ corlib_native_System_DateTime.cpp //
90
+ //////////////////////////////////////////////////////////////////////////////////////////
88
91
[ DebuggerBrowsable ( DebuggerBrowsableState . Never ) ]
89
92
private const long _ticksAtOrigin = 504911232000000000 ;
90
93
@@ -195,7 +198,7 @@ public DateTime(long ticks)
195
198
/// nanoFramework doesn't support local time, only UTC, so it's not possible to specify <see cref="DateTimeKind.Local"/>.
196
199
/// </remarks>
197
200
public DateTime ( long ticks , DateTimeKind kind )
198
- : this ( ticks )
201
+ : this ( ticks )
199
202
{
200
203
// it's OK to check kind parameter only here
201
204
// if it's invalid the exception will be thrown anyway and allows the constructor to be reused
@@ -505,8 +508,7 @@ public int Month
505
508
/// </value>
506
509
public static DateTime UtcNow
507
510
{
508
- [ MethodImpl ( MethodImplOptions . InternalCall ) ]
509
- get => new DateTime ( ) ;
511
+ get => new DateTime ( GetUtcNowAsTicks ( ) , DateTimeKind . Utc ) ;
510
512
}
511
513
512
514
/// <summary>
@@ -556,8 +558,7 @@ public TimeSpan TimeOfDay
556
558
/// </value>
557
559
public static DateTime Today
558
560
{
559
- [ MethodImpl ( MethodImplOptions . InternalCall ) ]
560
- get => new DateTime ( ) ;
561
+ get => new DateTime ( GetTodayAsTicks ( ) , DateTimeKind . Utc ) ;
561
562
}
562
563
563
564
/// <summary>
@@ -826,10 +827,10 @@ public static bool TryParse(
826
827
string s ,
827
828
out DateTime result )
828
829
{
829
- result = Convert . NativeToDateTime (
830
- s ,
830
+ Convert . NativeToDateTime ( s ,
831
831
false ,
832
- out bool success ) ;
832
+ out bool success ,
833
+ out result ) ;
833
834
834
835
return success ;
835
836
}
@@ -839,5 +840,11 @@ public static bool TryParse(
839
840
840
841
[ MethodImpl ( MethodImplOptions . InternalCall ) ]
841
842
private extern int GetDateTimePart ( DateTimePart part ) ;
843
+
844
+ [ MethodImpl ( MethodImplOptions . InternalCall ) ]
845
+ private extern static long GetUtcNowAsTicks ( ) ;
846
+
847
+ [ MethodImpl ( MethodImplOptions . InternalCall ) ]
848
+ private extern static long GetTodayAsTicks ( ) ;
842
849
}
843
850
}
0 commit comments