sailrish / shipit

shipit node module
MIT License
86 stars 65 forks source link

render a datetime in addition to timestamp for carriers that provide timezone in shipment activites #29

Closed sailrish closed 8 years ago

sailrish commented 8 years ago

Most shipping carriers have activities with time data along with location and a description of the event, like this:

<Timestamp>2016-04-30T11:52:56-04:00</Timestamp>
    <EventDescription>Delivered</EventDescription>
    <StatusExceptionDescription>
        Left at back door. Signature Service not requested.
    </StatusExceptionDescription>
    <Address>
        <City>Aiken</City>
        <StateOrProvinceCode>SC</StateOrProvinceCode>
        <PostalCode>29805</PostalCode>
        <CountryCode>US</CountryCode>
    </Address>

But the time information is sometimes a timestamp, and sometimes only a datetime. The distinction between the two is that a timestamp contains timezone information (such as in the fedex example above, in the form of a UTC offset -04:00). The only two carriers that provide a timezone-rich timestamp are FedEx and A1 International. This PR updates the implementation for those two carriers to return both a timestamp and a datetime field in all the activities of a shipment.

Here's what the output for a fedex shipment will now look like (notice the datetime field which represents the local time at the location specified in the activity):

{
  "eta": "2016-05-10T23:59:59.000Z",
  "service": "FedEx Home Delivery",
  "weight": "2.9 LB",
  "destination": "Ottumwa, IA",
  "activities": [
    {
      "timestamp": "2016-05-07T11:00:00.000Z",
      "datetime": "2016-05-07T06:00:00",
      "location": "Ottumwa, IA 52501",
      "details": "On FedEx vehicle for delivery"
    },
    {
      "timestamp": "2016-05-07T09:52:04.000Z",
      "datetime": "2016-05-07T04:52:04",
      "location": "Ottumwa, IA 52501",
      "details": "At local FedEx facility"
    },
    {
      "timestamp": "2016-05-07T07:26:02.000Z",
      "datetime": "2016-05-07T02:26:02",
      "location": "Rock Island, IL 61201",
      "details": "Departed FedEx location"
    },
    {
      "timestamp": "2016-05-07T04:48:00.000Z",
      "datetime": "2016-05-06T23:48:00",
      "location": "Rock Island, IL 61201",
      "details": "Arrived at FedEx location"
    },
    {
      "timestamp": "2016-05-07T00:58:08.000Z",
      "datetime": "2016-05-06T19:58:08",
      "location": "Carol Stream, IL 60188",
      "details": "Left FedEx origin facility"
    },
    {
      "timestamp": "2016-05-06T23:05:00.000Z",
      "datetime": "2016-05-06T18:05:00",
      "location": "Carol Stream, IL 60188",
      "details": "Arrived at FedEx location"
    },
    {
      "timestamp": "2016-05-06T21:29:00.000Z",
      "datetime": "2016-05-06T16:29:00",
      "location": "Carol Stream, IL 60188",
      "details": "Picked up"
    },
    {
      "timestamp": "2016-05-06T20:51:00.000Z",
      "datetime": "2016-05-06T15:51:00",
      "location": "US 60532",
      "details": "Shipment information sent to FedEx"
    }
  ],
  "status": 3,
  "request": {
    "trackingNumber": "783008979965"
  }
}
sailrish commented 8 years ago

@cmswalker and @katylava: would you please review this? This should address #27, and is similar to #28.

cmswalker commented 8 years ago

This looks great, mind updating the README with this info? If you dont have the time, let me know and I will, but I say this PR looks good to go, thank you!

sailrish commented 8 years ago

Thanks @cmswalker. I have updated the readme, and I'm now merging this PR. I have one more pending change related to a timeout option for shipping carrier objects. Once that's done too, I'll release a new version to NPM. Thanks for your help. And @katylava thanks for bringing this issue to my attention, and identifying the incorrect test case.

katylava commented 8 years ago

Sorry I didn't reply in a timely fashion. Thanks for the fix!