mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 08:21:39 -06:00
fix(metadata): preserve calendar dates across timezones
Keep month-name metadata dates stable in positive UTC offsets so local-to-UTC conversion cannot change the stored calendar day. Fixes #1194
This commit is contained in:
@@ -28,6 +28,7 @@ describe('published-date utils', () => {
|
|||||||
expect(parsePublishedDateKey('1965/8/1')).toBe('1965-08-01');
|
expect(parsePublishedDateKey('1965/8/1')).toBe('1965-08-01');
|
||||||
expect(parsePublishedDateKey('1965-08-01T12:30:00Z')).toBe('1965-08-01');
|
expect(parsePublishedDateKey('1965-08-01T12:30:00Z')).toBe('1965-08-01');
|
||||||
expect(parsePublishedDateKey('August 1, 1965')).toBe('1965-08-01');
|
expect(parsePublishedDateKey('August 1, 1965')).toBe('1965-08-01');
|
||||||
|
expect(parsePublishedDateKey('January 1, 2020')).toBe('2020-01-01');
|
||||||
expect(parsePublishedDateKey('1965')).toBeUndefined();
|
expect(parsePublishedDateKey('1965')).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ export function parsePublishedDateKey(value: unknown): string | undefined {
|
|||||||
|
|
||||||
if (MONTH_NAME_RE.test(trimmed) && /\b\d{1,2}\b/.test(trimmed) && /\b\d{4}\b/.test(trimmed)) {
|
if (MONTH_NAME_RE.test(trimmed) && /\b\d{1,2}\b/.test(trimmed) && /\b\d{4}\b/.test(trimmed)) {
|
||||||
const parsed = new Date(trimmed);
|
const parsed = new Date(trimmed);
|
||||||
return dateToPublishedDateKey(parsed);
|
if (Number.isNaN(parsed.getTime())) return undefined;
|
||||||
|
return buildDateKey(String(parsed.getFullYear()), String(parsed.getMonth() + 1), String(parsed.getDate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user