Files
immich-folio/lib/__tests__/journalDate.test.ts
Ralksta ad8b09700b release: v0.19.0
Release v0.19.0. See the `## [0.19.0] — 2026-09-29` section of
[CHANGELOG.md](https://github.com/ralksta/immich-folio/blob/dev/CHANGELOG.md)
for the full list.

Highlights: client proofing links (#683), custom content pages (#738),
asset picker search (#740), concurrent-edit detection (#742), env-locked
settings (#739), an accessibility baseline (#741), three security fixes
with advisories (#737, #755, #759), and a pre-release quality pass
(#780–#797).

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: ralksta <ralksta@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Ralf <rohlenbo79@gmail.com>
Co-authored-by: Paul Thies <110185070+ImScheinox@users.noreply.github.com>
Co-authored-by: lancetm714 <108419425+lancetm714@users.noreply.github.com>
Co-authored-by: Lance Martin <lancetaylor95@gmail.com>
2026-09-29 22:50:30 +02:00

52 lines
1.9 KiB
TypeScript

import { describe, it, expect, beforeAll, afterAll } from 'vitest';
import { formatJournalDate } from '../journalDate';
/**
* The /journal index formatted `new Date(frontmatter.date)` in the server's
* timezone: `2026-03-15` is UTC midnight, so every server west of Greenwich
* printed Mar 14. Hand-typed dates became "Invalid Date", and the entry page
* printed the raw string next to the index's localized one.
*
* Run under a negative UTC offset so a regression to local-time formatting
* shows up on any machine.
*/
let savedTz: string | undefined;
beforeAll(() => {
savedTz = process.env.TZ;
process.env.TZ = 'America/Los_Angeles';
});
afterAll(() => {
if (savedTz === undefined) delete process.env.TZ;
else process.env.TZ = savedTz;
});
describe('formatJournalDate', () => {
it('keeps the calendar day of a date-only value west of UTC', () => {
// Sanity check that the offset is in effect: this is the old code path.
expect(new Date('2026-03-15').getDate()).toBe(14);
expect(formatJournalDate('2026-03-15', 'en-US')).toBe('Mar 15, 2026');
expect(formatJournalDate('2026-01-01', 'de-DE')).toBe('1. Jan. 2026');
});
it('takes the written day of a value with a time', () => {
expect(formatJournalDate('2026-03-15T23:30:00+01:00', 'en-US')).toBe('Mar 15, 2026');
expect(formatJournalDate('2026-03-15 08:00', 'en-US')).toBe('Mar 15, 2026');
});
it('shows a year-month value without inventing a day', () => {
expect(formatJournalDate('2026-03', 'en-US')).toBe('March 2026');
});
it.each(['15.03.2026', 'March 2026', 'Spring 2026', '2026-02-30', '2026-13', '2026-03-150'])(
'shows %s as written instead of Invalid Date or a guessed day',
(raw) => {
expect(formatJournalDate(raw, 'en-US')).toBe(raw);
},
);
it('returns null for a missing or blank date', () => {
expect(formatJournalDate(undefined, 'en-US')).toBeNull();
expect(formatJournalDate(' ', 'en-US')).toBeNull();
});
});