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

Can't set time_class to Date #411

Open
jgomo3 opened this issue Apr 3, 2023 · 1 comment
Open

Can't set time_class to Date #411

jgomo3 opened this issue Apr 3, 2023 · 1 comment

Comments

@jgomo3
Copy link

jgomo3 commented Apr 3, 2023

This line [1] suggest that one could use Date as the time_class. But if you do, then this other line fails[2] because the class Date doesn't have the now method.

You would think that the option :now would work, but line[3] fails as it doesn't use this option.

require 'date'
require 'chronic'
Chronic.time_class = Date
Chronic.parse('2000 January 1st', now: Time.now)

Error:

Traceback (most recent call last):
       11: from bin/console:14:in `<main>'
       10: from (irb):5
        9: from /home/monkey/.rvm/gems/ruby-2.7.2/gems/chronic-0.10.2/lib/chronic.rb:90:in `parse'
        8: from /home/monkey/.rvm/gems/ruby-2.7.2/gems/chronic-0.10.2/lib/chronic/parser.rb:60:in `parse'
        7: from /home/monkey/.rvm/gems/ruby-2.7.2/gems/chronic-0.10.2/lib/chronic/parser.rb:228:in `tokenize'
        6: from /home/monkey/.rvm/gems/ruby-2.7.2/gems/chronic-0.10.2/lib/chronic/parser.rb:228:in `each'
        5: from /home/monkey/.rvm/gems/ruby-2.7.2/gems/chronic-0.10.2/lib/chronic/parser.rb:229:in `block in tokenize'
        4: from /home/monkey/.rvm/gems/ruby-2.7.2/gems/chronic-0.10.2/lib/chronic/ordinal.rb:12:in `scan'
        3: from /home/monkey/.rvm/gems/ruby-2.7.2/gems/chronic-0.10.2/lib/chronic/ordinal.rb:12:in `each_index'
        2: from /home/monkey/.rvm/gems/ruby-2.7.2/gems/chronic-0.10.2/lib/chronic/ordinal.rb:19:in `block in scan'
        1: from /home/monkey/.rvm/gems/ruby-2.7.2/gems/chronic-0.10.2/lib/chronic/date.rb:66:in `make_year'
NoMethodError (undefined method `now' for Date:Class)
Did you mean?  new

[1] https://github.com/mojombo/chronic/blob/master/lib/chronic.rb#L145
[2] https://github.com/mojombo/chronic/blob/master/lib/chronic/parser.rb#L60
[3] https://github.com/mojombo/chronic/blob/master/lib/chronic/date.rb#L65

@sriram0601
Copy link

Chronic gem basically parse the given string to suitable Time or DateTime object, when it comes to Date, we cannot handle the time based methods (i.e: we cannot find hour, mins and seconds). I think thats why they don't provide option to handle Date class.

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

2 participants