Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unmask milliseconds #377

Merged
merged 2 commits into from
Aug 9, 2024
Merged
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/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ export function maskTime(time, timePadding) {
return baseHour + padding;
} else {
// If the padding is missing we use the current second to spread
// the result a little bit. We drop the current minute and the
// current milliseconds
// the result a little bit. We drop the current minute.
const numSeconds = Math.floor((time - baseHour) / 1000);
const numMillis = time - baseHour - (numSeconds * 1000);
const currentSecondAsMS = (numSeconds % 60) * 1000;

return baseHour + currentSecondAsMS;
return baseHour + currentSecondAsMS + numMillis;
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/utils.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ describe('Test Utils', () => {
it('Use current second if padding is missing', () => {
const sometime = new Date(2023, 8, 6, 15, 45, 27, 999);

const expectedTime = new Date(2023, 8, 6, 15, 0, 27).getTime();
const expectedTime = new Date(2023, 8, 6, 15, 0, 27, 999).getTime();
const masked = maskTime(sometime);
assert.equal(expectedTime, masked);
});

it('Use current second if padding is not a number', () => {
const sometime = new Date(2023, 8, 6, 15, 45, 27, 999);

const expectedTime = new Date(2023, 8, 6, 15, 0, 27).getTime();
const expectedTime = new Date(2023, 8, 6, 15, 0, 27, 999).getTime();
const masked = maskTime(sometime, 'hello');
assert.equal(expectedTime, masked);
});
Expand Down
Loading