adrienpoly / stimulus-flatpickr

A modest, yet powerful wrapper of Flatpickr 📆 for Stimulus
MIT License
415 stars 30 forks source link

Add mapping support for `%-l` strftime format #61

Closed aeturnumfluctus closed 4 years ago

aeturnumfluctus commented 4 years ago

This PR introduces a minor update to the strftime mapper which adds support for proper translation of the %-l (non-padded hour of day) strftime conversion specification.


Remedies the following issue:

Given the following I18n setup:

en:
  date: 
    formats:
       custom: "%A %m/%d/%y, %-l:%M"

and the following input field (abbreviated) setup:

<%= f.text_field :start_at,
      data: {
        controller: "flatpickr",
        flatpickr_alt_format: t("date.formats.custom"),
        ...
      } %>

Currently, when a date is selected, a the resulting datetime string is incorrectly formatted.

For example, selecting 2020.02.20 @ 2:20pm results in the following:

"Thursday 02/20/2020, %-Thursday:20"

This PR fixes this formatting issue, thus returning:

"Thursday 02/20/2020, 2:20"
adrienpoly commented 4 years ago

Excellent, thanks for this contribution

adrienpoly commented 4 years ago

I have released 1.3.3 with this fix

aeturnumfluctus commented 4 years ago

Glad to contribute! Thanks for the quick turn-around on this and for the effort you've put into building/maintaining this library! :beers: