From 3f89b2aa77a49cd64f8691f41800a73ca9874528 Mon Sep 17 00:00:00 2001 From: Senyoret1 <34079003+Senyoret1@users.noreply.github.com> Date: Mon, 21 May 2018 13:48:43 -0400 Subject: [PATCH] Change timestamps format and timezone --- src/app/app.module.ts | 6 +++++- .../address-detail.component.html | 2 +- .../block-details/block-details.component.html | 2 +- .../pages/blocks/blocks.component.html | 2 +- .../transaction-detail.component.html | 4 ++-- .../unconfirmed-transactions.component.html | 6 +++--- .../unspent-outputs.component.html | 2 +- src/app/pipes/explorer-date.pipe.spec.ts | 8 ++++++++ src/app/pipes/explorer-date.pipe.ts | 17 +++++++++++++++++ 9 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 src/app/pipes/explorer-date.pipe.spec.ts create mode 100644 src/app/pipes/explorer-date.pipe.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 6cf468bc..66263c26 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -27,6 +27,8 @@ import { TranslateModule, TranslateLoader } from '@ngx-translate/core'; import { AppTranslateLoader } from 'app/app.translate-loader'; import { GenericHeaderComponent } from 'app/components/layout/generic-header/generic-header.component'; import { GenericFooterComponent } from 'app/components/layout/generic-footer/generic-footer.component'; +import { ExplorerDatePipe } from 'app/pipes/explorer-date.pipe'; +import { DatePipe } from '@angular/common'; const ROUTES = [ @@ -93,6 +95,7 @@ const ROUTES = [ RichlistComponent, UnspentOutputsComponent, CopyButtonComponent, + ExplorerDatePipe, ], imports: [ BrowserModule, @@ -110,7 +113,8 @@ const ROUTES = [ providers: [ ApiService, ExplorerService, - {provide: RouteReuseStrategy, useClass: AppReuseStrategy} + {provide: RouteReuseStrategy, useClass: AppReuseStrategy}, + DatePipe, ], bootstrap: [AppComponent] }) diff --git a/src/app/components/pages/address-detail/address-detail.component.html b/src/app/components/pages/address-detail/address-detail.component.html index a0b16568..cd122a37 100644 --- a/src/app/components/pages/address-detail/address-detail.component.html +++ b/src/app/components/pages/address-detail/address-detail.component.html @@ -38,7 +38,7 @@

{{ 'addressDetail.title' | translate }}

-
{{ 'txBoxes.date' | translate }}:
{{ transaction ? (transaction.timestamp * 1000 | date: 'short') : loadingMsg }}
+
{{ 'txBoxes.date' | translate }}:
{{ transaction ? (transaction.timestamp | explorerDate) : loadingMsg }}
diff --git a/src/app/components/pages/block-details/block-details.component.html b/src/app/components/pages/block-details/block-details.component.html index 978a35a3..46835131 100644 --- a/src/app/components/pages/block-details/block-details.component.html +++ b/src/app/components/pages/block-details/block-details.component.html @@ -2,7 +2,7 @@

{{ 'blockDetails.title' | translate }}

{{ 'blockDetails.height' | translate }}
{{ block ? block.id : loadingMsg }}
-
{{ 'blockDetails.timestamp' | translate }}
{{ block ? ((block.timestamp * 1000) | date: 'short') : loadingMsg }}
+
{{ 'blockDetails.timestamp' | translate }}
{{ block ? (block.timestamp | explorerDate) : loadingMsg }}
{{ 'blockDetails.size' | translate }}
{{ block ? (block.size | number) + ' bytes' : loadingMsg }}
{{ 'blockDetails.hash' | translate }}
{{ block.hash }} {{ loadingMsg }}
{{ 'blockDetails.parentHash' | translate }}
{{ block.parent_hash }} {{ 'blockDetails.withoutParent' | translate }} {{ loadingMsg }}
diff --git a/src/app/components/pages/blocks/blocks.component.html b/src/app/components/pages/blocks/blocks.component.html index 560193c0..356291b4 100644 --- a/src/app/components/pages/blocks/blocks.component.html +++ b/src/app/components/pages/blocks/blocks.component.html @@ -34,7 +34,7 @@

{{ 'blocks.blocksTitle' | translate }}

-
{{ block.timestamp * 1000 | date:'short' }}
+
{{ block.timestamp | explorerDate }}
{{ block.id }}
{{ block.transactions.length }}
{{ block.hash }}
diff --git a/src/app/components/pages/transaction-detail/transaction-detail.component.html b/src/app/components/pages/transaction-detail/transaction-detail.component.html index f5d15ca3..d24cf005 100644 --- a/src/app/components/pages/transaction-detail/transaction-detail.component.html +++ b/src/app/components/pages/transaction-detail/transaction-detail.component.html @@ -2,7 +2,7 @@

{{ 'transactionDetail.title' | translate }}

{{ 'transactionDetail.status' | translate }}
{{ transaction ? (transaction.status ? ('transactionDetail.confirmed' | translate) : ('transactionDetail.unconfirmed' | translate)) : loadingMsg }}
-
{{ 'transactionDetail.timestamp' | translate }}
{{ transaction ? (transaction.timestamp * 1000 | date: 'short') : loadingMsg }}
+
{{ 'transactionDetail.timestamp' | translate }}
{{ transaction ? (transaction.timestamp | explorerDate) : loadingMsg }}
{{ 'transactionDetail.size' | translate }}
{{ transaction ? (transaction.length | number) + ' bytes' : loadingMsg }}
{{ 'transactionDetail.block' | translate }}
{{ transaction ? transaction.block : loadingMsg }}
@@ -27,7 +27,7 @@

{{ 'transactionDetail.title' | translate }}

{{ loadingMsg }}
-
{{ 'txBoxes.date' | translate }}:
{{ transaction ? (transaction.timestamp * 1000 | date: 'short') : loadingMsg }}
+
{{ 'txBoxes.date' | translate }}:
{{ transaction ? (transaction.timestamp | explorerDate) : loadingMsg }}
diff --git a/src/app/components/pages/unconfirmed-transactions/unconfirmed-transactions.component.html b/src/app/components/pages/unconfirmed-transactions/unconfirmed-transactions.component.html index a3cf77bc..3b415540 100644 --- a/src/app/components/pages/unconfirmed-transactions/unconfirmed-transactions.component.html +++ b/src/app/components/pages/unconfirmed-transactions/unconfirmed-transactions.component.html @@ -3,8 +3,8 @@

{{ 'unconfirmedTx.title' | translate }}

{{ 'unconfirmedTx.quantity' | translate }}
{{ transactions ? (transactions.length > 0 ? transactions.length : ('unconfirmedTx.withoutTransactions' | translate)) : loadingMsg }}
{{ 'unconfirmedTx.size' | translate }}
{{ transactions ? (transactions.length > 0 ? (totalSize | number) + ' bytes' : ('unconfirmedTx.withoutTransactions' | translate)) : loadingMsg }}
-
{{ 'unconfirmedTx.newest' | translate }}
{{ transactions ? (transactions.length > 0 ? (mostRecent | date: 'short') : ('unconfirmedTx.withoutTransactions' | translate)) : loadingMsg }}
-
{{ 'unconfirmedTx.oldest' | translate }}
{{ transactions ? (transactions.length > 0 ? (leastRecent | date: 'short') : ('unconfirmedTx.withoutTransactions' | translate)) : loadingMsg }}
+
{{ 'unconfirmedTx.newest' | translate }}
{{ transactions ? (transactions.length > 0 ? (mostRecent | explorerDate:false) : ('unconfirmedTx.withoutTransactions' | translate)) : loadingMsg }}
+
{{ 'unconfirmedTx.oldest' | translate }}
{{ transactions ? (transactions.length > 0 ? (leastRecent | explorerDate:false) : ('unconfirmedTx.withoutTransactions' | translate)) : loadingMsg }}
@@ -27,7 +27,7 @@

{{ 'unconfirmedTx.title' | translate }}

{{ loadingMsg }}
-
{{ 'txBoxes.firstSeen' | translate }}:
{{ transaction ? (transaction.timestamp * 1000 | date: 'short') : loadingMsg }}
+
{{ 'txBoxes.firstSeen' | translate }}:
{{ transaction ? (transaction.timestamp | explorerDate:false) : loadingMsg }}
diff --git a/src/app/components/pages/unspent-outputs/unspent-outputs.component.html b/src/app/components/pages/unspent-outputs/unspent-outputs.component.html index 71838d2c..eae8922c 100644 --- a/src/app/components/pages/unspent-outputs/unspent-outputs.component.html +++ b/src/app/components/pages/unspent-outputs/unspent-outputs.component.html @@ -26,7 +26,7 @@

{{ 'unspentOutputs.title' | translate }}

{{ output.src_tx }}
-
{{ 'unspentOutputs.date' | translate }}:
{{ output.time * 1000 | date: 'short' }}
+
{{ 'unspentOutputs.date' | translate }}:
{{ output.time | explorerDate }}
diff --git a/src/app/pipes/explorer-date.pipe.spec.ts b/src/app/pipes/explorer-date.pipe.spec.ts new file mode 100644 index 00000000..71efc677 --- /dev/null +++ b/src/app/pipes/explorer-date.pipe.spec.ts @@ -0,0 +1,8 @@ +import { ExplorerDatePipe } from "app/pipes/explorer-date.pipe"; + +describe('ExplorerDatePipe', () => { + it('create an instance', () => { + const pipe = new ExplorerDatePipe(null); + expect(pipe).toBeTruthy(); + }); +}); diff --git a/src/app/pipes/explorer-date.pipe.ts b/src/app/pipes/explorer-date.pipe.ts new file mode 100644 index 00000000..a0815ee6 --- /dev/null +++ b/src/app/pipes/explorer-date.pipe.ts @@ -0,0 +1,17 @@ +import { Pipe, PipeTransform } from '@angular/core'; +import { Transaction } from '../app.datatypes'; +import { DatePipe } from '@angular/common'; + +@Pipe({ + name: 'explorerDate', +}) +export class ExplorerDatePipe implements PipeTransform { + + constructor(private datePipe: DatePipe) { + } + + transform(value: any, unixDateInSeconds = true): string { + value = unixDateInSeconds ? value * 1000 : value; + return this.datePipe.transform(value, 'yyyy-MM-dd HH:mm:ss', 'UTC'); + } +} \ No newline at end of file