Skip to content

Commit

Permalink
UPS events time zone (#4)
Browse files Browse the repository at this point in the history
* fix: Set correct timezone for shipping events

* fix: Better management of the offset

* fix: Improved code

* chore: bump version
  • Loading branch information
jheysen authored Dec 7, 2021
1 parent 66b322b commit 82e068c
Show file tree
Hide file tree
Showing 5 changed files with 394 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/active_shipping/carriers/ups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ def parse_tracking_response(response, options = {})
shipment_events = activities.map do |activity|
description = activity.at('Status/StatusType/Description').try(:text)
type_code = activity.at('Status/StatusType/Code').try(:text)
zoneless_time = parse_ups_datetime(:time => activity.at('Time'), :date => activity.at('Date'))
zoneless_time = parse_ups_datetime(:time => activity.at('Time'), :date => activity.at('Date'), :offset => activity.at('GMTOffset'))
location = location_from_address_node(activity.at('ActivityLocation/Address'))
ShipmentEvent.new(description, zoneless_time, location, description, type_code)
end
Expand Down Expand Up @@ -1107,15 +1107,16 @@ def location_from_address_node(address)
end

def parse_ups_datetime(options = {})
time, date = options[:time].try(:text), options[:date].text
time, date, offset = options[:time].try(:text), options[:date].text, options[:offset]&.text
if time.nil?
hour, minute, second = 0
else
hour, minute, second = time.scan(/\d{2}/)
end
offset ||= '+00:00'
year, month, day = date[0..3], date[4..5], date[6..7]

Time.utc(year, month, day, hour, minute, second)
Time.new(year, month, day, hour, minute, second, offset).utc
end

def response_success?(document)
Expand Down
2 changes: 1 addition & 1 deletion lib/active_shipping/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveShipping
VERSION = "2.3.1"
VERSION = "2.3.2"
end
Loading

0 comments on commit 82e068c

Please sign in to comment.