Skip to content

Commit

Permalink
Fixed future fast rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
vkostyanetsky committed Mar 8, 2024
1 parent 7d1dca8 commit 5b84fe8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 17 additions & 6 deletions src/codeblocks/fastimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
FastStatus
} from '../types'
import { DESTRUCTION } from 'dns';
import { posix } from 'path';

interface FastingZone {
startTimestamp: number;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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})`)
Expand Down

0 comments on commit 5b84fe8

Please sign in to comment.