File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed
modules/shared/pipes/substract-date Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ import { CreateProjectTypeComponent } from './modules/customer-management/compon
56
56
import { CustomerEffects } from './modules/customer-management/store/customer-management.effects' ;
57
57
import { EntryEffects } from './modules/time-clock/store/entry.effects' ;
58
58
import { InjectTokenInterceptor } from './modules/shared/interceptors/inject.token.interceptor' ;
59
+ import { SubstractDatePipe } from './modules/shared/pipes/substract-date/substract-date.pipe' ;
59
60
60
61
@NgModule ( {
61
62
declarations : [
@@ -90,6 +91,7 @@ import { InjectTokenInterceptor } from './modules/shared/interceptors/inject.tok
90
91
ProjectTypeListComponent ,
91
92
CreateProjectTypeComponent ,
92
93
EntryFieldsComponent ,
94
+ SubstractDatePipe ,
93
95
] ,
94
96
imports : [
95
97
CommonModule ,
Original file line number Diff line number Diff line change
1
+ import { SubstractDatePipe } from './substract-date.pipe' ;
2
+
3
+ describe ( 'SubstractDatePipe' , ( ) => {
4
+ it ( 'create an instance' , ( ) => {
5
+ const pipe = new SubstractDatePipe ( ) ;
6
+ expect ( pipe ) . toBeTruthy ( ) ;
7
+ } ) ;
8
+
9
+ it ( 'returns the date diff' , ( ) => {
10
+ const fromDate = new Date ( '2011-04-11T10:20:30Z' ) ;
11
+ const substractDate = new Date ( '2011-04-11T08:00:30Z' ) ;
12
+
13
+ const diff = new SubstractDatePipe ( ) . transform ( fromDate , substractDate ) ;
14
+
15
+ expect ( diff ) . toBe ( '02:20' ) ;
16
+ } ) ;
17
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { Pipe , PipeTransform } from '@angular/core' ;
2
+
3
+ @Pipe ( {
4
+ name : 'substractDate'
5
+ } )
6
+ export class SubstractDatePipe implements PipeTransform {
7
+
8
+ transform ( fromDate : Date , substractDate : Date ) : string {
9
+ const difference = fromDate . valueOf ( ) - substractDate . valueOf ( ) ;
10
+
11
+ const minutes = Math . floor ( ( difference / ( 1000 * 60 ) ) % 60 ) ;
12
+ const hours = Math . floor ( difference / ( 1000 * 60 * 60 ) % 24 ) ;
13
+
14
+ return `${ this . formatTime ( hours ) } :${ this . formatTime ( minutes ) } ` ;
15
+ }
16
+
17
+ formatTime ( time : number ) : string {
18
+ const formattedTime = ( time < 10 ) ? '0' + time : time . toString ( ) ;
19
+ return formattedTime ;
20
+ }
21
+
22
+ }
You can’t perform that action at this time.
0 commit comments