Skip to content

Commit 11c4757

Browse files
committed
add relative time format back
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 6db4a76 commit 11c4757

File tree

6 files changed

+34
-8223
lines changed

6 files changed

+34
-8223
lines changed

css/logreader-main.css

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/logreader-main.mjs

Lines changed: 1 addition & 8218 deletions
Large diffs are not rendered by default.

js/logreader-main.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/vendor.LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ version: 9.0.0
197197
license: MIT
198198

199199
vite-plugin-node-polyfills
200-
version: 0.17.0
200+
version: 0.15.0
201201
license: MIT
202202

203203
vue

src/components/settings/SettingsDatetimeFormat.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
@update:checked="setDateTimeFormat">
2525
{{ t('logreader', 'UTC time') }}
2626
</NcCheckboxRadioSwitch>
27+
<NcCheckboxRadioSwitch :checked="dateTimeFormat"
28+
:disabled="isLocalLogfile"
29+
value="relative"
30+
name="timestamp_format"
31+
type="radio"
32+
@update:checked="setDateTimeFormat">
33+
{{ t('logreader', 'Relative') }}
34+
</NcCheckboxRadioSwitch>
2735
</fieldset>
2836
</template>
2937

src/utils/format.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import { getCanonicalLocale, translate as t } from '@nextcloud/l10n'
1010
import { LOGGING_LEVEL_NAMES } from '../constants'
1111
import { useSettingsStore } from '../store/settings'
1212

13+
// in miliseconds
14+
const units = {
15+
year : 24 * 60 * 60 * 1000 * 365,
16+
month : 24 * 60 * 60 * 1000 * 365/12,
17+
day : 24 * 60 * 60 * 1000,
18+
hour : 60 * 60 * 1000,
19+
minute: 60 * 1000,
20+
second: 1000
21+
}
22+
1323
export const useLogFormatting = (pinia?: Pinia) => {
1424
const settingsStore = useSettingsStore(pinia)
1525

@@ -25,6 +35,16 @@ export const useLogFormatting = (pinia?: Pinia) => {
2535
timeStyle: 'medium',
2636
})
2737
return dateFormat.format(new Date(time))
38+
} else if (settingsStore.dateTimeFormat === 'relative') {
39+
const dateFormat = new Intl.RelativeTimeFormat(getCanonicalLocale(), {
40+
style: 'short',
41+
})
42+
const elapsed = new Date(time) - (+new Date())
43+
for (let u in units) {
44+
if (Math.abs(elapsed) > units[u] || u == 'second') {
45+
return dateFormat.format(Math.round(elapsed / units[u]), u)
46+
}
47+
}
2848
} else if (settingsStore.dateTimeFormat === 'utc') {
2949
const dateFormat = Intl.DateTimeFormat(getCanonicalLocale(), {
3050
dateStyle: 'medium',

0 commit comments

Comments
 (0)