Skip to content

Commit

Permalink
Fix invalid date issues
Browse files Browse the repository at this point in the history
  • Loading branch information
svk31 committed Nov 2, 2017
1 parent 4f57b87 commit 75e6a99
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 15 deletions.
10 changes: 7 additions & 3 deletions app/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class App extends React.Component {
let synced = true;
let dynGlobalObject = ChainStore.getObject("2.1.0");
if (dynGlobalObject) {
let block_time = dynGlobalObject.get("time") + "+00:00";
let block_time = dynGlobalObject.get("time");
if (!/Z$/.test(block_time)) {
block_time += "Z";
}

let bt = (new Date(block_time).getTime() + ChainStore.getEstimatedChainTimeOffset()) / 1000;
let now = new Date().getTime() / 1000;
synced = Math.abs(now - bt) < 5;
Expand Down Expand Up @@ -137,7 +141,7 @@ class App extends React.Component {
theme: settings.get("themes")
});
}


}

Expand Down Expand Up @@ -176,7 +180,7 @@ class App extends React.Component {
<div className="grid-block vertical">
{this.props.children}
</div>

</div>
{showFooter ? <Footer synced={this.state.synced}/> : null}
<ReactTooltip ref="tooltip" place="top" type={theme === "lightTheme" ? "dark" : "light"} effect="solid"/>
Expand Down
5 changes: 4 additions & 1 deletion app/components/Account/AccountVoting.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,13 @@ class AccountVoting extends React.Component {
budgetObject = ChainStore.getObject(lastBudgetObject ? lastBudgetObject : "2.13.1");
if (budgetObject) {
let timestamp = budgetObject.get("time");
if (!/Z$/.test(timestamp)) {
timestamp += "Z";
}
let now = new Date();

let idIndex = parseInt(budgetObject.get("id").split(".")[2], 10);
let currentID = idIndex + Math.floor((now - new Date(timestamp + "+00:00").getTime()) / 1000 / 60 / 60) - 1;
let currentID = idIndex + Math.floor((now - new Date(timestamp).getTime()) / 1000 / 60 / 60) - 1;
let newID = "2.13." + Math.max(idIndex, currentID);

ChainStore.getObject(newID);
Expand Down
7 changes: 3 additions & 4 deletions app/components/Utility/TimeAgo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ class TimeAgo extends React.Component {

render() {
let {time, chain_time} = this.props;
var offset_mills = chain_time ? ChainStore.getEstimatedChainTimeOffset() : 0
var offset_mills = chain_time ? ChainStore.getEstimatedChainTimeOffset() : 0;
if (!time) {
return null;
}

if (typeof time === "string" && time.indexOf("+") === -1) {
time += "+00:00";
if (typeof time === "string" && time.indexOf("+") === -1 && !/Z$/.test(time)) {
time += "Z";
}

let timePassed = Math.round( ( new Date().getTime() - new Date(time).getTime() + offset_mills ) / 1000 );
Expand Down
4 changes: 2 additions & 2 deletions app/lib/common/market_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ const MarketUtils = {
if (order.time) {
time = order.time.split("T")[1];
let now = new Date();
let offset = now.getTimezoneOffset() / 60;
let date = utils.format_date(order.time + "Z").split(/\W/);
let offset = now.getTimezoneOffset() / 60;
let date = utils.format_date(order.time).split(/\W/);
let hour = time.substr(0, 2);
let hourNumber = parseInt(hour, 10);
let localHour = hourNumber - offset;
Expand Down
8 changes: 7 additions & 1 deletion app/lib/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,17 @@ var Utils = {
},

format_date: function(date_str) {
if (!/Z$/.test(date_str)) {
date_str += "Z";
}
let date = new Date(date_str);
return date.toLocaleDateString();
},

format_time: function(time_str) {
if (!/Z$/.test(time_str)) {
time_str += "Z";
}
let date = new Date(time_str);
return date.toLocaleString();
},
Expand Down Expand Up @@ -464,7 +470,7 @@ var Utils = {
if (!globalObject || !dynGlobalObject) return null;
const block_interval = globalObject.get("parameters").get("block_interval");
const head_block = dynGlobalObject.get("head_block_number");
const head_block_time = new Date(dynGlobalObject.get("time") + "+00:00");
const head_block_time = new Date(dynGlobalObject.get("time") + "Z");
const seconds_below = (head_block - block_number) * block_interval;
return new Date(head_block_time - seconds_below * 1000);
},
Expand Down
1 change: 0 additions & 1 deletion app/stores/BlockchainStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class BlockchainStore {
onGetLatest(payload) {
let {block, maxBlock} = payload;
if (typeof block.timestamp === "string") {
block.timestamp += "+00:00";
if (!/Z$/.test(block.timestamp)) {
block.timestamp += "Z";
}
Expand Down
12 changes: 9 additions & 3 deletions app/stores/MarketsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,14 @@ class MarketsStore {

let addTime = (time, i, bucketSize) => {
return new Date(time.getTime() + i * bucketSize * 1000);
}
};

for (let i = 0; i < this.priceHistory.length; i++) {
let current = this.priceHistory[i];
let date = new Date(current.key.open + "+00:00");
if (!/Z$/.test(current.key.open)) {
current.key.open += "Z";
}
let date = new Date(current.key.open);

if (this.quoteAsset.get("id") === current.key.quote) {
high = utils.get_asset_price(current.high_base, this.baseAsset, current.high_quote, this.quoteAsset);
Expand Down Expand Up @@ -946,7 +949,10 @@ class MarketsStore {
if (history.length) {
let first;
history.forEach((bucket, i) => {
let date = new Date(bucket.key.open + "+00:00").getTime();
if (!/Z$/.test(bucket.key.open)) {
bucket.key.open += "Z";
}
let date = new Date(bucket.key.open).getTime();
if (date > yesterday) {
noTrades = false;
if (!first) {
Expand Down

0 comments on commit 75e6a99

Please sign in to comment.