Skip to content

Instantly share code, notes, and snippets.

@trevvvy
Created June 28, 2014 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevvvy/41f90b40a8a5bd423117 to your computer and use it in GitHub Desktop.
Save trevvvy/41f90b40a8a5bd423117 to your computer and use it in GitHub Desktop.
class MigrateTimeZones
attr_reader :old_zone, :new_zone
def initialize(old_zone = "Pacific Time (US & Canada)", new_zone = Company.current.time_zone)
@old_zone = ActiveSupport::TimeZone.new old_zone
@new_zone = ActiveSupport::TimeZone.new new_zone
end
def call
update_appointments
update_shifts
update_requested_appointments
end
def update_appointments
Appointment.find_each do |a|
a.start_at = in_zone(a.start_at)
a.end_at = in_zone(a.end_at)
a.save
end
end
def update_shifts
end
def update_requested_appointments
end
def in_zone(old_time)
old_time + difference_for_date(old_time)
end
def difference_for_date(datetime)
date = datetime.to_date
old = old_zone.parse "#{date} 00:00:00"
new = new_zone.parse "#{date} 00:00:00"
new - old
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment