mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 10:51:36 +01:00
Ability to bulk import or export articles as gzip, handle domain prefix logic in API and other smaller improvements
This commit is contained in:
@@ -1,16 +1,30 @@
|
||||
<script lang="ts">
|
||||
const { date }: { date: Date } = $props();
|
||||
const { date }: { date: string } = $props();
|
||||
|
||||
const options: Intl.DateTimeFormatOptions = {
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit"
|
||||
const dateObject = new Date(date);
|
||||
|
||||
const calcTimeAgo = (date: Date) => {
|
||||
const formatter = new Intl.RelativeTimeFormat("en");
|
||||
const ranges = [
|
||||
["years", 60 * 60 * 24 * 365],
|
||||
["months", 60 * 60 * 24 * 30],
|
||||
["weeks", 60 * 60 * 24 * 7],
|
||||
["days", 60 * 60 * 24],
|
||||
["hours", 60 * 60],
|
||||
["minutes", 60],
|
||||
["seconds", 1]
|
||||
] as const;
|
||||
const secondsElapsed = (date.getTime() - Date.now()) / 1000;
|
||||
|
||||
for (const [rangeType, rangeVal] of ranges) {
|
||||
if (rangeVal < Math.abs(secondsElapsed)) {
|
||||
const delta = secondsElapsed / rangeVal;
|
||||
return formatter.format(Math.round(delta), rangeType);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<time datetime={new Date(date).toLocaleString("sv").replace(" ", "T")}>
|
||||
{new Date(date).toLocaleString("en-us", { ...options })}
|
||||
<time datetime={dateObject.toLocaleString("sv").replace(" ", "T")}>
|
||||
{calcTimeAgo(dateObject)}
|
||||
</time>
|
||||
|
||||
Reference in New Issue
Block a user