TimeSpanParser icon indicating copy to clipboard operation
TimeSpanParser copied to clipboard

Issue with years parsing

Open lawrence-laz opened this issue 2 years ago • 2 comments

Years parsing seems a bit weird: while this works TimeSpanParser.Parse("0 years"), neither TimeSpanParser.Parse("1 years") nor TimeSpanParser.Parse("1 year") work. Any ideas why this happens?

EDIT: Just noticed this in the readme: ". . . Other values for years/months are not currently accepted". Would be nice to have 1 year just equal 365 days or something in scenarios where leap year is not that important.

lawrence-laz avatar Nov 06 '23 19:11 lawrence-laz

Hi, yes I left it out deliberately because of the ambiguity, implication of relative timespans, and added work to support all possible "correct" values of "1 year" or "1 month". I also didn't have a use case. Can you tell me about yours?

pengowray avatar Nov 07 '23 10:11 pengowray

I was building an internal command line tool for generating licenses. The expiration parameter is parsed using this library. Licenses usually last for years, but when I entered "1 year" it failed to parse, which was unexpected initially. Setting 365 days is a good enough workaround for now though.

lawrence-laz avatar Nov 09 '23 17:11 lawrence-laz