Skip to content
Permalink
Browse files

Merge pull request #241 from AnnanFay/economy_date_fix

Economy date fix
  • Loading branch information...
Manuel-777 committed Mar 31, 2019
2 parents 79123f5 + 3861371 commit 76ec17ba753bd57cb1a1cb0099541ae8eeb57b4f

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -45,6 +45,7 @@
"async": "^2.6.1",
"chart.js": "^2.7.3",
"conf": "^2.2.0",
"date-fns": "^1.30.1",
"electron-debug": "^1.5.0",
"electron-transparency-mouse-fix": "^1.0.0-beta",
"electron-updater": "^4.0.8",
@@ -55,7 +56,8 @@
"lodash.transform": "^4.6.0",
"mathjs": "^5.5.0",
"qs": "^6.6.0",
"queue": "^4.5.1"
"queue": "^4.5.1",
"time-elements": "^2.0.0"
},
"devDependencies": {
"acorn": "^6.1.1",
@@ -831,11 +831,10 @@ function addCardTile(grpId, indent, quantity, element) {
return false;
}


/**
* Creates a select box
* This is a "fixed" version of SelectAdd and should replace it.
**/
**/
function createSelect(parent, options, current, callback, divClass) {
let selectContainer = createDivision(["select_container", divClass]);
selectContainer.id = divClass;
@@ -991,7 +990,7 @@ function addCardHover(element, card) {
mainImageElement.addEventListener("load", evt => {
$$(".loader").forEach(el => (el.style.opacity = 0));
});

// show card quantity
if (renderer == 0) {
attachOwnerhipStars(card, $$(".hover_card_quantity")[0]);
@@ -2155,12 +2154,12 @@ function convert_deck_from_v3(deck) {
if (key === "mainDeck" || key === "sideboard") {
let ret = [];
for (let i = 0; i < value.length; i += 2) {
ret.push({ id : value[i], quantity : value[i + 1] });
ret.push({ id: value[i], quantity: value[i + 1] });
}
return ret;
}
return value;
})
});
}

//
@@ -2255,6 +2254,10 @@ function daysPast(_date) {
);
}

function niceDateFormat(date) {
return `<relative-time datetime="${date.toISOString()}">${date.toString()}</relative-time>`;
}

//
function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, "g"), replace);
@@ -0,0 +1,64 @@
// Utility functions that belong only to background

const parse = require("date-fns").parse;

//
function parseWotcTime(str) {
try {
let datePart = str.split(" ")[0];
let timePart = str.split(" ")[1];
let midnight = str.split(" ")[2];

datePart = datePart.split("/");
timePart = timePart.split(":");

timePart.forEach(function(s, index) {
timePart[index] = parseInt(s);
});
datePart.forEach(function(s, index) {
datePart[index] = parseInt(s);
});

if (midnight == "PM" && timePart[0] != 12) {
timePart[0] += 12;
}
if (midnight == "AM" && timePart[0] == 12) {
timePart[0] = 0;
}

var date = new Date(
datePart[2],
datePart[0] - 1,
datePart[1],
timePart[0],
timePart[1],
timePart[2]
);
return date;
} catch (e) {
return new Date();
}
}

// throws an error if it fails
function parseWotcTime2(dateStr) {
// example input: 1/23/2019 8:42:41 PM
return parse(dateStr, "M/d/yyyy h:mm:ss a..aaa", new Date());
}

function normaliseFields(iterator) {
if (typeof iterator == "object") {
return transform(iterator, function(result, value, key) {
let nkey =
typeof key == "string" ? key.replace(/List$/, "").toLowerCase() : key;
result[nkey] = normaliseFields(value);
});
}
return iterator;
}

module.exports = {
parseWotcTime: parseWotcTime,
parseWotcTime2: parseWotcTime2,
normaliseFields: normaliseFields
};
Oops, something went wrong.

0 comments on commit 76ec17b

Please sign in to comment.
You can’t perform that action at this time.