~pepe/bearimy

6a62fa20af9f7d450973411851bac2fef83ddc2a — Josef Pospíšil 4 months ago cce0f8d
Add local-time dyn
2 files changed, 12 insertions(+), 5 deletions(-)

M bearimy/init.janet
M test/suite0.janet
M bearimy/init.janet => bearimy/init.janet +7 -5
@@ 50,13 50,15 @@
                       (get-in week-days [:short wd]) (inc d) (get-in months [:short m]) y h u s))}
    Date))

(defn- table-date [] (merge (os/date)))
(defn- table-date [&opt dt]
  (default dt (os/time))
  (merge (os/date dt (dyn :local-time))))

(defn now []
  (make DateTime (table-date)))

(defn today []
  (make Date (merge (table-date) midnite)))
  (make Date (merge-into (table-date) midnite)))

(defn- nc [c &opt dc] (fn [n] {c ((if dc dec identity) (scan-number n))}))
(defn- mc [& cs] (merge ;cs))


@@ 94,16 96,16 @@
  (case (type x)
    :table x
    :struct (merge x)
    :number (merge (os/date x))
    :number (table-date x)
    :string (from-string x)))

(defn make-date [date] # name?
  (def d (normalize date))
  (make Date (merge (os/date (os/mktime (merge d midnite))))))
  (make Date (table-date (os/mktime (merge d midnite)))))

(defn make-date-time [date-time]
  (def dt (normalize date-time))
  (make DateTime (merge (os/date (os/mktime (merge dt))))))
  (make DateTime (table-date (os/mktime dt))))

(def Interval
  @{:format

M test/suite0.janet => test/suite0.janet +5 -0
@@ 352,4 352,9 @@

(assert (= (:in-minutes (make-interval {:hours 1})) 60) "in-minutes")

(def non-local-now (now))
(with-dyns [:local-time true]
  (assert (= (inc (non-local-now :hours)) ((now) :hours))
          "local now")) # NB: CEST

(end-suite)