Created
June 28, 2014 00:53
-
-
Save trevvvy/41f90b40a8a5bd423117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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