~pepe/bearimy

cce0f8de525525458f2ad9acd9c9b3e63bef8e7d — Josef Pospíšil 4 months ago 773ee17
Fix human date
2 files changed, 8 insertions(+), 9 deletions(-)

M bearimy/utils.janet
M test/suite1.janet
M bearimy/utils.janet => bearimy/utils.janet +7 -8
@@ 1,4 1,4 @@
(use bearimy)
(use ./init)

(defn format-date-time [dt]
  (:format (make-date-time dt)))


@@ 97,11 97,10 @@
  (make-date (merge tdy {:year (+ (tdy :year) n)} year-start month-start)))

(defn current-year-start [&opt tdy]
  (start-of-year 0))
  (start-of-year 0 tdy))

(defn human [dt &opt dtn]
  (default dtn (now))
  (def cn (make-calendar dtn))
  (def cn (make-calendar (or dtn (now))))
  (def cdt (make-calendar dt))
  (cond
    (:contains? (make-period (:sooner cn {:minutes 1}) {:minutes 2}) cdt)


@@ 120,10 119,10 @@
    (let [dist (math/ceil (/ (- (:epoch cn) (:epoch cdt))
                             (* 7 24 3600)))]
      (string dist " weeks ago"))
    (= (dec (cn :year)) (cdt :year))
    "last year"
    (:contains? (make-period (:sooner cn {:days 365})
    (:contains? (make-period (:sooner cn {:days 364})
                             {:days 338}) cdt)
    (let [dist (math/ceil (/ (- (:epoch cn) (:epoch cdt))
                             (* 30 24 3600)))]
      (string dist " months ago"))))
      (string dist " months ago"))
    (= (dec (cn :year)) (cdt :year))
    "last year"))

M test/suite1.janet => test/suite1.janet +1 -1
@@ 159,7 159,7 @@
(assert (= (human (:sooner dtn {:hours 47}) dtn) "Saturday")
        "2 days ago")

(assert (= (human (:sooner dtn {:hours 71}) dtn ) "Friday")
(assert (= (human (:sooner dtn {:hours 71}) dtn) "Friday")
        "3 days ago")

(assert (= (human (:sooner dtn {:hours 95}) dtn) "Thursday")