blob: 5f62385a97822b1909c169cb421f89fdb3195cce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/**
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { translate as t } from '@nextcloud/l10n'
import moment from '@nextcloud/moment'
import { dateFactory } from '../services/dateService.js'
/**
* Formats a clearAt object to be human readable
*
* @param {object} clearAt The clearAt object
* @return {string|null}
*/
const clearAtFilter = (clearAt) => {
if (clearAt === null) {
return t('user_status', 'Don\'t clear')
}
if (clearAt.type === 'end-of') {
switch (clearAt.time) {
case 'day':
return t('user_status', 'Today')
case 'week':
return t('user_status', 'This week')
default:
return null
}
}
if (clearAt.type === 'period') {
return moment.duration(clearAt.time * 1000).humanize()
}
// This is not an officially supported type
// but only used internally to show the remaining time
// in the Set Status Modal
if (clearAt.type === '_time') {
const momentNow = moment(dateFactory())
const momentClearAt = moment(clearAt.time, 'X')
return moment.duration(momentNow.diff(momentClearAt)).humanize()
}
return null
}
export {
clearAtFilter,
}
|