mojombo / chronic

Chronic is a pure Ruby natural language date parser.
http://injekt.github.com/chronic
MIT License
3.24k stars 461 forks source link

Parsing dates with years less than 1000 #291

Open kmccarp opened 9 years ago

kmccarp commented 9 years ago

Chronic.parse('1000-01-01') returns the correct date. => 1000-01-01 12:00:00 -0752

However,

Chronic.parse('0999-01-01') => nil and Chronic.parse('0000-01-01') => nil

both return nil.

Chronic.parse('999-01-01') => 0999-01-01 12:00:00 -0752 and Chronic.parse('100-01-01') => 0100-01-01 12:00:00 -0752

both work, though.

davispuh commented 9 years ago

these work on 0.10.2 and on master

Chronic.parse('1000-01-01')
=> 1000-01-01 12:00:00 +0200
Chronic.parse('0999-01-01')
=> 0999-01-01 12:00:00 +0200

Chronic.parse('0000-01-01') is expected to be nil, I don't think anyone would encounter such valid date.

Chronic.parse('999-01-01')
Chronic.parse('100-01-01')

these probably won't work in future versions unless there's a good reason to implement them, because typically year is always 4 digits and it doesn't really make sense with 3 digits and what about Chronic.parse('10-01-01')? that might be short year notation so it wouldn't be possible to specify 10year anyway.