adzap / validates_timeliness

Date and time validation plugin for ActiveModel and Rails. Supports multiple ORMs and allows custom date/time formats.
MIT License
1.59k stars 227 forks source link

Use Time.zone for restriction shorthand #111

Closed damien closed 10 years ago

damien commented 10 years ago

The restriction shorthand seems to be referencing Time.now and Date.today. As far as I'm aware, this is not the correct way to reference localized time within rails; more specifically I don't believe these methods will pick up changes to Time.zone.

Time.zone.today and Time.zone.now will respect changes to Time.zone within rails. I'd be happy to submit a pull request with tests for these changes, would there be any objections to getting this into the gem?

adzap commented 10 years ago

These are shortcut equivalents to the zoned full version.

http://api.rubyonrails.org/v3.2.14/classes/Time.html#method-c-current

On 04/12/2013, at 4:47 PM, Damien Wilson notifications@github.com wrote:

The (restriction shorthand)[https://github.com/adzap/validates_timeliness/blob/master/lib/validates_timeliness.rb#L38-L41] seems to be referencing Time.now and Date.today. As far as I'm aware, this is not the correct way to reference localized time within rails; more specifically I don't believe these methods will pick up changes to Time.zone.

Time.zone.today and Time.zone.now will respect changes to Time.zone within rails. I'd be happy to submit a pull request with tests for these changes, would there be any objections to getting this into the gem?

— Reply to this email directly or view it on GitHub.

damien commented 10 years ago

@adzap Consider me enlightened, these things I did not know! Sorry for taking up your time with a non-issue. :)