diff --git a/src/runPart.ts b/src/runPart.ts index 4acb9fd..29e95ef 100644 --- a/src/runPart.ts +++ b/src/runPart.ts @@ -5,7 +5,7 @@ import { general } from './general.ts'; import { toYMD } from './toYMD.ts'; import { defaultLocale, type LocaleData } from './locale.ts'; import { - u_HOUR, u_MIN, u_SEC, u_DSEC, u_CSEC, u_MSEC, + u_DSEC, u_CSEC, u_MSEC, EPOCH_1317, MIN_S_DATE, MAX_S_DATE, MIN_L_DATE, MAX_L_DATE, @@ -226,8 +226,8 @@ export function runPart (value: number | string | bigint, part: Partition, opts: subsec = 0; } } - // a time shown as midnight belongs to the next day; a date alone ignores the time - if (time === DAYSIZE && part.date & (u_HOUR | u_MIN | u_SEC | u_DSEC | u_CSEC | u_MSEC)) { + // a time that rounds to midnight belongs to the next day + if (time === DAYSIZE) { time = 0; date += 1; } diff --git a/test/numfmt.spec.ts b/test/numfmt.spec.ts index 70f5f79..6814704 100644 --- a/test/numfmt.spec.ts +++ b/test/numfmt.spec.ts @@ -319,8 +319,13 @@ test('A time that rounds up to midnight shows the next day', () => { expect(numfmt('m/d/yy h:mm', 45292.9999999)).toBe('1/2/24 0:00'); expect(numfmt('yyyy-mm-dd hh:mm:ss', 45292.999995)).toBe('2024-01-02 00:00:00'); expect(numfmt('dddd h:mm', 45292.9999999)).toBe('Tuesday 0:00'); - expect(numfmt('m/d/yy', 45292.9999999)).toBe('1/1/24'); - expect(numfmt('m/d/yy', 45292.99999999)).toBe('1/1/24'); + expect(numfmt('m/d/yy', 45292.9999999)).toBe('1/2/24'); + expect(numfmt('m/d/yy', 45292.99999999)).toBe('1/2/24'); +}); + +test('A date-only format shows the next day when the time rounds up to midnight', () => { + expect(numfmt('yyyy-mm-dd', 45000.9999942130)).toBe('2023-03-16'); + expect(numfmt('yyyy-mm-dd', 45000.9999942129)).toBe('2023-03-15'); }); test('General rounds 10 and 11 digit numbers with a fraction', () => {