Skip to content

Commit 4d52759

Browse files
use user time zone when calculating time left
1 parent 064aeb0 commit 4d52759

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"form-data": "^2.3.3",
2121
"graphql-request": "^1.8.2",
2222
"lodash.debounce": "^4.0.8",
23+
"moment-timezone": "^0.5.25",
2324
"vue": "^2.5.22"
2425
},
2526
"devDependencies": {

src/app.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const debug = require('electron-debug');
1414
const ipc = require('electron-better-ipc');
1515
const logger = require('electron-timber');
1616
const { autoUpdater } = require('electron-updater');
17+
const moment = require('moment');
1718

1819
debug();
1920

@@ -439,9 +440,7 @@ app.on('ready', () => {
439440

440441
async function setAuthorizationCode(event, authorization_code) {
441442
try {
442-
console.log('getting access token');
443443
const oauth = await wip.getAccessToken(authorization_code);
444-
console.log(oauth);
445444
store.set('oauth', oauth);
446445
wip.setApiKey(store.get('oauth.access_token'));
447446
await requestViewerData();
@@ -458,20 +457,15 @@ app.on('ready', () => {
458457
}
459458

460459
function timeLeft() {
461-
const now = new Date();
460+
moment.tz.setDefault(store.get('viewer.time_zone'));
462461

463-
let midnight = new Date(now.valueOf());
464-
midnight.setHours(24);
465-
midnight.setMinutes(0 - now.getTimezoneOffset());
466-
midnight.setSeconds(0);
467-
midnight.setMilliseconds(0);
462+
var now = moment();
463+
var midnight = now.clone().endOf('day');
468464

469-
const timeDifference = midnight.getTime() - now.getTime();
465+
const minutes = Math.abs(now.diff(midnight, 'minutes'));
466+
const hours = Math.abs(now.diff(midnight, 'hours'));
470467

471-
const minutes = Math.floor(timeDifference / 60000);
472-
const hours = Math.floor(minutes / 60);
473-
474-
let output = `${hours % 24}`;
468+
let output = hours;
475469
output += hours % 24 == 1 ? ` hour` : ` hours`;
476470
output += `, ${minutes % 60}`;
477471
output += minutes % 60 == 1 ? ` minute` : ` minutes`;

src/wip.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ function viewer(options = {}) {
5656
best_streak
5757
completed_todos_count
5858
streaking
59+
time_zone
5960
products {
6061
name
6162
url
@@ -71,6 +72,7 @@ function viewer(options = {}) {
7172
currentStreak: json.viewer.streak,
7273
bestStreak: json.viewer.best_streak,
7374
streaking: json.viewer.streaking,
75+
time_zone: json.viewer.time_zone,
7476
products: json.viewer.products,
7577
};
7678
return resolve(data);

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,6 +2634,13 @@ mkdirp@0.5.1, mkdirp@^0.5.0, mkdirp@^0.5.1:
26342634
dependencies:
26352635
minimist "0.0.8"
26362636

2637+
moment-timezone@^0.5.25:
2638+
version "0.5.25"
2639+
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.25.tgz#a11bfa2f74e088327f2cd4c08b3e7bdf55957810"
2640+
integrity sha512-DgEaTyN/z0HFaVcVbSyVCUU6HeFdnNC3vE4c9cgu2dgMTvjBUBdBzWfasTBmAW45u5OIMeCJtU8yNjM22DHucw==
2641+
dependencies:
2642+
moment ">= 2.9.0"
2643+
26372644
moment-timezone@^0.5.x:
26382645
version "0.5.23"
26392646
resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.23.tgz#7cbb00db2c14c71b19303cb47b0fb0a6d8651463"

0 commit comments

Comments
 (0)