commit d462bc1233a20987df2f1c1f1a3c8ebf14580faa parent f514164bed33fcdc51de6a60b020e1df527e44c2 Author: Daniel Barlow <dan@telent.net> Date: Fri, 8 Aug 2025 21:07:46 +0100 parse iso timestamps (UTC only) Diffstat:
| M | lib.fnl | | | 21 | ++++++++++++++++++++- |
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/lib.fnl b/lib.fnl @@ -65,8 +65,23 @@ :isdst true ; probably? })))) +(fn parse-iso-timestamp [date-str] + (let [(s _ year month day hour min sec frac) + (string.find date-str "(%d+)%-(%d+)%-(%d+)T(%d+):(%d+):(%d+)%.(%d+)Z")] + (and s + (os.time { + : year + : month + : day + : hour + : min + : sec + :isdst false + })))) + (fn parse-timestamp [s] - (or (parse-rfc2822-timestamp s) + (or (parse-iso-timestamp s) + (parse-rfc2822-timestamp s) (parse-emacs-timestamp s))) (define-tests :date-parsing @@ -78,6 +93,10 @@ (expect= (parse-rfc2822-timestamp "Sat Jul 19 23:53:21 2025") nil) (expect= (parse-timestamp "Sat Jul 19 23:53:21 2025") 1752965601) (expect= (parse-timestamp "Wed Aug 8 12:51:52 2018") 1533729112) + + (expect= (parse-timestamp "2024-05-08T12:46:56.865432Z") 1715172416) + + ) {