timeliness icon indicating copy to clipboard operation
timeliness copied to clipboard

parse with format mmm yyyy fails

Open Rauskii opened this issue 4 years ago • 1 comments

When trying to parse a string 'Feb 2019', using Timeliness.parse('Feb 2019', format: 'mmm yyyy') it returns nil, if the current date is something that does not exist. For example I was trying to parse above Feb 2019 string on 29th day of July, and parsing it apparently fails as there is no 29th day in february 2019. Same issue might happen when trying to parse lets say 'April yyyy' during 31st day of some month. Could the 'mmm yyyy' format parsing default to first day of the month instead of returning nil on these rare cases?

Rauskii avatar Jul 29 '19 10:07 Rauskii

One of the goals of this gem is be more strict or 'correct' than the native Ruby Time behaviour. I would not consider your suggestion to be necessarily correct. The expected behaviour of this format is ambiguous and I don't think I want to change the current behaviour as it is consistent.

What I think is the best way forward is to improve the default date parts handling. At the moment the date parts can be configured for when a time type value (time only string) is being parsed so that a Time object can be returned. I think expanding this behaviour to allow you specify default date part values when they are not specified in a format for date, time, or datetime types.

I have no timeline for this at present.

adzap avatar Jul 30 '19 01:07 adzap