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

Incorrect date parse #375

Open
MeterSoft opened this issue Mar 17, 2018 · 7 comments
Open

Incorrect date parse #375

MeterSoft opened this issue Mar 17, 2018 · 7 comments
Labels

Comments

@MeterSoft
Copy link

[10] pry(#)> Chronic.parse("4/30")
=> Mon, 30 Apr 2018 12:00:00 PDT -07:00
[11] pry(#)> Chronic.parse("4/31")
=> nil
[12] pry(#)> Chronic.parse("4/32")
=> Fri, 16 Apr 2032 00:00:00 PDT -07:00

In last example should be nil

@davispuh davispuh added the bug label Mar 17, 2018
@davispuh
Copy link
Collaborator

It's fixed in my unfinished rewrite branch.

@MeterSoft
Copy link
Author

@davispuh yes, this branch works with my example but has many another issues.
Example
[5] pry(Order)> Chronic.parse("1/1/18")
=> Mon, 01 Jan 2018 12:00:00 PST -08:00
[6] pry(Order)> Chronic.parse("01/1/18")
=> Thu, 18 Jan 2001 12:00:00 PST -08:00
[7] pry(Order)> Chronic.parse("1/01/18")
=> Mon, 01 Jan 2018 12:00:00 PST -08:00
[8] pry(Order)> Chronic.parse("11/01/18")
=> Tue, 18 Jan 2011 12:00:00 PST -08:00

@davispuh
Copy link
Collaborator

That's kinda expected behavior. There are 3 different ways how to interpret it and it just guesses it as best as it's possible.

In lib/chronic/definition.rb
you can see there is

[[ScalarYear, SeparatorSlash, ScalarMonth, SeparatorSlash, ScalarDay], :handle_sy_sm_sd],
...
[[ScalarMonth, SeparatorSlash, ScalarDay, SeparatorSlash, ScalarYear, [SeparatorDot, Scalar, :none]], :handle_sm_sd_sy],
...
[[ScalarDay, SeparatorSlash, ScalarMonth, SeparatorSlash, ScalarYear, [SeparatorDot, Scalar, :none]], :handle_sd_sm_sy],

@MeterSoft
Copy link
Author

it is possible to set default format %m%d%y ?

@davispuh
Copy link
Collaborator

Default I don't think so. But you could remove other formats with monkey patching.

Anyway firstly you need to pass :endian_precedence => [:middle] so it doesn't use dd/mm/yy and then to remove other formats

class Chronic::DateDefinitions
  def definitions
    []
  end
end

class Chronic::ShortDateDefinitions
  def definitions
    []
  end
end

class Chronic::DateTimeDefinitions
  def definitions
    []
  end
end

@MeterSoft
Copy link
Author

it is possible to fix reported issue in this master branch?

@davispuh
Copy link
Collaborator

It will be fixed when rewrite branch will be finished and merged in master.

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

No branches or pull requests

2 participants