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

Implement getDefaultOptions, setDefaultOptions #3069

Merged
merged 10 commits into from
Jun 23, 2022
Merged

Conversation

leshakoss
Copy link
Contributor

@leshakoss leshakoss commented May 31, 2022

No description provided.

@leshakoss leshakoss self-assigned this May 31, 2022
@leshakoss leshakoss mentioned this pull request Jun 1, 2022
26 tasks
@leshakoss leshakoss marked this pull request as ready for review June 1, 2022 18:25
@leshakoss leshakoss requested a review from kossnocorp June 1, 2022 18:25
@leshakoss leshakoss marked this pull request as draft June 2, 2022 17:48
@leshakoss leshakoss marked this pull request as ready for review June 10, 2022 15:05
@leshakoss leshakoss marked this pull request as draft June 10, 2022 16:52
Comment on lines 40 to 46
const weekStartsOn = toInteger(
options?.weekStartsOn ??
options?.locale?.options?.weekStartsOn ??
_defaultOptions.weekStartsOn ??
_defaultOptions.locale?.options?.weekStartsOn ??
0
)
Copy link
Member

Choose a reason for hiding this comment

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

I'm comparing this PR to #3087 and this one, with the wider scope, feels more future-prone.

If we decide to move locales to separate packages and make Intl the default approach, the change will still make sense. Furthermore, we might think of option autodetection and apply user-specific defaults for weekStartsOn, which would be impossible if we stick to locale-only.

It is indeed more code, but we can approach it slightly differently and reduce it to something like:

Suggested change
const weekStartsOn = toInteger(
options?.weekStartsOn ??
options?.locale?.options?.weekStartsOn ??
_defaultOptions.weekStartsOn ??
_defaultOptions.locale?.options?.weekStartsOn ??
0
)
const weekStartsOn = getOption(options, 'weekStartsOn')

That will also help to abstract the default behavior that we repeat from function to function.

src/_lib/defaultOptions/index.ts Outdated Show resolved Hide resolved
Comment on lines 19 to 33
export type AllOptions = LocaleOptions &
WeekStartOptions &
FirstWeekContainsDateOptions &
StepOptions &
RoundingOptions &
RepresentationOptions &
Omit<FormatDurationOptions, 'format'> & {
format?: FormatOptions['format'] | FormatDurationOptions['format']
} & FormatRFC3339Options &
AdditionalDigitsOptions &
AdditionalTokensOptions &
FormatDistanceOptions &
FormatDistanceStrictOptions &
RoundToNearestMinutesOptions &
AreIntervalsOverlappingOptions
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we don't need to make all options global, but locale, weekStartsOn, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reduced the scope to the big three: locale, weekStartsOn, firstWeekContainsDate

@leshakoss leshakoss marked this pull request as ready for review June 23, 2022 08:41
const locale = options?.locale ?? defaultOptions.locale ?? defaultLocale
const format = options?.format ?? defaultFormat
const zero = options?.zero ?? false
const delimiter = options?.delimiter ?? ' '
Copy link
Member

Choose a reason for hiding this comment

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

I'm afraid that this can be a breaking change, but I don't mind it haha

src/formatISO/test.ts Outdated Show resolved Hide resolved
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.

Look goods except for exsessive usage of ?? that might alter behavior. I don't mind shipping it as is because it's better for the future.

@leshakoss leshakoss merged commit 1e639f9 into master Jun 23, 2022
@leshakoss leshakoss deleted the v2-setDefaultOptions branch June 23, 2022 09:40
@olee
Copy link

olee commented Jul 9, 2022

When might we expect a new version to be published with those changes, if I dare to ask? :-)

@leshakoss
Copy link
Contributor Author

This closed #816

@leshakoss
Copy link
Contributor Author

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

Successfully merging this pull request may close these issues.

None yet

3 participants