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

Enumerate possible format results #81

Open
linkviii opened this issue Apr 25, 2021 · 0 comments
Open

Enumerate possible format results #81

linkviii opened this issue Apr 25, 2021 · 0 comments

Comments

@linkviii
Copy link

linkviii commented Apr 25, 2021

I'm laying out some text with multiple dates and a format argument. I would like to know the maximum size of a formatted date. Calculating the size of all my formatted dates takes too much time for me. (After implementing this I realized I didn't really need it, but since I already did it, here it is)

_locale being private/not exported prevents implementing enumeration without modifying the library.

I forked the library and provided an exported enumerate function that was implemented basically by a copy paste of _processFormat. https://github.com/Linkviii/strftime

Excerpts of my demo-enum.js:

Enumerate %c: (Tue 07 Jun 2011 06:51:45 PM GMT) →
[
  [
    'Sun', 'Mon',
    'Tue', 'Wed',
    'Thu', 'Fri',
    'Sat'
  ],
  [ ' ' ],
  [ '08', '88' ],
  [ ' ' ],
  [
    'Jan', 'Feb', 'Mar',
    'Apr', 'May', 'Jun',
    'Jul', 'Aug', 'Sep',
    'Oct', 'Nov', 'Dec'
  ],
  [ ' ' ],
  [ '8888' ],
  [ ' ' ],
  [ '08', '88' ],
  [ ':' ],
  [ '08', '88' ],
  [ ':' ],
  [ '08', '88' ],
  [ ' ' ],
  [ 'AM', 'PM' ],
  [ ' ' ],
  [ 'GMT' ]
]
Max string length of '%A %B' 
costs 19 → 'Wednesday September'

I'm not sure this is a feature this library would be interested in supporting, but I thought I'd leave this issue here in case anyone is interested.

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

1 participant