accept more datetime formats
authorGeoffrey Allott <geoffrey@allott.email>
Wed, 9 Aug 2023 17:59:45 +0000 (18:59 +0100)
committerGeoffrey Allott <geoffrey@allott.email>
Wed, 9 Aug 2023 17:59:45 +0000 (18:59 +0100)
site/modules/datetime.js

index 94994034902085922af86e38acc12a9388c4172c..50c219f7ba7e1d015ea0965ca55845cd1dad1cf8 100644 (file)
@@ -1,5 +1,5 @@
 export function parse_datetime(input) {
-    const re = /^(?:(?<year>[0-9]{4})-(?<month>[0-9]{1,2})-(?<day>[0-9]{1,2})\s)?\s*(?<hour>[0-9]{1,2}):(?<minute>[0-9]{2})(?::(?<second>[0-9]{2}))?$/;
+    const re = /^(?:(?<year>[0-9]{4})-(?<month>[0-9]{1,2})-(?<day>[0-9]{1,2})\s)?\s*(?<hour>[0-9]{1,2}):(?<minute>[0-9]{1,2})(?::(?<second>[0-9]{1,2}))?$/;
     const match = input.match(re);
     if (match === null) return null;
     const datetime = new Date();
@@ -30,7 +30,7 @@ export function stringify_datetime(millis) {
 }
 
 export function parse_duration(input) {
-    const re = /^(?:(?<hours>[0-9]{1,2}):)?(?<minutes>[0-9]{2}):(?<seconds>[0-9]{2})$/;
+    const re = /^(?:(?<hours>[0-9]{1,2}):)?(?<minutes>[0-9]{1,2}):(?<seconds>[0-9]{1,2})$/;
     const match = input.match(re);
     if (match === null) return null;
     return ((((match.groups.hours !== undefined ? +match.groups.hours : 0) * 60 + +match.groups.minutes) * 60) + +match.groups.seconds) * 1000;