This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
src/ServiceStack.Text/Common
tests/ServiceStack.Text.Tests/Utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,7 +79,11 @@ public static DateTime ParseShortestXsdDateTime(string dateTimeStr)
7979 if ( dateTimeStr . Length == DefaultDateTimeFormat . Length
8080 || dateTimeStr . Length == DefaultDateTimeFormatWithFraction . Length )
8181 {
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 ( ) ;
8387 }
8488
8589 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()
354354 }
355355 }
356356
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+
357373 [ Test ]
358374 public void Can_serialize_nullable_DateTime ( )
359375 {
You can’t perform that action at this time.
0 commit comments