[OCaml] Mobile-friendly clone of cgit.
Make relative time function idiomatic.
lib/views/repo.ml
@@ -90,23 +90,21 @@
90
90
91
91
let relative_time (date, _) =
92
92
let seconds = Unix.time () -. Int64.to_float date |> int_of_float in
93
Added:
let minutes = seconds / 60 in
94
Added:
let hours = minutes / 60 in
95
Added:
let days = hours / 24 in
96
Added:
let months = days / 30 in
97
Added:
let years = months / 12 in
93
98
let quantity value singular =
94
99
Printf.sprintf "%d %s%s ago" value singular (if value = 1 then "" else "s")
95
100
in
96
Removed:
if seconds < 60 then "just now"
97
Removed:
else
98
Removed:
let minutes = seconds / 60 in
99
Removed:
if minutes < 60 then quantity minutes "minute"
100
Removed:
else
101
Removed:
let hours = minutes / 60 in
102
Removed:
if hours < 24 then quantity hours "hour"
103
Removed:
else
104
Removed:
let days = hours / 24 in
105
Removed:
if days < 30 then quantity days "day"
106
Removed:
else
107
Removed:
let months = days / 30 in
108
Removed:
if months < 12 then quantity months "month"
109
Removed:
else quantity (months / 12) "year"
101
Added:
match seconds with
102
Added:
| s when s < 60 -> "just now"
103
Added:
| _ when minutes < 60 -> quantity minutes "minute"
104
Added:
| _ when hours < 24 -> quantity hours "hour"
105
Added:
| _ when days < 30 -> quantity days "day"
106
Added:
| _ when months < 12 -> quantity months "month"
107
Added:
| _ -> quantity years "year"
110
108
111
109
let li_of_commit ?(hide_pill = false) repo (commit : Resolvers.Commit.t) =
112
110
let message = parse_commit_message commit.message in