Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/runPart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 7 additions & 2 deletions test/numfmt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down