henrypoydar / chronic_duration

A simple Ruby natural language parser for elapsed time
MIT License
351 stars 68 forks source link

output and parse are not equivalent for years: #16

Closed errm closed 12 years ago

errm commented 12 years ago

ChronicDuration.output(ChronicDuration.parse("2 year")) => "2 yrs 10 days"

Output is off by 5 days per year as 12 * 30 != 365

flynfish commented 12 years ago

Is this a similar output error?

ChronicDuration.output(ChronicDuration.parse("18 months")) => "1 yr 6 mos -5 days"

I assume this is a bug, but I am not really familiar with all the time issues:

ChronicDuration.parse("18 months")           => 46656000 
ChronicDuration.parse("1 year 6 months") => 47088000
errm commented 12 years ago

yes it seems my changes introduced that . . .

errm commented 12 years ago

So it seems correct in a way.

what exactly is 18 months 18 * 30 * 24 * 3600, but 1 year 6 months should be (6 30 + 365) * 24 \ 3600

so I think we should preserve those differences when we parse. But output needs to be something more like 1 year 5 months 25 days or 18 months.....