Fix midnight end times.
authorC. Scott Ananian <cscott@cscott.net>
Sat, 22 Jan 2011 08:41:43 +0000 (03:41 -0500)
committerBenjamin Mako Hill <mako@atdot.cc>
Sun, 17 Jun 2012 23:13:06 +0000 (19:13 -0400)
app/models/election.rb
app/views/election/_overview_form.rhtml

index b48c923..ac8d628 100644 (file)
@@ -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
-
-
index 1f540c6..a36e817 100644 (file)
@@ -17,7 +17,7 @@
 
 <p><label for="election_enddate">Election End Date</label><br />
 <font size="-1"><em>All elections end at 23:59.</em></font><br />
-<%= date_select :election, :enddate %></p>
+<%= datetime_select :election, :enddate, {:discard_hour=>true, :discard_minute=>true} %></p>
 
 <p><label for="election_election_method">Election Method</label><br />
 <% type_hash = {}; ELECTION_TYPES.each {|k,v| type_hash[v] = k} %>

Benjamin Mako Hill || Want to submit a patch?