mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-24 06:28:42 +01:00
* WIP vue3 * WIP vue3 * WIP vue3 * Migrates to vitejs * Fixes js tests and removes not needed modules * Fixes unmount * Updates to use css instead for space * Fixes tests and rebases one more time * Uses orgua * Fixes migrations bugs with oruga and fixes scroll * Fixes v-deep * Fixes icons to prod * Fixes icons to prod * Adds favicon back * Transitions some to composition api * Updates another component to comp api * Cleans defineProps * Updates log messages * Moves more to compose api * Cleans up styles and rewrites event source * Tries to fix DOMPurify * Removes postcss * WIP typescript * Improves importing * Converts all to ts * Converts main to ts * Makes changes for tsconfig * Moves more to ts * Adds typing to store * More typing * Updates to ts * Updates the rest to ts * Fixes computes * Fixes unmount * Adds cypress with custom base fixed * Fixes jest tests * Fixes golang tests * Adds gitignore for cypress * Removes int in favor of e2e with cypress * Tries to fix int tests again * Adds title * Updates e2e tests * Uses vue for isMobile * Removes app spec * Cleans up docker * Adds drop down for settings * Fixes bug with restart * Fixes scroll up bug * Adds tests for light mode
50 lines
1.1 KiB
Vue
50 lines
1.1 KiB
Vue
<template>
|
|
<time :datetime="date.toISOString()">{{ relativeTime(date, locale) }}</time>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import { mapState } from "vuex";
|
|
import { formatRelative } from "date-fns";
|
|
import enGB from "date-fns/locale/en-GB";
|
|
import enUS from "date-fns/locale/en-US";
|
|
|
|
const use24Hr =
|
|
new Intl.DateTimeFormat(undefined, {
|
|
hour: "numeric",
|
|
})
|
|
.formatToParts(new Date(2020, 0, 1, 13))
|
|
.find((part) => part.type === "hour").value.length === 2;
|
|
|
|
const auto = use24Hr ? enGB : enUS;
|
|
const styles = { auto, 12: enUS, 24: enGB };
|
|
|
|
export default {
|
|
props: {
|
|
date: {
|
|
required: true,
|
|
type: Date,
|
|
},
|
|
},
|
|
name: "RelativeTime",
|
|
components: {},
|
|
computed: {
|
|
...mapState(["settings"]),
|
|
locale() {
|
|
const locale = styles[this.settings.hourStyle];
|
|
const oldFormatter = locale.formatRelative;
|
|
return {
|
|
...locale,
|
|
formatRelative(token) {
|
|
return oldFormatter(token) + "p";
|
|
},
|
|
};
|
|
},
|
|
},
|
|
methods: {
|
|
relativeTime(date, locale) {
|
|
return formatRelative(date, new Date(), { locale });
|
|
},
|
|
},
|
|
};
|
|
</script>
|