This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
src/ServiceStack.Text/Common
tests/ServiceStack.Text.Tests/Utils Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,11 @@ public static DateTime ParseShortestXsdDateTime(string dateTimeStr)
79
79
if ( dateTimeStr . Length == DefaultDateTimeFormat . Length
80
80
|| dateTimeStr . Length == DefaultDateTimeFormatWithFraction . Length )
81
81
{
82
- return DateTime . Parse ( dateTimeStr , CultureInfo . InvariantCulture ) . Prepare ( ) ;
82
+ var unspecifiedDate = DateTime . Parse ( dateTimeStr , CultureInfo . InvariantCulture ) ;
83
+ if ( JsConfig . AssumeUtc )
84
+ unspecifiedDate = DateTime . SpecifyKind ( unspecifiedDate , DateTimeKind . Utc ) ;
85
+
86
+ return unspecifiedDate . Prepare ( ) ;
83
87
}
84
88
85
89
switch ( JsConfig . DateHandler )
Original file line number Diff line number Diff line change @@ -354,6 +354,22 @@ public void DateTime_Is_Serialized_As_Utc_and_Deserialized_as_local()
354
354
}
355
355
}
356
356
357
+ [ Test ]
358
+ public void Does_parse_as_UTC ( )
359
+ {
360
+ JsConfig . AssumeUtc = true ;
361
+
362
+ var dateStr = "2014-08-27 14:30:23" ;
363
+ var dateTime = dateStr . FromJson < DateTime > ( ) ;
364
+
365
+ Assert . That ( dateTime . Kind , Is . EqualTo ( DateTimeKind . Utc ) ) ;
366
+ Assert . That ( dateTime . Hour , Is . EqualTo ( 14 ) ) ;
367
+ Assert . That ( dateTime . Minute , Is . EqualTo ( 30 ) ) ;
368
+ Assert . That ( dateTime . Second , Is . EqualTo ( 23 ) ) ;
369
+
370
+ JsConfig . Reset ( ) ;
371
+ }
372
+
357
373
[ Test ]
358
374
public void Can_serialize_nullable_DateTime ( )
359
375
{
You can’t perform that action at this time.
0 commit comments