diff --git a/.ikc3_history b/.ikc3_history
index 571864b..2031d04 100644
--- a/.ikc3_history
+++ b/.ikc3_history
@@ -1,5 +1,3 @@
-quote [a: 1, b: 2]
-[a: 1, b: 2]
AList.to_map([a: 1, b: 2])
1 + 1
1 + 100000000000000000000000000000000000000000000000000000000
@@ -97,4 +95,6 @@ Crypt.sha512("Plop", "$6$rounds=123456$abc0123456789$")
1 + 1
1 + 10000000000000000000000000000000000000000000
Time.from_str("1970-01-01 00:00:00")
+Time.from_str("2024-10-31 23:00:00")
+Time.to_str(Time.from_str("2024-10-31 23:00:00"))
diff --git a/lib/kc3/0.1/time.kc3 b/lib/kc3/0.1/time.kc3
index ce347f9..274a2bf 100644
--- a/lib/kc3/0.1/time.kc3
+++ b/lib/kc3/0.1/time.kc3
@@ -6,4 +6,6 @@ defmodule Time do
def from_str = cfn Time "time_init_str" (Result, Str)
+ def to_str = cfn Str "time_to_str" (Time, Result)
+
end
diff --git a/libkc3/time.c b/libkc3/time.c
index ca961f5..7779f66 100644
--- a/libkc3/time.c
+++ b/libkc3/time.c
@@ -13,6 +13,7 @@
#include <stdlib.h>
#include "alloc.h"
#include "assert.h"
+#include "str.h"
#include "tag.h"
#include "time.h"
@@ -131,6 +132,25 @@ f64 * time_to_f64 (const s_timespec *time, f64 *dest)
return dest;
}
+s_str * time_to_str (const s_time *time, s_str *dest)
+{
+ char a[64] = {0};
+ time_t t;
+ const struct tm *tm;
+ t = time->tv_sec;
+ if (! (tm = gmtime(&t))) {
+ err_puts("time_to_str: gmtime");
+ assert(! "time_to_str: gmtime");
+ return NULL;
+ }
+ if (! strftime(a, sizeof(a), "%F %T", tm)) {
+ err_puts("time_to_str: strftime");
+ assert(! "time_to_str: strftime");
+ return NULL;
+ }
+ return str_init_copy_1(dest, a);
+}
+
s_tag * time_to_tag (const s_timespec *time, s_tag *dest)
{
s_tag tmp = {0};
diff --git a/libkc3/time.h b/libkc3/time.h
index 60944c5..a44493d 100644
--- a/libkc3/time.h
+++ b/libkc3/time.h
@@ -31,6 +31,7 @@ s_time * time_init_str (s_time *time, const s_str *src);
/* Observers */
f64 * time_to_f64 (const s_timespec *time, f64 *dest);
+s_str * time_to_str (const s_time *time, s_str *dest);
s_tag * time_to_tag (const s_timespec *time, s_tag *dest);
/* Operators */