From: C. Scott Ananian Date: Sat, 22 Jan 2011 08:41:43 +0000 (-0500) Subject: Fix midnight end times. X-Git-Url: https://projects.mako.cc/source/selectricity-live/commitdiff_plain/3062c2d0a2b51fdf3c6b1f3bbd35d524020890a7?hp=b436d3fd0e673b4f5bcc01f0e7cce39ff0e40f82 Fix midnight end times. --- diff --git a/app/models/election.rb b/app/models/election.rb index b48c923..ac8d628 100644 --- a/app/models/election.rb +++ b/app/models/election.rb @@ -184,13 +184,23 @@ class Election < ActiveRecord::Base end end + def just_before_midnight(datetime) + if datetime.instance_of? DateTime + off = datetime.offset + else + off = Rational(datetime.utc_offset, 60*60*24) + end + return DateTime.new(datetime.year, datetime.month, datetime.day, + 23, 59, 59, off) + end + private def enforce_constraints + # elections end just before midnight + self.enddate = just_before_midnight(self.enddate) # kiosks can't be authenticated self.authenticated = false if kiosk? return true end end - - diff --git a/app/views/election/_overview_form.rhtml b/app/views/election/_overview_form.rhtml index 1f540c6..a36e817 100644 --- a/app/views/election/_overview_form.rhtml +++ b/app/views/election/_overview_form.rhtml @@ -17,7 +17,7 @@


All elections end at 23:59.
-<%= date_select :election, :enddate %>

+<%= datetime_select :election, :enddate, {:discard_hour=>true, :discard_minute=>true} %>


<% type_hash = {}; ELECTION_TYPES.each {|k,v| type_hash[v] = k} %>