-module(kitazith@timestamp). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/kitazith/timestamp.gleam"). -export([from_rfc3339/1, from_unix_seconds/1, to_string/1, to_json/1]). -export_type([timestamp/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -opaque timestamp() :: {timestamp, gleam@time@timestamp:timestamp()}. -file("src/kitazith/timestamp.gleam", 14). ?DOC(" Parse an RFC 3339 string into a `Timestamp`.\n"). -spec from_rfc3339(binary()) -> {ok, timestamp()} | {error, nil}. from_rfc3339(Input) -> case gleam@time@timestamp:parse_rfc3339(Input) of {ok, Ts} -> {ok, {timestamp, Ts}}; {error, nil} -> {error, nil} end. -file("src/kitazith/timestamp.gleam", 22). ?DOC(" Create a `Timestamp` from Unix seconds.\n"). -spec from_unix_seconds(integer()) -> timestamp(). from_unix_seconds(Seconds) -> {timestamp, gleam@time@timestamp:from_unix_seconds(Seconds)}. -file("src/kitazith/timestamp.gleam", 27). ?DOC(" Convert a `Timestamp` to an RFC 3339 string in UTC.\n"). -spec to_string(timestamp()) -> binary(). to_string(Ts) -> gleam@time@timestamp:to_rfc3339(erlang:element(2, Ts), {duration, 0, 0}). -file("src/kitazith/timestamp.gleam", 32). ?DOC(" Serialize a `Timestamp` to JSON as an RFC 3339 string.\n"). -spec to_json(timestamp()) -> gleam@json:json(). to_json(Ts) -> gleam@json:string(to_string(Ts)).