peachpie
peachpie copied to clipboard
DateTime doesn't support the years <=0 or > 9999
Sample:
$datetime = DateTime::createFromFormat("Y-m-d", "00-01-01");
echo var_dump($datetime) . "\r\n";
PeachPie output:
Unhandled Exception: System.ArgumentOutOfRangeException: Year must be between 1 and 9999.
Parameter name: year
at System.DateTime.IsLeapYear(Int32 year)
at System.DateTime.DaysInMonth(Int32 year, Int32 month)
at Pchp.Library.DateTime.DateInfo.CheckOverflows(Int32 y, Int32 m, Int32& d, Int32& h, Int32& days_overflow)
at Pchp.Library.DateTime.DateInfo.GetDateTime(Context ctx, DateTime utcStart)
at Pchp.Library.DateTime.DateTime.createFromFormat(Context ctx, String format, String time, DateTimeZone timezone)
at <Root>.main_php.<Main>(Context <ctx>, PhpArray <locals>, Object this, RuntimeTypeHandle <self>) in /mnt/c/Development/laravel-peachpie-sample/Laravel.Tests/main.php:line 32
at <Script>.Main(String[] args)
PHP output:
object(DateTime)#1 (3) {
["date"]=>
string(26) "0000-01-01 13:35:46.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Berlin"
}
seems the year 0
is not supported by .NET's DateTime
Might it be feasible to port the time library used by PHP to C# ? https://github.com/derickr/timelib
An alternative would be to use the prebuilt library, but that introduces a native dependency in the codebase
@smx-smx you are right - one of the feasible solutions would be to port timelib (which we partially did in order to implement datetime parsing and formatting)
native dependency is not possible, peachpie is managed and crossplatform.
In general, we're trying to make maximum use of .NET standard which already has faster and more powerful DateTime API. We're trying to minimize the actual code being a part of peachpie, and the use of DateTime provides all what's needed.
One of the solutions would be to add an year offset to our existing DateTime value ..