Skip to content

Commit

Permalink
Merge pull request #22 from sepatel/master
Browse files Browse the repository at this point in the history
No longer use Geocode for UPS Timestamp
  • Loading branch information
freshlogic committed Sep 17, 2020
2 parents fae57de + f5c5af3 commit 4ad9a07
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions carriers/ups.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ function UPS(options) {
InquiryNumber: trackingNumber,
Request: {
RequestAction: 'Track',
RequestOption: 'activity'
RequestOption: 'activity',
SubVersion: '1907',
}
}
},
Expand Down Expand Up @@ -158,9 +159,13 @@ function UPS(options) {
activitiesList = getActivities(packageInfo);
}

async.mapLimit(Array.from(new Set(activitiesList.map(activity => activity.location))), 10, function(location, callback) {
async.mapLimit(Array.from(new Set(activitiesList.map(activity => [activity.location, activity.GMTTime]))), 10, function(info, callback) {
const location = info[0];
const gmt = info[1] != null;
if (!location) {
callback();
} else if (gmt) {
callback(null, location);
} else {
geography.parseLocation(location, options, function(err, address) {
if (err || !address) {
Expand All @@ -184,15 +189,20 @@ function UPS(options) {
address = addresses.find(a => a && a.location === activity.location);
}

let timezone = 'America/New_York';
let timezone = activity.GMTTime
? 'UTC'
: 'America/New_York';

if (address && address.timezone) {
timezone = address.timezone;
}

const ts = activity.GMTTime
? `${activity.GMTDate} ${activity.GMTTime}`
: `${activity.Date} ${activity.Time}`;
const event = {
address: activity.address,
date: moment.tz(`${activity.Date} ${activity.Time}`, 'YYYYMMDD HHmmss', timezone).toDate(),
date: moment.tz(ts, 'YYYYMMDD HHmmss', timezone).toDate(),
description: activity.Description || (activity.Status && activity.Status.Description) || (activity.Status && activity.Status.StatusType && activity.Status.StatusType.Description)
};

Expand Down Expand Up @@ -236,4 +246,4 @@ function UPS(options) {
}
}

module.exports = UPS;
module.exports = UPS;

0 comments on commit 4ad9a07

Please sign in to comment.