Skip to content

Enumerate possible format results #81

@linkviii

Description

@linkviii

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions