1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

First commit

Public timeline working, with refreshing and load more
This commit is contained in:
Zhiyuan Zheng
2020-10-22 00:47:02 +02:00
parent fb152fece9
commit 4af19d0588
10 changed files with 587 additions and 22 deletions

19
utils/relative-time.js Normal file
View File

@@ -0,0 +1,19 @@
export default function relative_time (date) {
var units = {
year: 24 * 60 * 60 * 1000 * 365,
month: (24 * 60 * 60 * 1000 * 365) / 12,
day: 24 * 60 * 60 * 1000,
hour: 60 * 60 * 1000,
minute: 60 * 1000,
second: 1000
}
var rtf = new Intl.RelativeTimeFormat('zh', { numeric: 'auto' })
var elapsed = new Date(date) - new Date()
// "Math.abs" accounts for both "past" & "future" scenarios
for (var u in units)
if (Math.abs(elapsed) > units[u] || u == 'second')
return rtf.format(Math.round(elapsed / units[u]), u)
}