samsonjs / strftime

strftime for JavaScript

Home Page:http://samhuri.net/projects/strftime

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add option (%-) to not pad days and hours

TylerRick opened this issue · comments

In Ruby, I like to use this format:

Time::DATE_FORMATS[:day_name_long_at_time] = "%A, %B %-d, %Y, at %-I:%M %P"

Which gives me nice human-readable times like this:

'Thursday, October 4, 2012, at 5:00 pm'

I don't know if you're aiming for full feature parity with Ruby's strftime (probably not), but I noticed you had added some other nice Ruby extensions so I'm hoping you'll add this one.... because really, who wants to have their dates formatted as October 04 instead of October 4? :)

Here's the relevant section of ri strftime:

  The directive consists of a percent (%) character,
  zero or more flags, optional minimum field width,
  optional modifier and a conversion specifier
  as follows.

    %<flags><width><modifier><conversion>

  Flags:
    -  don't pad a numerical output.
    _  use spaces for padding.
    0  use zeros for padding.
    ^  upcase the result string.
    #  change case.
    :  use colons for %z.

Good suggestion. I will add a couple of these, %- and %_ for sure, probably %0 and %^ as well.

Just a note that %e is equivalent to %-d and %l (lowercase L) is like %-I except it includes the space. Might be a useful workaround.

I am going to try and implement this tonight though, so you may not have to use them.

sweet, thanks!