chronic icon indicating copy to clipboard operation
chronic copied to clipboard

Different parsing result for same time without date/with date/without date

Open lemboy opened this issue 10 years ago • 4 comments
trafficstars

It is bug or feature?

[5] pry(main)> Chronic.parse("5:30", endian_precedence: :little)
=> 2015-05-29 17:30:00 +0300
[6] pry(main)> Chronic.parse("29/05/2015 05:30", endian_precedence: :little)
=> 2015-05-29 05:30:00 +0300
[7] pry(main)> Chronic.parse("05:30", endian_precedence: :little)
=> 2015-05-30 05:30:00 +0300

ruby '2.2.1' gem 'rails', '4.2.0' gem 'chronic', '~> 0.10.2'

lemboy avatar May 29 '15 19:05 lemboy

I'm not sure what you mean? It looks correct to me.

# by default, :context => :future and :hours24 => nil
# which means it will take best guess
# you ran it before 17:30 so closest time to 5:30 is 17:30
Chronic.parse("5:30", endian_precedence: :little)
=> 2015-05-29 17:30:00 +0300

# 05:30 forces :hours24 => true so it will definitely be 05:30
Chronic.parse("29/05/2015 05:30", endian_precedence: :little)
=> 2015-05-29 05:30:00 +0300

# no date specified and closest 05:30 is only tomorrow so
Chronic.parse("05:30", endian_precedence: :little)
=> 2015-05-30 05:30:00 +0300

davispuh avatar May 29 '15 20:05 davispuh

Oh, sorry, I see - 5 and 05.

But what can I do for unambiguous result: 5:20 parse to 05:20 05:20 parse to 05:20 17:20 parse to 17:20 and so on with or without any date...

Use :ambiguous_time_range => :none or, may be :ambiguous_time_range => 24 ?

And thank you for reply and for Chronic!

lemboy avatar May 29 '15 20:05 lemboy

I already mentioned by default, :context => :future and :hours24 => nil so you just pass :hours24 => true ;)

davispuh avatar May 29 '15 20:05 davispuh

Thanks again! For patience too. :)

lemboy avatar May 29 '15 20:05 lemboy