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

formatDuration: Include undefined values if formatting with zero option set to true #3703

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tommaso-sebastianelli
Copy link

@tommaso-sebastianelli tommaso-sebastianelli commented Feb 7, 2024

If I provide format values in FormatDurationOptions and set zero to true, I'm expecting also undefined Duration values to be considered in the output.

Example

Input

formatDuration(
  {
    seconds: 10,
  },
  {
    format: ["hours", "minutes", "seconds"],
    zero: true,
  }

Actual output:

10 seconds

Expected output:

Since I've explicitly set hours, minutes, and seconds I'm expecting to see them as 0 in the output.

0 hours 0 minutes 10 seconds

Note: It seems this was working like expected in 2.x but it is not working anymore in 3.x.
If this is the wanted behaviour instead, I suggest to update the relative doc in order to avoid misleading interpretations of zero param.

@tommaso-sebastianelli tommaso-sebastianelli changed the title Include undefined values if formatting with zero option set to true formatDuration > Include undefined values if formatting with zero option set to true Feb 7, 2024
@tommaso-sebastianelli tommaso-sebastianelli changed the title formatDuration > Include undefined values if formatting with zero option set to true formatDuration: Include undefined values if formatting with zero option set to true Feb 7, 2024
@tommaso-sebastianelli tommaso-sebastianelli force-pushed the fix/include-undefined-values-when-formatting branch from c99ad5e to f2b2950 Compare February 7, 2024 16:02
@kossnocorp
Copy link
Member

Hey! I hate to say it, but merging the PR will break the function for anyone using zero right now. Additionally, the Duration doesn't allow undefined to be set as property (I realize that not all use TypeScript and set exactOptionalPropertyTypes).

Said that, breaking the function behavior was not a good idea to begin with, but let's work with what we have.

Let's hide this behavior behind an option. I feel like strict sounds the best as what you expect is to formatDuration strictly follow the format and print all units.

The docs can also be more explicit; I would appreciate it if you could update them as well.

What do you think?

Copy link
Member

@kossnocorp kossnocorp left a comment

Choose a reason for hiding this comment

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

Let's hide it behind an option, see my comment: #3703 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: WIP
Development

Successfully merging this pull request may close these issues.

None yet

3 participants