mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-24 04:55:53 -07:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2163747170 | |||
| a7a4378a40 |
@@ -115,6 +115,7 @@ You can also find a list of all available service widgets in the sidebar navigat
|
||||
- [Prowlarr](prowlarr.md)
|
||||
- [Proxmox](proxmox.md)
|
||||
- [Proxmox Backup Server](proxmoxbackupserver.md)
|
||||
- [PrusaLink](prusalink.md)
|
||||
- [Pterodactyl](pterodactyl.md)
|
||||
- [PyLoad](pyload.md)
|
||||
- [qBittorrent](qbittorrent.md)
|
||||
|
||||
@@ -106,6 +106,12 @@ function relativeDate(date, formatter) {
|
||||
const unitIndex = cutoffs.findIndex((cutoff) => cutoff > Math.abs(delta));
|
||||
const divisor = unitIndex ? cutoffs[unitIndex - 1] : 1;
|
||||
|
||||
if (units[unitIndex] === "day") {
|
||||
// compare calendar days, not elapsed 24h blocks
|
||||
const startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
||||
return formatter.format(Math.round((startOfDay(date) - startOfDay(new Date())) / 86400000), "day");
|
||||
}
|
||||
|
||||
return formatter.format(Math.floor(delta / divisor), units[unitIndex]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { createRequire } from "node:module";
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const i18nextConfig = require("../../next-i18next.config.js");
|
||||
|
||||
function getRelativeDateFormatter() {
|
||||
let relativeDateFormatter;
|
||||
|
||||
i18nextConfig.use[0].init({
|
||||
services: {
|
||||
formatter: {
|
||||
add(name, formatter) {
|
||||
if (name === "relativeDate") relativeDateFormatter = formatter;
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return relativeDateFormatter;
|
||||
}
|
||||
|
||||
describe("relativeDate formatter", () => {
|
||||
const formatRelativeDate = getRelativeDateFormatter();
|
||||
const options = { numeric: "auto" };
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date(2026, 8, 23, 16, 0));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it.each([
|
||||
["hours away on the same day", new Date(2026, 8, 23, 20, 0), "in 4 hours"],
|
||||
["next calendar day", new Date(2026, 8, 24, 20, 0), "tomorrow"],
|
||||
["two calendar days away but under 48h", new Date(2026, 8, 25, 10, 40), "in 2 days"],
|
||||
["previous calendar day", new Date(2026, 8, 22, 10, 0), "yesterday"],
|
||||
["two calendar days ago but under 48h", new Date(2026, 8, 21, 20, 0), "2 days ago"],
|
||||
])("formats %s", (_description, value, expected) => {
|
||||
expect(formatRelativeDate(value.toISOString(), "en", options)).toBe(expected);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user