Reputation: 3
am not a developer i dowloaded theme for WordPress but after i change the language to arabic i had this error message
Uncaught Exception: DateTime::__construct(): Failed to parse time string (٢٠٢٠/٠٢/٠٦ ١٩:٣٠) at position 0 (�): Unexpected character in C:\xampp\htdocs\Carna2\wp-content\themes\motors\inc\woocommerce_setups_rental.php:928 Stack trace: #0
here is code lines with error
/*$date1 = new DateTime(explode(' ', $values['pickup_date'])[0]);
$date2 = new DateTime(explode(' ', $values['return_date'])[0]);
$diff = $date2->diff($date1)->format("%a");*/
$date1 = new DateTime( $values['calc_pickup_date'] );
$date2 = new DateTime( $values['calc_return_date'] );
$diff = $date2->diff( $date1 )->format( "%a.%h" );
$hm = explode('.', $diff);
please keep in mind i dont have any coding experience thnks
Upvotes: 0
Views: 168
Reputation: 1780
In fact the problem is with the arabic input numbers, you need to convert them to normal digits.
If you put the code below it will resolve the error you are having:
//$values = ['calc_pickup_date' => '٢٠٢٠/٠٢/٠٦ ١٩:٣٠','calc_return_date' => '٢٠٢٠/٠٦/٠٦ ١٩:٣٠' ];
// function that converts arabic numbers to standard digits
$convertNumbers = function($str) {
$westernArabic = array('0','1','2','3','4','5','6','7','8','9');
$easternArabic = array('٠','١','٢','٣','٤','٥','٦','٧','٨','٩');
return str_replace($easternArabic, $westernArabic, $str);
};
$values = array_map($convertNumbers, $values); // convert numbers
// The rest of your code but using converted inputs
$date1 = new DateTime( $values['calc_pickup_date'] );
$date2 = new DateTime( $values['calc_return_date'] );
$diff = $date2->diff( $date1 )->format( "%a.%h" );
$hm = explode('.', $diff);
NOTE : I guess you need someone with development skills or try to learn some basics as this issue might be just the beginning ...
Upvotes: 2