Skip to content

Commit 2671f10

Browse files
🌐 - fix: use dutch translations in function
1 parent ad3af96 commit 2671f10

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

frontend/src/lib/string.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface TimeAgoOptions {
3232

3333
/**
3434
* Calculate how long ago a given date was and return a human-readable string.
35+
* TODO: Consider using a specialized library.
3536
*
3637
* @param dateInput - The date to calculate the time difference from. It can be a Date object or an ISO 8601 string.
3738
* @param options - Customization options for the output.
@@ -62,12 +63,12 @@ export function timeAgo(
6263

6364
// Define the intervals in seconds for various time units
6465
const intervals = [
65-
{ label: "year", seconds: 31536000 },
66-
{ label: "month", seconds: 2592000 },
67-
{ label: "week", seconds: 604800 },
68-
{ label: "day", seconds: 86400 },
69-
{ label: "hour", seconds: 3600 },
70-
{ label: "minute", seconds: 60 },
66+
{ label: "jaar", plural: "jaren", shortFormat: "j", seconds: 31536000 },
67+
{ label: "maand", plural: "maanden", shortFormat: "ma", seconds: 2592000 },
68+
{ label: "week", plural: "weken", shortFormat: "w", seconds: 604800 },
69+
{ label: "dag", plural: "dagen", shortFormat: "d", seconds: 86400 },
70+
{ label: "uur", plural: "uur", shortFormat: "u", seconds: 3600 },
71+
{ label: "minuut", plural: "minuten", shortFormat: "m", seconds: 60 },
7172
];
7273

7374
let result = "";
@@ -78,9 +79,12 @@ export function timeAgo(
7879
if (intervalCount >= 1) {
7980
// Format the label based on short or long format
8081
const label = shortFormat
81-
? interval.label.charAt(0) + (interval.label === "month" ? "o" : "")
82-
: interval.label + (intervalCount !== 1 ? "s" : "");
83-
result += `${intervalCount} ${label}${shortFormat ? "" : " ago"}`;
82+
? interval.shortFormat
83+
: intervalCount === 1
84+
? interval.label
85+
: interval.plural;
86+
87+
result += `${intervalCount} ${label}${shortFormat ? "" : " geleden"}`;
8488
// Update seconds to the remainder for the next interval
8589
seconds %= interval.seconds;
8690
// If in short format, add a space for the next unit

0 commit comments

Comments
 (0)