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

Not working in certain time zones #56

Closed
sgringwe opened this issue Feb 23, 2015 · 3 comments
Closed

Not working in certain time zones #56

sgringwe opened this issue Feb 23, 2015 · 3 comments

Comments

@sgringwe
Copy link

Our tests run in random time zones. In some of the time zones, the date validator does not seem to work:

The code:

ap @appointment.valid?
ap @appointment.errors.full_messages.join(', ')
ap @appointment.start_date
ap @appointment.end_date

The output:

false
"End date must be a date on or after 2015-02-24"
Tue, 24 Feb 2015 01:11:09 KRAT +07:00
Tue, 24 Feb 2015 02:11:09 KRAT +07:00
@akshaysmurthy
Copy link

A snippet of your model validation code code would be very useful here. But it looks like the date given in the validation is a Date object while @appointment.end_date is an ActiveSupport::TimeWithZone object.

Try this -

DATE_GIVEN_IN_THE_VALIDATION.in_time_zone.utc

@appointment.end_date.utc

I think you will find that the validation is right :)

@sgringwe
Copy link
Author

@akshaysmurthy my validations are

validates :start_date, presence: true, date: {}
validates :end_date, presence: true, date: { on_or_after: :start_date }

both are a datetime in the db

#  start_date                 :datetime
#  end_date                   :datetime

but it's possible rails is interpreting them differently from the server?

@akshaysmurthy
Copy link

@sgringwe
If you look at https://github.com/codegram/date_validator/blob/master/lib/active_model/validations/date_validator.rb#L15, you'll see that on_or_after is not a valid check. You should use after_or_equal_to.

@sgringwe sgringwe closed this as completed Oct 2, 2016
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