You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 25, 2026. It is now read-only.
Perhaps a cool feature would be to allow for Php datetime objects to be directly translated to native System.DateTime.
I don't need this myself but it should be easy enough to implement - i have this code-snippet that does the job halfway already which we can use - so just posting this as a nice to have backlog item ^^.
privatestaticDateTime?ParsePhpDateTimeStringSafe(stringdateString,stringtimezone,longtimezoneType){try{returnParsePhpDateTimeString(dateString,timezone,timezoneType);}catch{// We're swallowing exceptions because we'll be handling null values instead.returnnull;}}privatestaticDateTimeParsePhpDateTimeString(stringdateString,stringtimezone,longtimezoneType){varlocalDateTimePattern=LocalDateTimePattern.CreateWithInvariantCulture("yyyy-MM-dd HH:mm:ss.ffffff");varlocalDateTime=localDateTimePattern.Parse(dateString).GetValueOrThrow();// See: https://stackoverflow.com/a/17711005/4122889// Type 1; A UTC offset, such as in new DateTime("17 July 2013 -0300");// Type 2; A timezone abbreviation, such as in new DateTime("17 July 2013 GMT");// Type 3: A timezone identifier, such as in new DateTime("17 July 2013", new DateTimeZone("Europe/London"));switch(timezoneType){case1:varoffSetPattern=OffsetPattern.CreateWithInvariantCulture("+HH:mm");varoffset=offSetPattern.Parse(timezone).Value;varzonedDateTimeFromOffset=localDateTime.InZoneStrictly(DateTimeZone.ForOffset(offset));returnzonedDateTimeFromOffset.ToDateTimeUtc();case2:thrownewNotSupportedException("Not (Yet) support converting from timeZonetype 2 - but doable to add in!");case3:vardateTimeZone=DateTimeZoneProviders.Tzdb[timezone];varzonedDateTime=dateTimeZone.AtStrictly(localDateTime);vardateTimeUtc=zonedDateTime.ToDateTimeUtc();returndateTimeUtc;default:thrownewArgumentOutOfRangeException(nameof(timezoneType));}}
This does however use the NodaTime package which may not be a dependency we'd like. Optionally we could move this to a seperate package to give consumers more control over this.
We may also be able to get the code working without NodaTime, perhaps with something like https://github.com/mattjohnsonpint/TimeZoneNames for the timezonedb values but i have not given this much thought.
Perhaps a cool feature would be to allow for Php datetime objects to be directly translated to native System.DateTime.
I don't need this myself but it should be easy enough to implement - i have this code-snippet that does the job halfway already which we can use - so just posting this as a nice to have backlog item ^^.
This does however use the NodaTime package which may not be a dependency we'd like. Optionally we could move this to a seperate package to give consumers more control over this.
We may also be able to get the code working without NodaTime, perhaps with something like https://github.com/mattjohnsonpint/TimeZoneNames for the timezonedb values but i have not given this much thought.