Skip to content

Commit

Permalink
Convert dates on result objs to proper zulu time
Browse files Browse the repository at this point in the history
  • Loading branch information
zarathustra323 committed Dec 1, 2018
1 parent 0dc9c54 commit f72318e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const soap = require('soap');
const MarketingCloudAuth = require('marketing-cloud-auth');
const applyAuthHeader = require('./utils/apply-auth-header');
const convertDates = require('./utils/convert-dates');
const ResponseError = require('./objects/response-error');
const defaultProps = require('./default-props');

Expand Down Expand Up @@ -152,7 +153,12 @@ class MarketingCloudSOAP {
if (ResponseError.pattern.test(OverallStatus)) {
throw new ResponseError({ result, rawResponse, rawRequest }, OverallStatus);
}
return result;

const Results = (isArray(result.Results)) ? result.Results : [];
return {
...result,
Results: Results.map(obj => convertDates(obj)),
};
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/utils/convert-dates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const moment = require('moment-timezone');

const { keys } = Object;

module.exports = (obj) => {
if (!obj || typeof obj !== 'object') return obj;
return keys(obj).reduce((o, key) => {
const value = obj[key] instanceof Date
? moment.tz(moment(obj[key]).format('YYYY-MM-DDTHH:mm:ss'), 'America/Chicago').toDate()
: obj[key];
return { ...o, [key]: value };
}, {});
};

0 comments on commit f72318e

Please sign in to comment.