From 5b84fe838ebcc8bfe18b117e8130517a9e30b7ec Mon Sep 17 00:00:00 2001 From: Vlad Kostyanetsky Date: Fri, 8 Mar 2024 18:56:13 +0400 Subject: [PATCH] Fixed future fast rendering --- CHANGELOG.md | 1 + src/codeblocks/fastimer.ts | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f267e6..a02529c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Made the code block more compact. * Fixed verb forms in the code block. +* Fixed a few bugs in code block rendering for a upcoming fast. ## 1.2.0 - 2024-03-05 diff --git a/src/codeblocks/fastimer.ts b/src/codeblocks/fastimer.ts index 7dd2133..ef016a0 100644 --- a/src/codeblocks/fastimer.ts +++ b/src/codeblocks/fastimer.ts @@ -12,6 +12,7 @@ import { FastStatus } from '../types' import { DESTRUCTION } from 'dns'; +import { posix } from 'path'; interface FastingZone { startTimestamp: number; @@ -150,7 +151,7 @@ export default class FastimerCodeBlock { private static async addFastProgressBar(lines: string[], fast: Fast, endTimestamp: number) { - let seconds_now = (endTimestamp - fast.startTimestamp) + let seconds_now = endTimestamp > fast.startTimestamp ? endTimestamp - fast.startTimestamp : 0 let seconds_all = (fast.plannedEndTimestamp - fast.startTimestamp) let percent = seconds_now / seconds_all * 100 @@ -180,15 +181,25 @@ export default class FastimerCodeBlock { let timestamp1 = fast.startTimestamp let timestamp2 = fast.currentEndTimestamp == 0 ? endTimestamp : fast.currentEndTimestamp - - let difference = DateTime.timestampsDifference(timestamp1, timestamp2) + + let difference = "" let postfix = "" - if (endTimestamp <= fast.plannedEndTimestamp) { - postfix = `remaining: **${DateTime.timestampsDifference(endTimestamp, fast.plannedEndTimestamp)}**` + if (timestamp1 <= timestamp2) { + + difference = DateTime.timestampsDifference(timestamp1, timestamp2) + postfix = "" + + if (endTimestamp <= fast.plannedEndTimestamp) { + postfix = `remaining: **${DateTime.timestampsDifference(endTimestamp, fast.plannedEndTimestamp)}**` + } + else { + postfix = `extra: **${DateTime.timestampsDifference(fast.plannedEndTimestamp, endTimestamp)}**` + } } else { - postfix = `extra: **${DateTime.timestampsDifference(fast.plannedEndTimestamp, endTimestamp)}**` + difference = "0h 0m" + postfix = `remaining: **${fast.plannedLengthInHours}h**` } lines.push(`> ${prefix}Duration: **${difference}** (${postfix})`)