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

feat: passing locale format date-fns #7

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

Conversation

fxamauri
Copy link

Hello guys, I made the changes to allow passing the locale in the format calls, and I think this might resolve #6 .

I hope this helps! I'm available for any further adjustments if needed.

@fxamauri fxamauri marked this pull request as ready for review August 23, 2024 02:15
@fxamauri fxamauri force-pushed the feat/passing-locale-format-date-fns branch from 6af8b45 to db62dbc Compare August 23, 2024 02:25
} from "date-fns";
import * as Locales from 'date-fns/locale';

Choose a reason for hiding this comment

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

I came up with the same solution first but then I wondered if this will affect the bundle size.

If the date-fns library would be a peer dependency #5 (comment): What about accepting the locale object as an optional parameter instead of a locale string? Then it will be up to the developer how the locale will be loaded (using a fixed set of locales or loaded dynamically).

I guess this would be a breaking change.

Copy link
Author

Choose a reason for hiding this comment

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

You're right, I initially considered accepting the locale as an object, but since we already have the option to pass the locale as a string, I wasn't sure how to approach this. Do you think it would be beneficial to accept the locale object in the options instead? However, this would mean exposing an internal dependency, the date-fns locales.

@dnsdrs
Copy link

dnsdrs commented Jan 14, 2025

Hi all!

I understand there is an unresolved discussion about whether little-date should continue using strings to define the locale format ({ locale: "fr-FR"}) or switch to a date-fns locale object. The latter option would introduce a peer dependency, which could be seen as unnecessary depending on individual opinions.

In any case, while this debate remains unresolved, the string option currently works only for time format and not for date format, correct?

Do you plan to decide how to address this issue soon? I would love to change the date format to match my locale.

@simonljus
Copy link

This PR made me try to create a similar date formatting library by using available Web APIs like Intl DateTimeFormat formatRange instead of date-fns. The only dependency is Tempo by FormKit (which has no dependencies) that provides some utility functions for date comparison and timezone calculations.

I have not been working on it since I made a first release a few months ago, but I hope it could work as an alternative to this library.

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.

All calls to date-fns format method miss locale
3 participants