Use Date.current and Time.current

Using Date.today and Time.now might lead to inconsistencies if the time
zone the application uses is not the same as the system time zone.
This commit is contained in:
Javi Martín
2019-06-18 01:15:06 +02:00
parent 158f59ce0d
commit a21240b230
20 changed files with 34 additions and 34 deletions

View File

@@ -44,10 +44,10 @@ class Dashboard::Action < ApplicationRecord
}
def self.active_for(proposal)
published_at = proposal.published_at&.to_date || Date.today
published_at = proposal.published_at&.to_date || Date.current
active.where("required_supports <= ?", proposal.cached_votes_up)
.where("day_offset <= ?", (Date.today - published_at).to_i)
.where("day_offset <= ?", (Date.current - published_at).to_i)
.by_proposal(proposal)
end
@@ -59,9 +59,9 @@ class Dashboard::Action < ApplicationRecord
end
def active_for?(proposal)
published_at = proposal.published_at&.to_date || Date.today
published_at = proposal.published_at&.to_date || Date.current
required_supports <= proposal.cached_votes_up && day_offset <= (Date.today - published_at).to_i
required_supports <= proposal.cached_votes_up && day_offset <= (Date.current - published_at).to_i
end
def requested_for?(proposal)
@@ -95,7 +95,7 @@ class Dashboard::Action < ApplicationRecord
private
def self.get_actions_for_today(proposal)
proposal_votes = proposal.cached_votes_up
day_offset = calculate_day_offset(proposal, Date.today)
day_offset = calculate_day_offset(proposal, Date.current)
calculate_actions(proposal_votes, day_offset, proposal)
end

View File

@@ -96,7 +96,7 @@ class Proposal < ApplicationRecord
end
def publish
update(published_at: Time.now)
update(published_at: Time.current)
send_new_actions_notification_on_published
end