Skip to content

Commit

Permalink
Use exchange timezone when formatting quote, if none is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan authored and Bryan committed Dec 2, 2019
1 parent f1a2030 commit a5f5a49
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
11 changes: 5 additions & 6 deletions lib/marketState/Exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ module.exports = (() => {
this.offsetExchange = null;

const tzDdf = Timezones.parse(timezoneDdf);
const txExchange = Timezones.parse(timezoneExchange);


const tzExchange = Timezones.parse(timezoneExchange);

if (tzDdf !== null) {
this.timezoneDdf = tzDdf.code;
this.offsetDdf = tzDdf.getUtcOffset(null, true);
}

if (txExchange !== null) {
this.timezoneExchange = txExchange.code;
this.offsetExchange = txExchange.getUtcOffset(null, true);
if (tzExchange !== null) {
this.timezoneExchange = tzExchange.code;
this.offsetExchange = tzExchange.getUtcOffset(null, true);
}
}

Expand Down
18 changes: 13 additions & 5 deletions lib/utilities/format/quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,35 @@ module.exports = (() => {
let t;
let utc;

if (is.string(timezone) && quote.timeUtc !== null) {
if (quote.timeUtc !== null && (is.string(timezone) || (quote.profile && quote.profile.exchangeRef && quote.profile.exchangeRef && quote.profile.exchangeRef.timezoneExchange))) {
utc = true;

let tz;

if (is.string(timezone)) {
tz = timezone;
} else {
tz = quote.profile.exchangeRef.timezoneExchange;
}

let epoch = quote.timeUtc.getTime();

if (!offsets.hasOwnProperty(timezone)) {
if (!offsets.hasOwnProperty(tz)) {
const offset = { };

offset.latest = epoch;
offset.timezone = Timezone.parse(timezone);
offset.timezone = Timezone.parse(tz);

if (offset.timezone !== null) {
offset.milliseconds = offset.timezone.getUtcOffset(null, true);
} else {
offset.milliseconds = null;
}

offsets[timezone] = offset;
offsets[tz] = offset;
}

const o = offsets[timezone];
const o = offsets[tz];

if (o.milliseconds !== null) {
t = new Date(epoch + o.milliseconds);
Expand Down

0 comments on commit a5f5a49

Please sign in to comment.