git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit e836f599f0095c03c6bb4b228c714e7130f797f6

Override lib.obs.timeAgo and add int method for time and dates.

Marcos Gutierrez committed on 9/29/2017, 3:30:49 PM
Parent: e5dd29c7a0d68080004e28769bbfed143db66881

Files changed

overrides/patchcore/lib/timeAgo.jsadded
plugs/intl/sync/i18n.jschanged
overrides/patchcore/lib/timeAgo.jsView
@@ -1,0 +1,42 @@
1+const Value = require('mutant/value')
2+const computed = require('mutant/computed')
3+const nest = require('depnest')
4+const human = require('human-time')
5+
6+exports.gives = nest('lib.obs.timeAgo')
7+
8+exports.needs = nest({
9+ 'intl.sync.time': 'first'
10+})
11+
12+exports.create = function (api) {
13+ return nest('lib.obs.timeAgo', timeAgo)
14+
15+ function timeAgo (timestamp) {
16+ var timer
17+ var value = Value(TimeIntl(timestamp))
18+ return computed([value], (a) => a, {
19+ onListen: () => {
20+ timer = setInterval(refresh, 30e3)
21+ refresh()
22+ },
23+ onUnlisten: () => {
24+ clearInterval(timer)
25+ }
26+ }, {
27+ idle: true
28+ })
29+
30+ function refresh () {
31+ value.set(TimeIntl(timestamp))
32+ }
33+
34+ function TimeIntl(timestamp) {
35+ return api.intl.sync.time(Time(timestamp))
36+ }
37+ }
38+}
39+
40+function Time (timestamp) {
41+ return human(new Date(timestamp))
42+}
plugs/intl/sync/i18n.jsView
@@ -6,8 +6,9 @@
66 exports.gives = nest('intl.sync', [
77 'locale',
88 'locales',
99 'i18n',
10+ 'time',
1011 ])
1112
1213 exports.needs = nest({
1314 'intl.sync.locale':'first',
@@ -27,9 +28,10 @@
2728
2829 return nest('intl.sync', {
2930 locale,
3031 locales,
31- i18n
32+ i18n,
33+ time
3234 })
3335
3436 //Get locale value in setting
3537 function locale () {
@@ -46,8 +48,28 @@
4648 _init()
4749 return i18nL.__(value)
4850 }
4951
52+ function time (date){
53+ return date
54+ .replace(/from now/, i18n('form now'))
55+ .replace(/ago/, i18n('ago'))
56+ .replace(/years/,i18n('years'))
57+ .replace(/months/,i18n('months'))
58+ .replace(/weeks/,i18n('weeks'))
59+ .replace(/days/,i18n('days'))
60+ .replace(/hours/,i18n('hours'))
61+ .replace(/minutes/,i18n('minutes'))
62+ .replace(/seconds/,i18n('seconds'))
63+ .replace(/year/,i18n('year'))
64+ .replace(/month/,i18n('month'))
65+ .replace(/week/,i18n('week'))
66+ .replace(/day/,i18n('day'))
67+ .replace(/hour/,i18n('hour'))
68+ .replace(/minute/,i18n('minute'))
69+ .replace(/second/,i18n('second'))
70+ }
71+
5072 //Init an subscribe to settings changes.
5173 function _init() {
5274 if (_locale) return
5375 //TODO: Depject this!

Built with git-ssb-web