From 0ffbf1c1a9a89aef2208eecaf99889759241a4f6 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Tue, 31 Mar 2020 12:37:17 +0300 Subject: [PATCH] Add time format --- package-lock.json | 12 ++++++++++++ package.json | 2 ++ src/Action/UpgradeBuildingAction.ts | 2 +- src/Scheduler.ts | 2 +- src/Storage/TaskQueue.ts | 4 ++-- src/TaskQueueRenderer.ts | 8 +++++++- 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5fd683e..26dbc69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -330,6 +330,12 @@ "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "dev": true }, + "@types/dateformat": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/dateformat/-/dateformat-3.0.1.tgz", + "integrity": "sha512-KlPPdikagvL6ELjWsljbyDIPzNCeliYkqRpI+zea99vBBbCIA5JNshZAwQKTON139c87y9qvTFVgkFd14rtS4g==", + "dev": true + }, "@types/jquery": { "version": "3.3.34", "resolved": "https://registry.npmjs.org/@types/jquery/-/jquery-3.3.34.tgz", @@ -1978,6 +1984,12 @@ "integrity": "sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk=", "dev": true }, + "dateformat": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz", + "integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==", + "dev": true + }, "debug": { "version": "3.2.6", "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", diff --git a/package.json b/package.json index 3572a83..e4bf994 100644 --- a/package.json +++ b/package.json @@ -22,12 +22,14 @@ }, "devDependencies": { "@types/chai": "^4.2.11", + "@types/dateformat": "^3.0.1", "@types/jquery": "^3.3.34", "@types/mocha": "^7.0.2", "@types/nanoid": "^2.1.0", "@types/node": "^13.9.4", "@types/url-parse": "^1.4.3", "chai": "^4.2.0", + "dateformat": "^3.0.3", "jquery": "^3.4.1", "mocha": "^7.1.1", "mocha-junit-reporter": "^1.23.3", diff --git a/src/Action/UpgradeBuildingAction.ts b/src/Action/UpgradeBuildingAction.ts index ac13826..70540c5 100644 --- a/src/Action/UpgradeBuildingAction.ts +++ b/src/Action/UpgradeBuildingAction.ts @@ -21,7 +21,7 @@ export default class UpgradeBuildingAction extends ActionController { this.scheduler.completeTask(task.id); btn.trigger('click'); } else { - throw new TryLaterError(60, 'No upgrade button, try later'); + throw new TryLaterError(5 * 60, 'No upgrade button, try later'); } return null; } diff --git a/src/Scheduler.ts b/src/Scheduler.ts index ba69ec0..9ff5578 100644 --- a/src/Scheduler.ts +++ b/src/Scheduler.ts @@ -148,7 +148,7 @@ export default class Scheduler { if (e instanceof TryLaterError) { console.warn('TRY', task.id, 'AFTER', e.seconds); this.actionQueue.clear(); - this.taskQueue.postpone(task.id, e.seconds); + this.taskQueue.postpone(task.id, timestamp() + e.seconds); this.nextSleepLong(); } } diff --git a/src/Storage/TaskQueue.ts b/src/Storage/TaskQueue.ts index 6102d5a..e8dd552 100644 --- a/src/Storage/TaskQueue.ts +++ b/src/Storage/TaskQueue.ts @@ -54,11 +54,11 @@ export class TaskQueue { this.flushItems(items); } - postpone(id: TaskId, deltaSeconds: number) { + postpone(id: TaskId, newTs: number) { const [task, items] = this.shiftTask(id); if (task) { this.log('POSTPONE', task); - items.push(task.withTime(task.ts + deltaSeconds)); + items.push(task.withTime(newTs)); } this.flushItems(items); } diff --git a/src/TaskQueueRenderer.ts b/src/TaskQueueRenderer.ts index a35a2da..12c31f9 100644 --- a/src/TaskQueueRenderer.ts +++ b/src/TaskQueueRenderer.ts @@ -1,8 +1,14 @@ import { TaskList } from './Storage/TaskQueue'; import { uniqId } from './utils'; +import dateFormat = require('dateformat'); const ID = uniqId(); +function formatDate(ts: number) { + const d = new Date(ts * 1000); + return dateFormat(d, 'HH:MM:ss'); +} + export default class TaskQueueRenderer { render(tasks: TaskList) { const ul = jQuery('') @@ -19,7 +25,7 @@ export default class TaskQueueRenderer { tasks.forEach(task => { ul.append( jQuery('
  • ').text( - task.ts + + formatDate(task.ts) + ' ' + task.cmd.name + ' ' +