I'm developing a website with CodeIgniter(PHP 7.1.1), in the client side, i need to send some dates to the server:
var date_str = date.toLocaleDateString();
var time_str = date.toLocaleTimeString().split(':');
time_str = time_str[0] + ':' + time_str[1];
...
data_to_ajax = {
date: inicio,
date2: termino
};
...
the server will validate those dates using:
DateTime::createFromFormat('d/m/Y H:i', $date);
DateTime::createFromFormat('d/m/Y H:i', $date2);
It works fine, except when using microsoft Edge, createFromFormat
will always return false for the date sent. To debug i called var_dump
on the dates sent and what i get is:
string(43) "29/08/2017 21:00"
string(31) "29/08/2017 23:30"
While in chrome and mozilla what i get is:
string(16) "29/08/2017 21:00"
string(16) "29/08/2017 23:30"
Well, debugging the http body data sent, chrome and mozilla will send 63 bytes:
date_loc=29%2F08%2F2017+21%3A00&date_ter=29%2F08%2F2017+23%3A30
while edge send 189(63*3) bytes:
date_loc=%E2%80%8E28%E2%80%8E%2F%E2%80%8E08%E2%80%8E%2F%E2%80%8E2017+%E2%80%8E21%E2%80%8E%3A%E2%80%8E00%E2%80%8E&date_ter=%E2%80%8E28%E2%80%8E%2F%E2%80%8E08%E2%80%8E%2F%E2%80%8E2017+23%3A30
Both seems right, because this: url encoder/decoder can decode them, the problems seems to be with the server, why would php show that two strings with the same number of characters have a different length? it is even more weird that var_dump
can display those strings normally, but createDateFromFormat
will fail.