]> projects.mako.cc - selectricity/commitdiff
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 b48c9238c0bf39a2a79f1a044d0ec723626a4395..ac8d628b16f003a1848f78215aa6f9b4e9811412 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 1f540c62462e056605af8684753ef6c44380fe38..a36e8172257f0e4dfb9ec17f227cd5186c436e61 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?