Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 8d972d2

Browse files
author
Andy Jacobs
committed
intl(dates): use moment for timeAgo and timestamps
This removes the internal timeAgo and uses moment's localized fromNow. It also shows the tooltip timestamp localized as moment.format('LLLL zz') with the chosen language in the settings. This branches off @ahdinosaurs prior art in #1206 and implements it across the codebase. Also removes the human-time requirement.
1 parent a9247e8 commit 8d972d2

File tree

24 files changed

+10
-337
lines changed

24 files changed

+10
-337
lines changed

lib/depject/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ module.exports = {
9191
sheet: require('./invite/sheet.js')
9292
},
9393
keys: require('./keys.js'),
94-
lib: {
95-
timeAgo: require('./lib/timeAgo.js')
96-
},
9794
message: {
9895
async: {
9996
name: require('./message/async/name.js'),

lib/depject/intl/sync/i18n.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ exports.gives = nest('intl.sync', [
1010
'localeNames',
1111
'i18n',
1212
'i18n_n',
13-
'time',
1413
'startsWith'
1514
])
1615

@@ -33,8 +32,7 @@ exports.create = (api) => {
3332
startsWith,
3433
localeNames,
3534
i18n,
36-
i18n_n: i18nN,
37-
time
35+
i18n_n: i18nN
3836
})
3937

4038
function startsWith (text, startsWith) {
@@ -71,26 +69,6 @@ exports.create = (api) => {
7169
return i18nL.__n(value, ...opts)
7270
}
7371

74-
function time (date) {
75-
return date
76-
.replace(/from now/, i18n('from now'))
77-
.replace(/ago/, i18n('ago'))
78-
.replace(/years/, i18n('years'))
79-
.replace(/months/, i18n('months'))
80-
.replace(/weeks/, i18n('weeks'))
81-
.replace(/days/, i18n('days'))
82-
.replace(/hours/, i18n('hours'))
83-
.replace(/minutes/, i18n('minutes'))
84-
.replace(/seconds/, i18n('seconds'))
85-
.replace(/year/, i18n('year'))
86-
.replace(/month/, i18n('month'))
87-
.replace(/week/, i18n('week'))
88-
.replace(/day/, i18n('day'))
89-
.replace(/hour/, i18n('hour'))
90-
.replace(/minute/, i18n('minute'))
91-
.replace(/second/, i18n('second'))
92-
}
93-
9472
// Init an subscribe to settings changes.
9573
function _init () {
9674
if (_locale) return

lib/depject/lib/timeAgo.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

lib/depject/message/html/render/gathering.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ const nest = require('depnest')
33
const extend = require('xtend')
44
const moment = require('moment-timezone')
55

6-
const localTimezone = moment.tz.guess()
7-
moment.locale(navigator.languages)
8-
96
exports.needs = nest({
107
'message.html.markdown': 'first',
118
'message.html.layout': 'first',
@@ -179,7 +176,7 @@ exports.create = function (api) {
179176

180177
function formatTime (time) {
181178
if (time && time.epoch) {
182-
return moment(time.epoch).tz(localTimezone).format('LLLL zz')
179+
return moment(time.epoch).format('LLLL zz')
183180
}
184181
}
185182

lib/depject/message/html/timestamp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const h = require('mutant/h')
22
const nest = require('depnest')
3+
const moment = require('moment-timezone')
34

45
exports.gives = nest('message.html.timestamp')
56
exports.needs = nest({
6-
'lib.obs.timeAgo': 'first',
77
'message.sync.timestamp': 'first',
88
'message.sync.root': 'first'
99
})
@@ -15,7 +15,7 @@ exports.create = function (api) {
1515
return h('a.Timestamp', {
1616
href: api.message.sync.root(msg) || msg.key,
1717
anchor: msg.key,
18-
title: new Date(api.message.sync.timestamp(msg))
19-
}, api.lib.obs.timeAgo(api.message.sync.timestamp(msg)))
18+
title: moment(api.message.sync.timestamp(msg)).format('LLLL zz')
19+
}, moment(api.message.sync.timestamp(msg)).fromNow())
2020
}
2121
}

lib/main-window.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const watch = require('mutant/watch')
1515
const requireStyle = require('require-style')
1616
const ssbUri = require('ssb-uri')
1717
const pull = require('pull-stream')
18+
const moment = require('moment-timezone')
19+
20+
const localTimezone = moment.tz.guess()
21+
moment.tz.setDefault(localTimezone)
1822

1923
module.exports = function (config) {
2024
const sockets = combine(
@@ -50,6 +54,7 @@ module.exports = function (config) {
5054

5155
const i18n = api.intl.sync.i18n
5256
const language = api.settings.obs.get('patchwork.lang', '')()
57+
moment.locale(language)
5358
setupContextMenuAndSpellCheck(api.config.sync.load(), { navigate, getMessageText, language })
5459

5560
const id = api.keys.sync.id()

locales/de.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,6 @@
9292
"Edit": "Bearbeiten",
9393
"identified ": "bezeichnet ",
9494
"self identifies as ": "bezeichnet sich selbst als ",
95-
"from now": "von jetzt",
96-
"ago": "her",
97-
"years": "Jahre",
98-
"months": "Monate",
99-
"weeks": "Wochen",
100-
"days": "Tage",
101-
"hours": "Stunden",
102-
"minutes": "Minuten",
103-
"seconds": "Sekunden",
104-
"year": "Jahr",
105-
"month": "Monat",
106-
"week": "Woche",
107-
"day": "Tag",
108-
"hour": "Stunde",
109-
"minute": "Minute",
110-
"second": "Sekunde",
11195
"assigned a display image to ": "hat ein Bild zugewiesen ",
11296
"Theme": "Theme",
11397
"Language": "Sprache",

locales/el.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,6 @@
6666
"Self Assigned": "Self Assigned",
6767
"Assigned By": "Εκχωρήθηκε από",
6868
"followed ": "ακολουθείται από ",
69-
"from now": "από τώρα",
70-
"ago": "πριν",
71-
"years": "χρόνια",
72-
"months": "μήνες",
73-
"weeks": "εβδομάδες",
74-
"days": "ημέρες",
75-
"hours": "ώρες",
76-
"minutes": "λεπτά",
77-
"seconds": "δευτερόλεπτα",
78-
"year": "έτος",
79-
"month": "μήνας",
80-
"week": "εβδομάδα",
81-
"day": "ημέρα",
82-
"hour": "ώρα",
83-
"minute": "λεπτό",
84-
"second": "δευτερόλεπτο",
8569
"Reply": "Απάντηση",
8670
"View full thread": "Δείτε την πλήρη ανάρτηση",
8771
"Unsubscribe": "Απεγγραφή",

locales/en.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,6 @@
6666
"Self Assigned": "Self Assigned",
6767
"Assigned By": "Assigned By",
6868
"followed ": "followed ",
69-
"from now": "from now",
70-
"ago": "ago",
71-
"years": "years",
72-
"months": "months",
73-
"weeks": "weeks",
74-
"days": "days",
75-
"hours": "hours",
76-
"minutes": "mins",
77-
"seconds": "secs",
78-
"year": "year",
79-
"month": "month",
80-
"week": "week",
81-
"day": "day",
82-
"hour": "hour",
83-
"minute": "min",
84-
"second": "sec",
8569
"Reply": "Reply",
8670
"View full thread": "View full thread",
8771
"Unsubscribe": "Unsubscribe",

locales/eo.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,6 @@
118118
"Close": "Fermi",
119119
"New Message": "Nova mesaĝo",
120120
"Language": "Lingvo",
121-
"from now": "de nun",
122-
"ago": "antaŭ",
123-
"years": "jaroj",
124-
"months": "monatoj",
125-
"weeks": "semajnoj",
126-
"days": "tagoj",
127-
"hours": "horoj",
128-
"minutes": "minutoj",
129-
"seconds": "sekundoj",
130-
"year": "jaro",
131-
"month": "monato",
132-
"week": "semajno",
133-
"day": "tago",
134-
"hour": "horo",
135-
"minute": "minuto",
136-
"second": "sekundo",
137121
"unsubscribed from ": "malabonis de ",
138122
"en": "en",
139123
"es": "es",

0 commit comments

Comments
 (0)