From 850752e0eafce78eb883cb41e0580eaacafcbe6e Mon Sep 17 00:00:00 2001 From: Mononaut Date: Thu, 29 Jun 2023 10:06:03 -0400 Subject: [PATCH] More precise relative block times --- .../blockchain-blocks/blockchain-blocks.component.html | 2 +- .../components/mempool-blocks/mempool-blocks.component.html | 4 ++-- frontend/src/app/components/time/time.component.ts | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.html b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.html index 0c22cf391..f630ab3c5 100644 --- a/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.html +++ b/frontend/src/app/components/blockchain-blocks/blockchain-blocks.component.html @@ -53,7 +53,7 @@ {{ i }} transactions
-
+
diff --git a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html index 2b4dd470e..5f09e0267 100644 --- a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html +++ b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html @@ -29,10 +29,10 @@
- + - +
diff --git a/frontend/src/app/components/time/time.component.ts b/frontend/src/app/components/time/time.component.ts index f2b220d39..2febf6238 100644 --- a/frontend/src/app/components/time/time.component.ts +++ b/frontend/src/app/components/time/time.component.ts @@ -29,6 +29,7 @@ export class TimeComponent implements OnInit, OnChanges, OnDestroy { @Input() fixedRender = false; @Input() relative = false; @Input() precision: number = 0; + @Input() minUnit: 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' = 'second'; @Input() fractionDigits: number = 0; constructor( @@ -96,10 +97,13 @@ export class TimeComponent implements OnInit, OnChanges, OnDestroy { for (const [index, unit] of this.units.entries()) { let precisionUnit = this.units[Math.min(this.units.length - 1, index + this.precision)]; counter = Math.floor(seconds / this.intervals[unit]); - const precisionCounter = Math.floor(seconds / this.intervals[precisionUnit]); + const precisionCounter = Math.round(seconds / this.intervals[precisionUnit]); if (precisionCounter > this.precisionThresholds[precisionUnit]) { precisionUnit = unit; } + if (this.units.indexOf(precisionUnit) === this.units.indexOf(this.minUnit)) { + counter = Math.max(1, counter); + } if (counter > 0) { let rounded = Math.round(seconds / this.intervals[precisionUnit]); if (this.fractionDigits) {