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

Feature Request: Macro Tokens for All Formats and Export expandMacroTokens function #1638

Open
hemanth307 opened this issue Jun 3, 2024 · 3 comments

Comments

@hemanth307
Copy link

I am currently using macro tokens for date formats, and I need to expand them for placeholders. However, I have encountered two issues:

(i) The expandMacroTokens functions are not exported, which makes it challenging to use them for custom formatting.

(ii) Not all Luxon formats have corresponding macro tokens (e.g., DATE_MED_WITH_WEEKDAY).

It would be extremely helpful if macro tokens could be added for every format, and if the expandMacroTokens functions could be exported for easier customization.

Thank you for considering this feature request.

@diesieben07
Copy link
Collaborator

You can use DateTime.parseFormatForOpts to convert any formatting options (like DATE_MED_WITH_WEEKDAY) into a format string:

console.log(DateTime.parseFormatForOpts(DateTime.DATE_MED_WITH_WEEKDAY)); // outputs: EEE, MMM d, yyyyy

expandMacroTokens is available via DateTime.expandFormat:

console.log(DateTime.expandFormat('DDD')); // outputs: MMMM d, yyyyy

Let me know if this solves your use cases.

@hemanth307
Copy link
Author

hemanth307 commented Jun 4, 2024

  1. Thank You That Helped, but i also have a locale which might be changing the format so can i pass the locale with the macrotoken format and get the particular format.

  2. Is there a way i can get the format if i pass the JavaScript Date Object and the locale. I need format not the formatted value.

  3. Can we get a macro option for DATE_MED_WITH_WEEKDAY which can change with the locale provided like for other tokens.

@diesieben07
Copy link
Collaborator

  1. Both parseFormatForOpts and expandFormat accept a 2nd parameter "localeOpts", which lets you configure the locale. Specifically this accepts an object with keys locale (like "en-US"), numberingSystem, outputCalendar and weekSettings.
  2. I'm not sure what you want to do here. How do you get a format from a Date object? A Date object is basically just a wrapper around a timestamp. What kind of format do you want to get?
  3. We can't add macro tokens for every conceivable format, at some point we'll run out of letters in the alphabet (many tokens already make no sense in terms of abbreviations). parseFormatForOpts should solve this for you by letting you expand DATE_MED_WITH_WEEKDAY manually.

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

No branches or pull requests

2 participants