Fork me on GitHub
#juxt
<
2023-04-28
>
Cezary17:04:56

Hey guys, is there a better way to read time given in epoch seconds in tick in the other way than below? The docs didn't help me - maybe my mistake.

(defn epoch->time [seconds]
  (t/>> (t/epoch) (t/new-duration seconds :seconds)))
Is this really the way I should do it? I hope not. Seems sketchy.

tomd17:04:17

I don't think tick has this built in, but cljc-time (which tick uses) has of-epoch-second if that's helpful to you

Cezary17:04:48

Ayyyy so many time libraries

😆 2
tomd17:04:41

I'd say make an issue or PR to add to tick, but I'm not sure how common parsing epoch seconds is :thinking_face:

Cezary17:04:51

Well... I guessed common enough to have support in a new lib. Thanks for the tip. Will do.

👍 2
dcj19:05:57

> I'm not sure how common parsing epoch seconds is For me, pretty common. Lots of systems/APIs report time in epoch seconds or epoch milliseconds, and I convert/coerce them to a zoned datetime ASAP. My utility fns:

(defn ems->
  ([x]
   (ems-> "UTC" x))
  ([tz x]
   (-> x
       t/instant
       (t/in tz))))


(defn es->
  ([x]
   (es-> "UTC" x))
  ([tz x]
   (ems-> tz (* x 1000))))
N.B "ems" == Epoch Milli Seconds, and "es" == Epoch Seconds

👍 2
Cezary14:05:39

Thanks, that's exactly what I did (-> seconds (* 1000) t/instant). *Therefore I take back the lack of epoch parsing in tick.* https://github.com/juxt/tick/issues/186.