[OCaml] Mobile-friendly clone of cgit.
refactor spell out Time_fmt as Time_format
Every other module in the repo spells its words out — static_handler, components, resolvers, line_diff — leaving Time_fmt as the sole abbreviation and the sole name a reader has to expand.
Changed files
doc/index.mld
@@ -36,7 +36,7 @@
36
36
{2 Supporting modules}
37
37
38
38
- {!module-Ogit.Syntax} — guesses a blob's language for highlighting.
39
Removed:
- {!module-Ogit.Time_fmt} — formats Git dates for display.
39
Added:
- {!module-Ogit.Time_format} — formats Git dates for display.
40
40
- {!module-Ogit.Diff} — computes line diffs between blobs.
41
41
- {!module-Ogit.Charts} — generates standalone SVG charts.
42
42
- {!module-Ogit.Config} — reads and validates the TOML configuration.
lib/views/repo.ml
@@ -5,7 +5,7 @@
5
5
6
6
Each page is a description: it names the parts it is made of and hands them
7
7
to {!Layout}. Markup lives in {!Ui}, ogit's page parts in {!Components},
8
Removed:
language guessing in {!Syntax}, and date formatting in {!Time_fmt}. *)
8
Added:
language guessing in {!Syntax}, and date formatting in {!Time_format}. *)
9
9
10
10
type context = { repo : string; description : string; site : Layout.site }
11
11
(** What every repository page needs to know about its subject. *)
@@ -133,11 +133,11 @@
133
133
Ui.item
134
134
[
135
135
Ui.inline_text ~class_:"timestamp"
136
Removed:
(Time_fmt.short_time commit.author.date);
136
Added:
(Time_format.short_time commit.author.date);
137
137
Ui.inline ~class_:"commit-title"
138
138
[ badge; Components.route_link (Commit (repo, commit.hash)) title ];
139
139
Ui.inline_text ~class_:"commit-ago"
140
Removed:
(Time_fmt.relative_time commit.author.date);
140
Added:
(Time_format.relative_time commit.author.date);
141
141
(match author with
142
142
| Some _ -> Ui.nothing
143
143
| None ->
@@ -393,7 +393,7 @@
393
393
else [ Ui.paragraph_text ~class_:"commit-body" message.body ]
394
394
in
395
395
let timestamp date =
396
Removed:
let machine, display = Time_fmt.exact_time date in
396
Added:
let machine, display = Time_format.exact_time date in
397
397
Ui.timestamp ~machine display
398
398
in
399
399
let metadata =
lib/views/root.ml
@@ -19,7 +19,7 @@
19
19
match List.assoc_opt path dates with
20
20
| None | Some None -> Ui.nothing
21
21
| Some (Some date) ->
22
Removed:
Ui.inline_text ~class_:"commit-ago" (Time_fmt.relative_time date)
22
Added:
Ui.inline_text ~class_:"commit-ago" (Time_format.relative_time date)
23
23
in
24
24
Ui.item
25
25
[
lib/views/time_fmt.ml
@@ -1,55 +0,0 @@
1
Removed:
(* -*- mode: tuareg; -*- *)
2
Removed:
3
Removed:
(** Formatting Git dates for display.
4
Removed:
5
Removed:
Git records a commit date as a Unix timestamp plus the offset of the zone
6
Removed:
the author was in. Relative and short forms drop that offset and use the
7
Removed:
server's local zone, which is what a reader scanning a list wants; the
8
Removed:
detailed form preserves it, because on a single commit the author's own
9
Removed:
wall-clock time is the meaningful one. *)
10
Removed:
11
Removed:
let relative_time (date, _) =
12
Removed:
let seconds = Unix.time () -. Int64.to_float date |> int_of_float in
13
Removed:
let minutes = seconds / 60 in
14
Removed:
let hours = minutes / 60 in
15
Removed:
let days = hours / 24 in
16
Removed:
let months = days / 30 in
17
Removed:
let years = months / 12 in
18
Removed:
let quantity value singular =
19
Removed:
Printf.sprintf "%d %s%s ago" value singular (if value = 1 then "" else "s")
20
Removed:
in
21
Removed:
match seconds with
22
Removed:
| s when s < 60 -> "just now"
23
Removed:
| _ when minutes < 60 -> quantity minutes "minute"
24
Removed:
| _ when hours < 24 -> quantity hours "hour"
25
Removed:
| _ when days < 30 -> quantity days "day"
26
Removed:
| _ when months < 12 -> quantity months "month"
27
Removed:
| _ -> quantity years "year"
28
Removed:
29
Removed:
(** Minute precision, server-local, for dense listings. *)
30
Removed:
let short_time (date, _) =
31
Removed:
let tm = date |> Int64.to_float |> Unix.localtime in
32
Removed:
Printf.sprintf "%04d-%02d-%02d %02d:%02d" (tm.tm_year + 1900) (tm.tm_mon + 1)
33
Removed:
tm.tm_mday tm.tm_hour tm.tm_min
34
Removed:
35
Removed:
(** Second precision in the recorded zone. Returns the machine-readable form for
36
Removed:
a [datetime] attribute alongside the human-readable form. *)
37
Removed:
let exact_time (date, timezone) =
38
Removed:
let offset_seconds, suffix =
39
Removed:
match timezone with
40
Removed:
| None -> (0, "Z")
41
Removed:
| Some (offset : Git.User.tz_offset) ->
42
Removed:
let direction = match offset.sign with `Plus -> 1 | `Minus -> -1 in
43
Removed:
let seconds = direction * ((offset.hours * 60) + offset.minutes) * 60 in
44
Removed:
let sign = match offset.sign with `Plus -> "+" | `Minus -> "-" in
45
Removed:
(seconds, Printf.sprintf "%s%02d:%02d" sign offset.hours offset.minutes)
46
Removed:
in
47
Removed:
let adjusted = Int64.add date (Int64.of_int offset_seconds) in
48
Removed:
let tm = adjusted |> Int64.to_float |> Unix.gmtime in
49
Removed:
let day =
50
Removed:
Printf.sprintf "%04d-%02d-%02d" (tm.tm_year + 1900) (tm.tm_mon + 1)
51
Removed:
tm.tm_mday
52
Removed:
in
53
Removed:
let clock = Printf.sprintf "%02d:%02d:%02d" tm.tm_hour tm.tm_min tm.tm_sec in
54
Removed:
( Printf.sprintf "%sT%s%s" day clock suffix,
55
Removed:
Printf.sprintf "%s %s %s" day clock suffix )
lib/views/time_format.ml
@@ -0,0 +1,55 @@
1
Added:
(* -*- mode: tuareg; -*- *)
2
Added:
3
Added:
(** Formatting Git dates for display.
4
Added:
5
Added:
Git records a commit date as a Unix timestamp plus the offset of the zone
6
Added:
the author was in. Relative and short forms drop that offset and use the
7
Added:
server's local zone, which is what a reader scanning a list wants; the
8
Added:
detailed form preserves it, because on a single commit the author's own
9
Added:
wall-clock time is the meaningful one. *)
10
Added:
11
Added:
let relative_time (date, _) =
12
Added:
let seconds = Unix.time () -. Int64.to_float date |> int_of_float in
13
Added:
let minutes = seconds / 60 in
14
Added:
let hours = minutes / 60 in
15
Added:
let days = hours / 24 in
16
Added:
let months = days / 30 in
17
Added:
let years = months / 12 in
18
Added:
let quantity value singular =
19
Added:
Printf.sprintf "%d %s%s ago" value singular (if value = 1 then "" else "s")
20
Added:
in
21
Added:
match seconds with
22
Added:
| s when s < 60 -> "just now"
23
Added:
| _ when minutes < 60 -> quantity minutes "minute"
24
Added:
| _ when hours < 24 -> quantity hours "hour"
25
Added:
| _ when days < 30 -> quantity days "day"
26
Added:
| _ when months < 12 -> quantity months "month"
27
Added:
| _ -> quantity years "year"
28
Added:
29
Added:
(** Minute precision, server-local, for dense listings. *)
30
Added:
let short_time (date, _) =
31
Added:
let tm = date |> Int64.to_float |> Unix.localtime in
32
Added:
Printf.sprintf "%04d-%02d-%02d %02d:%02d" (tm.tm_year + 1900) (tm.tm_mon + 1)
33
Added:
tm.tm_mday tm.tm_hour tm.tm_min
34
Added:
35
Added:
(** Second precision in the recorded zone. Returns the machine-readable form for
36
Added:
a [datetime] attribute alongside the human-readable form. *)
37
Added:
let exact_time (date, timezone) =
38
Added:
let offset_seconds, suffix =
39
Added:
match timezone with
40
Added:
| None -> (0, "Z")
41
Added:
| Some (offset : Git.User.tz_offset) ->
42
Added:
let direction = match offset.sign with `Plus -> 1 | `Minus -> -1 in
43
Added:
let seconds = direction * ((offset.hours * 60) + offset.minutes) * 60 in
44
Added:
let sign = match offset.sign with `Plus -> "+" | `Minus -> "-" in
45
Added:
(seconds, Printf.sprintf "%s%02d:%02d" sign offset.hours offset.minutes)
46
Added:
in
47
Added:
let adjusted = Int64.add date (Int64.of_int offset_seconds) in
48
Added:
let tm = adjusted |> Int64.to_float |> Unix.gmtime in
49
Added:
let day =
50
Added:
Printf.sprintf "%04d-%02d-%02d" (tm.tm_year + 1900) (tm.tm_mon + 1)
51
Added:
tm.tm_mday
52
Added:
in
53
Added:
let clock = Printf.sprintf "%02d:%02d:%02d" tm.tm_hour tm.tm_min tm.tm_sec in
54
Added:
( Printf.sprintf "%sT%s%s" day clock suffix,
55
Added:
Printf.sprintf "%s %s %s" day clock suffix )