Skip to content
Permalink
Browse files

Days difference instead of 24hr periods in economy

Fixes #251 and #149
  • Loading branch information...
Manuel-777 committed Apr 9, 2019
1 parent 25aaec7 commit afb924f14bce7ac5aa9ffb91b5ff22fe458cc8d5
Showing with 23 additions and 8 deletions.
  1. +10 −0 shared/util.js
  2. +12 −7 window_main/economy.js
  3. +1 −1 window_main/index.css
@@ -2308,6 +2308,16 @@ function niceDateFormat(date) {
return `<relative-time datetime="${date.toISOString()}">${date.toString()}</relative-time>`;
}

function localDateFormat(date) {
return `<local-time datetime="${date.toISOString()}"
month="short"
day="numeric"
hour="numeric"
minute="numeric">
${date.toString()}
</local-time>`;
}

//
function replaceAll(str, find, replace) {
return str.replace(new RegExp(find, "g"), replace);
@@ -1,8 +1,8 @@
/*
global
$,
daysPast,
get_colation_set,
localDateFormat,
getReadableEvent,
setsList,
addCardHover,
@@ -22,6 +22,8 @@ var filterEconomy = "All";
var daysago = 0;
var dayList = [];

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

class economyDay {
constructor(goldEarned = 0, gemsEarned = 0, goldSpent = 0, gemsSpent = 0) {
this.goldEarned = goldEarned;
@@ -93,7 +95,10 @@ function openEconomyTab(loadMore) {
if (change == undefined) continue;

// print out daily summaries but no sub-events
if (filterEconomy === "Day Summaries" && daysago != daysPast(change.date)) {
if (
filterEconomy === "Day Summaries" &&
daysago != differenceInCalendarDays(new Date(), change.date)
) {
mainDiv.appendChild(createDayHeader(change));
loadEnd++;
continue;
@@ -104,7 +109,7 @@ function openEconomyTab(loadMore) {
continue;
}

if (daysago != daysPast(change.date)) {
if (daysago != differenceInCalendarDays(new Date(), change.date)) {
mainDiv.appendChild(createDayHeader(change));
}

@@ -132,7 +137,7 @@ function openEconomyTab(loadMore) {
}

function createDayHeader(change) {
daysago = daysPast(change.date);
daysago = differenceInCalendarDays(new Date(), change.date);
let div = createDivision(["economy_title", "flex_item"]);

let flexLeft = createDivision(["flex_item"]);
@@ -507,7 +512,7 @@ function createChangeRow(change, economyId) {
)
);

var niceDate = niceDateFormat(new Date(change.date));
var niceDate = localDateFormat(new Date(change.date));
flexTop.appendChild(createDivision(["list_economy_time"], niceDate));

var flexLeft = createDivision(["flex_item"]);
@@ -555,8 +560,8 @@ function createEconomyUI(mainDiv) {
else dayList[daysago].goldSpent += Math.abs(change.delta.goldDelta);
}

if (daysago != daysPast(change.date)) {
daysago = daysPast(change.date);
if (daysago != differenceInCalendarDays(new Date(), change.date)) {
daysago = differenceInCalendarDays(new Date(), change.date);
dayList[daysago] = new economyDay();
}
}
@@ -2,7 +2,7 @@ span i {
margin-left: 4px;
}

relative-time {
relative-time, local-time {
margin-right: 8px;
margin-left: 8px;
font-size: 16px;

0 comments on commit afb924f

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