Skip to content

Commit

Permalink
fix: steel path times
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Mar 23, 2021
1 parent bd17032 commit ccd66fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ warframe-worldstate-parser-*.tgz

# Test debugging files
data.*.json

# unwanted configs from plugins
.jshintignore
.jshintrc
41 changes: 23 additions & 18 deletions lib/SteelPathOffering.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
'use strict';

const endOfWeek = () => {
const expiry = new Date();
expiry.setUTCHours(23);
expiry.setUTCMinutes(59);
expiry.setUTCSeconds(59);
expiry.setUTCDate(expiry.getUTCDate() + (7 - expiry.getUTCDay()));
return expiry;
};
const monday = 1;

const startOfWeek = () => {
const activation = new Date();
activation.setUTCHours(0);
activation.setUTCMinutes(0);
activation.setUTCSeconds(0);
activation.setUTCDate(activation.getUTCDate() - (activation.getUTCDay() - 1));
return activation;
};
function getFirstDayOfWeek() {
const resultDate = new Date();
const offset = resultDate.getUTCDay() === 0 ? 6 : resultDate.getUTCDay() - monday;
resultDate.setUTCDate(resultDate.getUTCDate() - offset);
resultDate.setUTCHours(0);
resultDate.setUTCMinutes(0);
resultDate.setUTCSeconds(0);
resultDate.setUTCMilliseconds(0);
return resultDate;
}

function getLastDayOfWeek() {
const last = new Date(getFirstDayOfWeek());
last.setUTCDate(last.getUTCDate() + 4);
last.setUTCHours(59);
last.setUTCMinutes(59);
last.setUTCSeconds(59);
last.setUTCMilliseconds(0);
return last;
}

/**
* Start of Steel Path cycle calculations
Expand Down Expand Up @@ -49,9 +54,9 @@ module.exports = class SteelPathOffering {

this.currentReward = rewards[ind];

this.activation = startOfWeek();
this.activation = getFirstDayOfWeek();

this.expiry = endOfWeek();
this.expiry = getLastDayOfWeek();

this.remaining = timeDate.timeDeltaToString(this.expiry.getTime() - Date.now());

Expand Down

0 comments on commit ccd66fb

Please sign in to comment.