adzap / timeliness

Fast date/time parsing for the control freak.
http://github.com/adzap/timeliness
MIT License
224 stars 28 forks source link

Add the option to add custom format tokens #31

Closed rs-cefigueiredo closed 4 years ago

rs-cefigueiredo commented 5 years ago

The intention is complement the possibility to add new formats that eventually is already in use on projects that integrate Timeliness. But on top of that, the option to use the tokens broadly used on existing projects in ruby, based on strptime tokens, like %Y-%m-%d.

The use would be

Timeliness.add_format_tokens({
  '%Y' => ['\d{4}', :year],
  '%m' => ['\d{2}', :month],
  '%d' => ['\d{2}', :day]
})
Timeliness.parse('2019-04-25', :date, format: '%Y-%m-%d')