Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1146 from YaleSTC/939_fix_dates
Browse files Browse the repository at this point in the history
#939 Fix Dates
  • Loading branch information
squidgetx committed Feb 17, 2015
2 parents f70fb3b + ca2d1c7 commit 6551de9
Show file tree
Hide file tree
Showing 76 changed files with 317 additions and 300 deletions.
4 changes: 2 additions & 2 deletions app/controllers/announcements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def index
end

def new
@announcement = Announcement.new(starts_at: Date.current,
ends_at: Date.tomorrow)
@announcement = Announcement.new(starts_at: Time.zone.today,
ends_at: Time.zone.today + 1.day)
end

def create
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def check_view_mode
end

def fix_cart_date
cart.start_date = (Date.current) if cart.start_date < Date.current
cart.start_date = (Time.zone.today) if cart.start_date < Time.zone.today
cart.fix_due_date
end

Expand Down Expand Up @@ -153,7 +153,7 @@ def update_cart # rubocop:disable MethodLength, AbcSize
params[:reserver_id]
end
rescue ArgumentError
cart.start_date = Date.current
cart.start_date = Time.zone.today
flash[:error] = 'Please enter a valid start or due date.'
end

Expand Down
6 changes: 4 additions & 2 deletions app/controllers/blackouts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ def show
end

def new
@blackout = Blackout.new(start_date: Date.current, end_date: Date.tomorrow)
@blackout = Blackout.new(start_date: Time.zone.today,
end_date: Time.zone.today + 1.day)
end

def new_recurring
@blackout = Blackout.new(start_date: Date.current, end_date: Date.tomorrow)
@blackout = Blackout.new(start_date: Time.zone.today,
end_date: Time.zone.today + 1.day)
end

def edit
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/equipment_models_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def show
@reservation_data =
Reservation.active.for_eq_model(@equipment_model).collect do |r|
if r.status == 'overdue'
end_date = Date.current + calendar_length
end_date = Time.zone.today + calendar_length
else
end_date = r.due_date
end
Expand All @@ -53,7 +53,7 @@ def show
{ start: b.start_date, end: b.end_date }
end

@date = Time.current.to_date
@date = Time.zone.today
@date_max = @date + calendar_length - 1.week
@max = @equipment_model.equipment_objects.active.count

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/equipment_objects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def new

def create
@equipment_object = EquipmentObject.new(equipment_object_params)
@equipment_object.notes = "#### Created at #{Time.current.to_s(:long)} "\
@equipment_object.notes = "#### Created at #{Time.zone.now.to_s(:long)} "\
"by #{current_user.md_link}."
if @equipment_object.save
flash[:notice] = 'Successfully created equipment object. '\
Expand Down Expand Up @@ -72,7 +72,7 @@ def update
def deactivate # rubocop:disable MethodLength, AbcSize
if params[:deactivation_reason] && !params[:deactivation_cancelled]
# update notes and deactivate
new_notes = "#### Deactivated at #{Time.current.to_s(:long)} by "\
new_notes = "#### Deactivated at #{Time.zone.now.to_s(:long)} by "\
"#{current_user.md_link}\n#{params[:deactivation_reason]}\n\n"\
+ @equipment_object.notes
@equipment_object.update_attributes(
Expand All @@ -97,7 +97,7 @@ def deactivate # rubocop:disable MethodLength, AbcSize

def activate
super
new_notes = "#### Reactivated at #{Time.current.to_s(:long)} by "\
new_notes = "#### Reactivated at #{Time.zone.now.to_s(:long)} by "\
"#{current_user.md_link}\n\n" + @equipment_object.notes
@equipment_object.update_attributes(deactivation_reason: nil,
notes: new_notes)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ def start_date
if session[:report_start_date].present?
session[:report_start_date]
else
Date.current - 1.year
Time.zone.today - 1.year
end
end

def end_date
if session[:report_end_date].present?
session[:report_end_date]
else
Date.current
Time.zone.today
end
end
end
12 changes: 6 additions & 6 deletions app/controllers/reservations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def set_reservation
end

def set_index_dates
session[:index_start_date] ||= Date.today - 7.days
session[:index_end_date] ||= Date.today + 7.days
session[:index_start_date] ||= Time.zone.today - 7.days
session[:index_end_date] ||= Time.zone.today + 7.days
@start_date = session[:index_start_date]
@end_date = session[:index_end_date]
end
Expand Down Expand Up @@ -168,7 +168,7 @@ def create # rubocop:disable all
if (cannot? :manage, Reservation) || (requested == true)
redirect_to(catalog_path) && return
end
if start_date.to_date == Date.current
if start_date == Time.zone.today
flash[:notice] += ' Are you simultaneously checking out equipment '\
'for someone? Note that only the reservation has been made. '\
'Don\'t forget to continue to checkout.'
Expand Down Expand Up @@ -399,7 +399,7 @@ def renew
redirect_to(@reservation) && return
else
flash[:notice] = 'Your reservation has been renewed until '\
"#{@reservation.due_date.to_date.to_s(:long)}."
"#{@reservation.due_date.to_s(:long)}."
redirect_to @reservation
end
end
Expand All @@ -415,7 +415,7 @@ def review
def approve_request
@reservation.approval_status = 'approved'
@reservation.notes = @reservation.notes.to_s # in case of nil
@reservation.notes += "\n\n### Approved on #{Time.current.to_s(:long)} "\
@reservation.notes += "\n\n### Approved on #{Time.zone.now.to_s(:long)} "\
"by #{current_user.md_link}"
if @reservation.save
flash[:notice] = 'Request successfully approved'
Expand All @@ -431,7 +431,7 @@ def approve_request
def deny_request
@reservation.approval_status = 'denied'
@reservation.notes = @reservation.notes.to_s # in case of nil
@reservation.notes += "\n\n### Denied on #{Time.current.to_s(:long)} by "\
@reservation.notes += "\n\n### Denied on #{Time.zone.now.to_s(:long)} by "\
"#{current_user.md_link}"
if @reservation.save
flash[:notice] = 'Request successfully denied'
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/category_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def make_deactivate_btn
object.equipment_models.each do |em|
res += Reservation.for_eq_model(em)
.reserved_in_date_range(
Date.current - 1.day, Date.current + 7.days)
Time.zone.today - 1.day, Time.zone.today + 7.days)
.not_returned.count
end
onclick_str = "handleBigDeactivation(this, #{res}, 'category');"
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/equipment_model_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def make_deactivate_btn
# find reservations in the next week
res = Reservation.for_eq_model(object)
.reserved_in_date_range(
Date.current - 1.day, Date.current + 7.days)
Time.zone.today - 1.day, Time.zone.today + 7.days)
.not_returned.count
onclick_str = "handleBigDeactivation(this, #{res}, 'equipment model');"
end
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/equipment_object_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def make_deactivate_btn
em = object.equipment_model
res = object.current_reservation
overbooked_dates = []
(Date.current..Date.current + 7.days).each do |date|
(Time.zone.today..Time.zone.today + 7.days).each do |date|
overbooked_dates << date.to_s(:short) if em.available_count(date) <= 0
end
onclick_str = "handleDeactivation(this, #{res ? res.id : 'null'}, "\
Expand Down
7 changes: 3 additions & 4 deletions app/helpers/reservations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def filter_message(set, source, filter, view_all)

def reservation_length
@reservation_length =
(@reservation.due_date.to_date - @reservation.start_date.to_date).to_i
(@reservation.due_date - @reservation.start_date).to_i
end

def bar_progress_res
Expand Down Expand Up @@ -62,9 +62,8 @@ def manage_reservations_btn # rubocop:disable all
# the "+ 1" terms are to account for the fact that the first
# day is counted as part of the length of the reservation.
def define_width_res
passed_length = Time.current.to_date - @reservation.start_date.to_date + 1
total_length = @reservation.due_date.to_date\
- @reservation.start_date.to_date + 1
passed_length = Time.zone.today - @reservation.start_date + 1
total_length = @reservation.due_date - @reservation.start_date + 1
# necessary to prevent division by 0
total_length = total_length == 0 ? 1 : total_length
@width = passed_length / total_length
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/user_mailer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def replace_variables(body)
body.gsub!('@reservation_id@', @reservation.id.to_s)
body.gsub!('@department_name@', @app_configs.department_name)
body.gsub!('@equipment_list@', @reservation.equipment_model.name)
body.gsub!('@return_date@', @reservation.due_date.to_date.to_s(:long))
body.gsub!('@start_date@', @reservation.start_date.to_date.to_s(:long))
body.gsub!('@return_date@', @reservation.due_date.to_s(:long))
body.gsub!('@start_date@', @reservation.start_date.to_s(:long))
body.gsub!('@late_fee@', number_to_currency(@reservation.late_fee))
body.gsub!('@replacement_fee@', number_to_currency(
@reservation.equipment_model.replacement_fee))
Expand Down
2 changes: 1 addition & 1 deletion app/inputs/deleted_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ def build_check_box(_unchecked_value = '')
@builder.object.deleted_at.blank? ? { checked: false } : { checked: true }
@builder.check_box(attribute_name,
box_val,
Time.current, '')
Time.zone.now, '')
end
end
2 changes: 1 addition & 1 deletion app/mailers/admin_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def notes_reservation_notification(notes_reservations_out,
@notes_reservations_in = notes_reservations_in
mail(to: @app_configs.admin_email,
subject: '[Reservations] Notes for '\
+ (Date.yesterday.midnight).strftime('%m/%d/%y'))
+ (Time.zone.today - 1.day).strftime('%m/%d/%y'))
end

def overdue_checked_in_fine_admin(overdue_checked_in)
Expand Down
2 changes: 1 addition & 1 deletion app/models/announcement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Announcement < ActiveRecord::Base

def self.current(hidden_ids = nil)
result = where('starts_at <= :now and ends_at >= :now',
now: Time.zone.now)
now: Time.zone.today)
result = result.where('id not in (?)', hidden_ids) if hidden_ids.present?
result
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/blackout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Blackout < ActiveRecord::Base
# this only matters if a user tries to inject into params because the
# datepicker doesn't allow form submission of invalid dates

scope :active, ->() { where('end_date >= ?', Date.current) }
scope :active, ->() { where('end_date >= ?', Time.zone.today) }
scope :for_date, lambda { |date|
where('end_date >= ? and start_date <= ?', date, date)
}
Expand Down
10 changes: 5 additions & 5 deletions app/models/cart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Cart
def initialize
@errors = ActiveModel::Errors.new(self)
@items = {}
@start_date = Date.current
@due_date = Date.tomorrow
@start_date = Time.zone.today
@due_date = Time.zone.today + 1.day
@reserver_id = nil
end

Expand Down Expand Up @@ -79,13 +79,13 @@ def reserve_all(user, res_notes = '', request = false) # rubocop:disable all
reservations.each do |r|
errors = r.validate
if request
notes = "### Requested on #{Time.current.to_s(:long)} by "\
notes = "### Requested on #{Time.zone.now.to_s(:long)} by "\
"#{user.md_link}\n\n#### Notes:\n#{res_notes}"
r.approval_status = 'requested'
message << "Request for #{r.equipment_model.md_link} filed "\
"successfully. #{errors.to_sentence}\n"
else
notes = "### Reserved on #{Time.current.to_s(:long)} by "\
notes = "### Reserved on #{Time.zone.now.to_s(:long)} by "\
"#{user.md_link}"
notes += "\n\n#### Notes:\n#{res_notes}" unless res_notes.nil? ||
res_notes.empty?
Expand All @@ -110,7 +110,7 @@ def request_all(user, notes = '')

# Returns the cart's duration
def duration # in days
@due_date.to_date - @start_date.to_date + 1
@due_date - @start_date + 1
end

# Returns the reserver
Expand Down
2 changes: 1 addition & 1 deletion app/models/cart_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def check_max_items(count_hash, relevant, count_method)
count_hash.each do |item, q|
max = item.maximum_per_user

start_date.to_date.upto(due_date.to_date) do |d|
start_date.upto(due_date) do |d|
unless Reservation.send(count_method, d, item.id, relevant) + q > max
next
end
Expand Down
5 changes: 2 additions & 3 deletions app/models/equipment_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def num_reserved(start_date, due_date, source_reservations)
# uses 0 queries, you need to specify the max number of
# items yourself
max_reserved = 0
start_date.to_date.upto(due_date.to_date) do |d|
start_date.upto(due_date) do |d|
reserved = Reservation.number_for_model_on_date(d, id,
source_reservations)
max_reserved = reserved if reserved > max_reserved
Expand All @@ -188,8 +188,7 @@ def num_available(start_date, due_date)
# for if you just want the number available, 1 query to get
# relevant reservations
relevant_reservations = Reservation.for_eq_model(self)
.reserved_in_date_range(start_date.to_datetime,
due_date.to_datetime)
.reserved_in_date_range(start_date, due_date)
.not_returned.all
num_available_from_source(start_date, due_date, relevant_reservations)
end
Expand Down
4 changes: 2 additions & 2 deletions app/models/equipment_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def make_switch_notes(old_res, new_res, handler)
new_res_msg = new_res ? new_res.md_link : 'available'
update_attributes(notes: "#### Switched by #{handler.md_link} from "\
"#{old_res_msg} to #{new_res_msg} on "\
"#{Time.current.to_s(:long)}\n\n" + notes)
"#{Time.zone.now.to_s(:long)}\n\n" + notes)
end

def update(current_user, new_params) # rubocop:disable all
Expand All @@ -79,7 +79,7 @@ def update(current_user, new_params) # rubocop:disable all
if changes.empty?
return self
else
new_notes = "#### Edited at #{Time.current.to_s(:long)} by "\
new_notes = "#### Edited at #{Time.zone.now.to_s(:long)} by "\
"#{current_user.md_link}\n\n"
new_notes += "\n\n#### Changes:"
changes.each do |param, diff|
Expand Down
Loading

0 comments on commit 6551de9

Please sign in to comment.