From 24b332c68257cb4c51f21ad2381c660b630a6826 Mon Sep 17 00:00:00 2001 From: Michael Sippel <micha@fragmental.art> Date: Wed, 19 Mar 2025 17:27:04 +0100 Subject: [PATCH] add morphism for unix-timestamp to iso8601 --- morphisms/timepoint.morphism-base | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 morphisms/timepoint.morphism-base diff --git a/morphisms/timepoint.morphism-base b/morphisms/timepoint.morphism-base new file mode 100644 index 0000000..39f5822 --- /dev/null +++ b/morphisms/timepoint.morphism-base @@ -0,0 +1,15 @@ +``` +#include <time.h> +``` + +morph_unixtime_to_iso () + TimePoint ~ <TimeSince UnixEpoch> ~ Duration ~ Seconds ~ ℝ ~ <QuantizedLinear 0 1 1> ~ ℕ ~ x86.UInt64 +--> TimePoint ~ ISO8601 ~ <Seq~<ValueTerminated 0> Char~Ascii~x86.UInt8> +``` + time_t rawtime = (time_t)(*src); + struct tm *timeinfo = gmtime(&rawtime); + if (!timeinfo) return -1; + + strftime((char*)dst, 20, "%Y-%m-%dT%H:%M:%SZ", timeinfo); + return 0; +```