fix relative time display for long-ago dates
This commit is contained in:
parent
f3ae3e2dc1
commit
b8393b39a5
|
@ -1,7 +1,7 @@
|
||||||
(ns commiteth.activity
|
(ns commiteth.activity
|
||||||
(:require [re-frame.core :as rf]
|
(:require [re-frame.core :as rf]
|
||||||
[reagent.core :as r]
|
[reagent.core :as r]
|
||||||
[commiteth.common :refer [relative-time
|
[commiteth.common :refer [human-time
|
||||||
items-per-page
|
items-per-page
|
||||||
display-data-page
|
display-data-page
|
||||||
issue-url]]))
|
issue-url]]))
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
^{:key (random-uuid)}
|
^{:key (random-uuid)}
|
||||||
[:div.balance-badge.token
|
[:div.balance-badge.token
|
||||||
(str (subs (str tla) 1) " " balance)])])
|
(str (subs (str tla) 1) " " balance)])])
|
||||||
[:div.time (relative-time updated)]]]])
|
[:div.time (human-time updated)]]]])
|
||||||
|
|
||||||
(defn activity-list [{:keys [items item-count page-number total-count]
|
(defn activity-list [{:keys [items item-count page-number total-count]
|
||||||
:as activity-page-data}
|
:as activity-page-data}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(ns commiteth.bounties
|
(ns commiteth.bounties
|
||||||
(:require [reagent.core :as r]
|
(:require [reagent.core :as r]
|
||||||
[re-frame.core :as rf]
|
[re-frame.core :as rf]
|
||||||
[commiteth.common :refer [relative-time
|
[commiteth.common :refer [human-time
|
||||||
display-data-page
|
display-data-page
|
||||||
items-per-page
|
items-per-page
|
||||||
issue-url]]
|
issue-url]]
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
[:div.open-bounty-item-content
|
[:div.open-bounty-item-content
|
||||||
[:div.header issue-link]
|
[:div.header issue-link]
|
||||||
[:div.bounty-item-row
|
[:div.bounty-item-row
|
||||||
[:div.time (relative-time updated)]
|
[:div.time (human-time updated)]
|
||||||
[:span.bounty-repo-label repo-link]]
|
[:span.bounty-repo-label repo-link]]
|
||||||
|
|
||||||
[:div.footer-row
|
[:div.footer-row
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
(:require [reagent.core :as r]
|
(:require [reagent.core :as r]
|
||||||
[re-frame.core :as rf]
|
[re-frame.core :as rf]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[goog.date.relative]))
|
[goog.date.relative]
|
||||||
|
[goog.i18n.DateTimePatterns :as DateTimePatterns])
|
||||||
|
(:import (goog.i18n DateTimeFormat)))
|
||||||
|
|
||||||
(defn input [val-ratom props]
|
(defn input [val-ratom props]
|
||||||
(fn []
|
(fn []
|
||||||
|
@ -24,10 +26,20 @@
|
||||||
:disabled (= item title)}
|
:disabled (= item title)}
|
||||||
item])]))
|
item])]))
|
||||||
|
|
||||||
(defn relative-time [time]
|
(def ^:private long-ago-fmt
|
||||||
"converts time in milliseconds to a relative form of '1 hour ago'"
|
(DateTimeFormat. DateTimePatterns/MONTH_DAY_FULL))
|
||||||
(let [js-time (clj->js time)]
|
|
||||||
(goog.date.relative/format js-time)))
|
(defn human-time [date]
|
||||||
|
"Shows a given date in a human-friendly way. For dates less than
|
||||||
|
two weeks ago this means a relative '3 hours ago' kind of thing.
|
||||||
|
For dates longer ago we return 'January 01'."
|
||||||
|
(let [ms (.getTime date)
|
||||||
|
relative (goog.date.relative/format ms)]
|
||||||
|
;; Dates older than 2 weeks will not be shown as relative
|
||||||
|
;; https://github.com/google/closure-library/blob/99d7fa323f4c9e35ce7a97ea3cb08fc1d97d9e92/closure/goog/date/relative.js#L206
|
||||||
|
(if-not (empty? relative)
|
||||||
|
relative
|
||||||
|
(goog.date.relative/formatDay ms #(.format long-ago-fmt %)))))
|
||||||
|
|
||||||
(defn issue-url [owner repo number]
|
(defn issue-url [owner repo number]
|
||||||
(str "https://github.com/" owner "/" repo "/issues/" number))
|
(str "https://github.com/" owner "/" repo "/issues/" number))
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
(ns commiteth.manage-payouts
|
(ns commiteth.manage-payouts
|
||||||
(:require [re-frame.core :as rf]
|
(:require [re-frame.core :as rf]
|
||||||
[commiteth.common :refer [relative-time]]))
|
[commiteth.common :refer [human-time]]))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
[:div.description (if paid?
|
[:div.description (if paid?
|
||||||
(str "(paid to " winner-login ")")
|
(str "(paid to " winner-login ")")
|
||||||
(str "(" (if merged? "merged" "open") ")"))]
|
(str "(" (if merged? "merged" "open") ")"))]
|
||||||
[:div.time (relative-time updated)]
|
[:div.time (human-time updated)]
|
||||||
[:button.ui.button
|
[:button.ui.button
|
||||||
(merge (if (and merged? (not paid?))
|
(merge (if (and merged? (not paid?))
|
||||||
{}
|
{}
|
||||||
|
|
Loading…
Reference in New Issue