Skip to content

Conversation

@y-exp
Copy link
Contributor

@y-exp y-exp commented Mar 16, 2025

With the 4.0.0 release of enhanced-ms, passing includeMs: true to the format method causes subsequent calls to always include milliseconds in the resulting string, even when includeMs: false is specified:

import { ms } from 'enhanced-ms';

console.log(ms(1001, { includeMs: false }));
// -> 1 second ✅
console.log(ms(1001, { includeMs: true }));
// -> 1 second 1 millisecond ✅
console.log(ms(1001, { includeMs: false }));
// -> 1 second 1 millisecond ❌

The same issue occurs with includeSubMs: true for microseconds and nanoseconds.

The bug stems from the resolveFormatOptions method, which modifies the original defaultFormatOptions.includedUnits array here:

https://github.com/apteryxxyz/enhanced-ms/blob/f119aff3969e72524a74139c3efca7081ab91597/src/format/helpers/resolve-options.ts#L133-L134

This PR fixes it by simply creating a copy of said array.

@y-exp y-exp requested a review from k0d13 as a code owner March 16, 2025 11:48
@changeset-bot
Copy link

changeset-bot bot commented Mar 16, 2025

⚠️ No Changeset found

Latest commit: 89a7bd1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@k0d13 k0d13 self-requested a review March 16, 2025 16:14
Copy link
Owner

@k0d13 k0d13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a changeset

@k0d13 k0d13 merged commit c452fb3 into k0d13:main Mar 16, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants