Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chronic thinks it can parse a date if the string begins "a " #402

Open
colinlieberman opened this issue Sep 24, 2020 · 2 comments
Open

Chronic thinks it can parse a date if the string begins "a " #402

colinlieberman opened this issue Sep 24, 2020 · 2 comments

Comments

@colinlieberman
Copy link

Apologies if this has already been addressed and I didn't find it when searching.

ruby 2.4.0p0
chronic 0.10.2

First had this issue with the string "A Swiftly Turning Planet", and expected a nil return:

> Chronic.parse("A Swiftly Tilting Planet")
 => 2020-09-24 13:00:00 -0700

After some poking around, it looks like it's the letter A followed by a space that's the issue:

2.4.0 :001 > Chronic.parse("tomatoes")
 => nil
2.4.0 :002 > Chronic.parse("A Swiftly Tilting Planet")
 => 2020-09-24 13:00:00 -0700
2.4.0 :003 > Chronic.parse("A Swiftly Tilting Planet", guess: false)
 => 2020-09-24 13:00:00 -0700..2020-09-24 13:00:01 -0700
2.4.0 :004 > Chronic.parse("A Swiftly Tilting Planet")
 => 2020-09-24 13:00:00 -0700
2.4.0 :005 > Chronic.parse("A Swiftly zTilting Planet")
 => 2020-09-24 13:00:00 -0700
2.4.0 :006 > Chronic.parse("A Swiftly zTilting Planetzzzz")
 => 2020-09-24 13:00:00 -0700
2.4.0 :007 > Chronic.parse("abracadabra")
 => nil
2.4.0 :008 > Chronic.parse("abracadabra tomatoes")
 => nil
2.4.0 :009 > Chronic.parse("abracadabra tomatoes planet")
 => nil
2.4.0 :010 > Chronic.parse("abracadabra tomatoes planet swift")
 => nil
2.4.0 :011 > Chronic.parse("A potatoe")
 => 2020-09-24 13:00:00 -0700
2.4.0 :012 > Chronic.parse("A potato")
 => 2020-09-24 13:00:00 -0700
2.4.0 :013 > Chronic.parse("B potato")
 => nil
2.4.0 :014 > Chronic.parse("A potato")
 => 2020-09-24 13:00:00 -0700
2.4.0 :015 > Chronic.parse("Apotato")
 => nil
@anuja-joshi
Copy link

Same happens for string starting with letter "p" and having number

[91] pry(main)> Chronic.parse("p 2")
=> 2021-01-22 14:00:00 +0530
[92] pry(main)> Chronic.parse("panything random 2")
=> 2021-01-22 14:00:00 +0530
[93] pry(main)> Chronic.parse("p nything random 2")
=> 2021-01-22 14:00:00 +0530
[94] pry(main)> Chronic.parse("p nything random")
=> nil

@nanobowers
Copy link

@colinlieberman
it's due to this line in the pre-normalization step:

   text.gsub!(/^\s?an? /i, '1 ')

which converts any a/an followed by a space into the numeric '1' which is allowed as a standalone scalar value and interpreted as a time (1pm?). AFAICT it's there to address interpreting "a minute" as "1 minute" or "an hour" as "1 hour" cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants