@@ -4037,13 +4037,20 @@ public static char FastStringToChar(string value) {
40374037 }
40384038
40394039 public static DateTimeOffset FastStringToDateTimeoffset ( string value , NetJSONSettings settings ) {
4040- var date = FastStringToDate ( value , settings ) ;
4041- return new DateTimeOffset ( date ) ;
4040+ TimeSpan offset ;
4041+ var date = StringToDate ( value , settings , out offset , isDateTimeOffset : true ) ;
4042+ return new DateTimeOffset ( date . Ticks , offset ) ;
40424043 }
40434044
40444045 private static char [ ] _dateNegChars = new [ ] { '-' } ,
40454046 _datePosChars = new [ ] { '+' } ;
40464047 public static DateTime FastStringToDate ( string value , NetJSONSettings settings ) {
4048+ TimeSpan offset ;
4049+ return StringToDate ( value , settings , out offset , isDateTimeOffset : false ) ;
4050+ }
4051+
4052+ private static DateTime StringToDate ( string value , NetJSONSettings settings , out TimeSpan offset , bool isDateTimeOffset ) {
4053+ offset = TimeSpan . Zero ;
40474054 if ( settings . DateFormat == NetJSONDateFormat . EpochTime ) {
40484055 var unixTimeStamp = FastStringToLong ( value ) ;
40494056 var date = new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , 0 , System . DateTimeKind . Utc ) ;
@@ -4090,14 +4097,14 @@ public static DateTime FastStringToDate(string value, NetJSONSettings settings)
40904097 var hasOffset = diff > 0 ;
40914098 var utcOffsetText = hasOffset ? value . Substring ( dateText . Length , diff ) : string . Empty ;
40924099 var firstChar = utcOffsetText [ 0 ] ;
4093- negative = diff > 0 && firstChar == '-' ;
4100+ negative = diff > 0 && firstChar == '-' ;
40944101 if ( hasOffset ) {
40954102 noOffSetValue = timeZoneFormat == NetJSONTimeZoneFormat . Utc || timeZoneFormat == NetJSONTimeZoneFormat . Unspecified ;
40964103 offsetText = utcOffsetText . Substring ( 1 , utcOffsetText . Length - 1 ) . Replace ( ":" , string . Empty ) . Replace ( "Z" , string . Empty ) ;
40974104 if ( timeZoneFormat == NetJSONTimeZoneFormat . Local ) {
40984105 int indexOfSign = offsetText . IndexOf ( '-' ) ;
40994106 negative = indexOfSign >= 0 ;
4100- if ( ! negative ) {
4107+ if ( ! negative ) {
41014108 indexOfSign = offsetText . IndexOf ( '+' ) ;
41024109 }
41034110 tickMilliseconds = FastStringToInt ( offsetText . Substring ( 0 , indexOfSign ) ) ;
@@ -4112,7 +4119,8 @@ public static DateTime FastStringToDate(string value, NetJSONSettings settings)
41124119 }
41134120 dt = DateTime . Parse ( dateText , CultureInfo . CurrentCulture , DateTimeStyles . AdjustToUniversal ) ;
41144121 if ( timeZoneFormat == NetJSONTimeZoneFormat . Local ) {
4115- dt = dt . ToUniversalTime ( ) ;
4122+ if ( ! isDateTimeOffset )
4123+ dt = dt . ToUniversalTime ( ) ;
41164124 dt = new DateTime ( dt . Year , dt . Month , dt . Day , dt . Hour , dt . Minute , dt . Second , dt . Millisecond , DateTimeKind . Local ) ;
41174125 } else if ( timeZoneFormat == NetJSONTimeZoneFormat . Utc ) {
41184126 dt = new DateTime ( dt . Year , dt . Month , dt . Day , dt . Hour , dt . Minute , dt . Second , dt . Millisecond , DateTimeKind . Utc ) ;
@@ -4132,8 +4140,10 @@ public static DateTime FastStringToDate(string value, NetJSONSettings settings)
41324140 var minutes = noOffSetValue ? 0 : ( offsetText . Length > 2 ? FastStringToInt ( offsetText . Substring ( 2 , 2 ) ) : 0 ) ;
41334141 if ( negative )
41344142 hours *= - 1 ;
4135-
4136- dt = dt . AddHours ( hours ) . AddMinutes ( minutes ) . AddTicks ( tickMilliseconds ) ;
4143+ offset = new TimeSpan ( hours , minutes , 0 ) ;
4144+ if ( ! isDateTimeOffset )
4145+ dt = dt . AddHours ( hours ) . AddMinutes ( minutes ) ;
4146+ dt = dt . AddTicks ( tickMilliseconds ) ;
41374147 }
41384148
41394149 return dt ;
0 commit comments