Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strptime in Javascript

I have a date input field that allows the user to enter in a date and I need to validate this input (I already have server side validation), but the trick is that the format is locale dependent. I already have a system for translating the strptime format string to the the user's preference and I would like to use this same format for validating on the Javascript side.

Any ideas or links to a strptime() implementation in Javascript?

like image 326
mpeters Avatar asked Nov 14 '22 16:11

mpeters


2 Answers

After a few days of googling I found this implementation which, although not complete, seems to handle all of the cases I have right now.

like image 75
mpeters Avatar answered Dec 15 '22 03:12

mpeters


I've just added our php.js implementation of strptime(); I've tested it a bit, but it needs further unit testing. Anyhow, feel free to give it a shot; it should cover everything that PHP does (except for not yet supporting the undocumented %E... (alternative locale format) specifiers).

Note that it also depends on our implementation of setlocale() and array_map()...

  • https://github.com/kvz/phpjs/blob/master/functions/strings/setlocale.js
  • https://github.com/kvz/phpjs/blob/master/functions/array/array_map.js
like image 22
Brett Zamir Avatar answered Dec 15 '22 01:12

Brett Zamir