A => Iso8601ToPosix.js +26 -0
@@ 1,26 @@
+const pad = n => n<10 ? '0'+n : n;
+
+const ISODateString = d =>
+ d.getUTCFullYear()+'-' + pad(d.getUTCMonth()+1)+'-' + pad(d.getUTCDate())+'T00:00Z';
+
+class Iso8601ToPosix {
+ evaluate() {
+ const ms = Date.parse(this.value);
+
+ if (isNaN(ms)) return "invalid";
+
+ return ms/1000|0;
+ }
+
+ text() { return isNaN(Date.parse(this.value)) ? "invalid" : this.value; }
+}
+
+Iso8601ToPosix.inputs = [
+ InputField("value", "Value", "String", {defaultValue: ISODateString(new Date())}),
+];
+
+Iso8601ToPosix.title = "ISO 8601 to Posix";
+Iso8601ToPosix.help = "https://git.sr.ht/~ehamberg/paw-iso8601-to-posix";
+Iso8601ToPosix.identifier = "no.hamberg.Iso8601ToPosix";
+
+registerDynamicValueClass(Iso8601ToPosix)
A => README.md +6 -0
@@ 1,6 @@
+# Iso8601ToPosix
+
+Simple [Paw](https://paw.cloud) dynamic value for converting from ISO 8601 to
+POSIX/Unix time (seconds since 1970-01-01).
+
+Licence: BSD-3-Clause OR Apache-2.0