Merge pull request #3915 from mempool/mononaut/block-time-precision
More precise relative block times
This commit is contained in:
		
						commit
						8ad4b952ea
					
				@ -41,7 +41,7 @@
 | 
				
			|||||||
              <tr>
 | 
					              <tr>
 | 
				
			||||||
                <td i18n="block.timestamp">Timestamp</td>
 | 
					                <td i18n="block.timestamp">Timestamp</td>
 | 
				
			||||||
                <td>
 | 
					                <td>
 | 
				
			||||||
                  <app-timestamp [unixTime]="block.timestamp"></app-timestamp>
 | 
					                  <app-timestamp [unixTime]="block.timestamp" [precision]="1" minUnit="minute"></app-timestamp>
 | 
				
			||||||
                </td>
 | 
					                </td>
 | 
				
			||||||
              </tr>
 | 
					              </tr>
 | 
				
			||||||
              <tr>
 | 
					              <tr>
 | 
				
			||||||
 | 
				
			|||||||
@ -53,7 +53,7 @@
 | 
				
			|||||||
              <ng-template #transactionsPlural let-i i18n="shared.transaction-count.plural">{{ i }} transactions</ng-template>
 | 
					              <ng-template #transactionsPlural let-i i18n="shared.transaction-count.plural">{{ i }} transactions</ng-template>
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <div [attr.data-cy]="'bitcoin-block-' + offset + '-index-' + i + '-time'" class="time-difference">
 | 
					            <div [attr.data-cy]="'bitcoin-block-' + offset + '-index-' + i + '-time'" class="time-difference">
 | 
				
			||||||
              <app-time kind="since" [time]="block.timestamp" [fastRender]="true"></app-time></div>
 | 
					              <app-time kind="since" [time]="block.timestamp" [fastRender]="true" [precision]="1" minUnit="minute"></app-time></div>
 | 
				
			||||||
          </ng-container>
 | 
					          </ng-container>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <div class="animated" [class]="showMiningInfo ? 'show' : 'hide'" *ngIf="block.extras?.pool != undefined">
 | 
					        <div class="animated" [class]="showMiningInfo ? 'show' : 'hide'" *ngIf="block.extras?.pool != undefined">
 | 
				
			||||||
 | 
				
			|||||||
@ -29,10 +29,10 @@
 | 
				
			|||||||
              </div>
 | 
					              </div>
 | 
				
			||||||
              <div [attr.data-cy]="'mempool-block-' + i + '-time'" class="time-difference" *ngIf="projectedBlock.blockVSize <= stateService.blockVSize; else mergedBlock">
 | 
					              <div [attr.data-cy]="'mempool-block-' + i + '-time'" class="time-difference" *ngIf="projectedBlock.blockVSize <= stateService.blockVSize; else mergedBlock">
 | 
				
			||||||
                <ng-template [ngIf]="network === 'liquid' || network === 'liquidtestnet'" [ngIfElse]="timeDiffMainnet">
 | 
					                <ng-template [ngIf]="network === 'liquid' || network === 'liquidtestnet'" [ngIfElse]="timeDiffMainnet">
 | 
				
			||||||
                  <app-time kind="until" [time]="(1 * i) + now + 61000" [fastRender]="false" [fixedRender]="true"></app-time>
 | 
					                  <app-time kind="until" [time]="(1 * i) + now + 61000" [fastRender]="false" [fixedRender]="true" [precision]="1" minUnit="minute"></app-time>
 | 
				
			||||||
                </ng-template>
 | 
					                </ng-template>
 | 
				
			||||||
                <ng-template #timeDiffMainnet>
 | 
					                <ng-template #timeDiffMainnet>
 | 
				
			||||||
                  <app-time kind="until" [time]="da.timeAvg * (i + 1) + now + da.timeOffset" [fastRender]="false" [fixedRender]="true"></app-time>
 | 
					                  <app-time kind="until" [time]="da.timeAvg * (i + 1) + now + da.timeOffset" [fastRender]="false" [fixedRender]="true" [precision]="1" minUnit="minute"></app-time>
 | 
				
			||||||
                </ng-template>
 | 
					                </ng-template>
 | 
				
			||||||
              </div>
 | 
					              </div>
 | 
				
			||||||
              <ng-template #mergedBlock>
 | 
					              <ng-template #mergedBlock>
 | 
				
			||||||
 | 
				
			|||||||
@ -29,6 +29,7 @@ export class TimeComponent implements OnInit, OnChanges, OnDestroy {
 | 
				
			|||||||
  @Input() fixedRender = false;
 | 
					  @Input() fixedRender = false;
 | 
				
			||||||
  @Input() relative = false;
 | 
					  @Input() relative = false;
 | 
				
			||||||
  @Input() precision: number = 0;
 | 
					  @Input() precision: number = 0;
 | 
				
			||||||
 | 
					  @Input() minUnit: 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' = 'second';
 | 
				
			||||||
  @Input() fractionDigits: number = 0;
 | 
					  @Input() fractionDigits: number = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(
 | 
					  constructor(
 | 
				
			||||||
@ -96,10 +97,13 @@ export class TimeComponent implements OnInit, OnChanges, OnDestroy {
 | 
				
			|||||||
    for (const [index, unit] of this.units.entries()) {
 | 
					    for (const [index, unit] of this.units.entries()) {
 | 
				
			||||||
      let precisionUnit = this.units[Math.min(this.units.length - 1, index + this.precision)];
 | 
					      let precisionUnit = this.units[Math.min(this.units.length - 1, index + this.precision)];
 | 
				
			||||||
      counter = Math.floor(seconds / this.intervals[unit]);
 | 
					      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]) {
 | 
					      if (precisionCounter > this.precisionThresholds[precisionUnit]) {
 | 
				
			||||||
        precisionUnit = unit;
 | 
					        precisionUnit = unit;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      if (this.units.indexOf(precisionUnit) === this.units.indexOf(this.minUnit)) {
 | 
				
			||||||
 | 
					        counter = Math.max(1, counter);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      if (counter > 0) {
 | 
					      if (counter > 0) {
 | 
				
			||||||
        let rounded = Math.round(seconds / this.intervals[precisionUnit]);
 | 
					        let rounded = Math.round(seconds / this.intervals[precisionUnit]);
 | 
				
			||||||
        if (this.fractionDigits) {
 | 
					        if (this.fractionDigits) {
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,6 @@
 | 
				
			|||||||
<span *ngIf="seconds !== undefined">
 | 
					<span *ngIf="seconds !== undefined">
 | 
				
			||||||
  ‎{{ seconds * 1000 | date: customFormat ?? 'yyyy-MM-dd HH:mm' }}
 | 
					  ‎{{ seconds * 1000 | date: customFormat ?? 'yyyy-MM-dd HH:mm' }}
 | 
				
			||||||
  <div class="lg-inline" *ngIf="!hideTimeSince">
 | 
					  <div class="lg-inline" *ngIf="!hideTimeSince">
 | 
				
			||||||
    <i class="symbol">(<app-time kind="since" [time]="seconds" [fastRender]="true"></app-time>)</i>
 | 
					    <i class="symbol">(<app-time kind="since" [time]="seconds" [fastRender]="true" [precision]="precision" [minUnit]="minUnit"></app-time>)</i>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
</span>
 | 
					</span>
 | 
				
			||||||
 | 
				
			|||||||
@ -11,6 +11,8 @@ export class TimestampComponent implements OnChanges {
 | 
				
			|||||||
  @Input() dateString: string;
 | 
					  @Input() dateString: string;
 | 
				
			||||||
  @Input() customFormat: string;
 | 
					  @Input() customFormat: string;
 | 
				
			||||||
  @Input() hideTimeSince: boolean = false;
 | 
					  @Input() hideTimeSince: boolean = false;
 | 
				
			||||||
 | 
					  @Input() precision: number = 0;
 | 
				
			||||||
 | 
					  @Input() minUnit: 'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' = 'second';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  seconds: number | undefined = undefined;
 | 
					  seconds: number | undefined = undefined;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user