Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { CreateProjectTypeComponent } from './modules/customer-management/compon
import { CustomerEffects } from './modules/customer-management/store/customer-management.effects';
import { EntryEffects } from './modules/time-clock/store/entry.effects';
import { InjectTokenInterceptor } from './modules/shared/interceptors/inject.token.interceptor';
import { SubstractDatePipe } from './modules/shared/pipes/substract-date/substract-date.pipe';

@NgModule({
declarations: [
Expand Down Expand Up @@ -90,6 +91,7 @@ import { InjectTokenInterceptor } from './modules/shared/interceptors/inject.tok
ProjectTypeListComponent,
CreateProjectTypeComponent,
EntryFieldsComponent,
SubstractDatePipe,
],
imports: [
CommonModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { SubstractDatePipe } from './substract-date.pipe';

describe('SubstractDatePipe', () => {
it('create an instance', () => {
const pipe = new SubstractDatePipe();
expect(pipe).toBeTruthy();
});

it('returns the date diff', () => {
const fromDate = new Date('2011-04-11T10:20:30Z');
const substractDate = new Date('2011-04-11T08:00:30Z');

const diff = new SubstractDatePipe().transform(fromDate, substractDate);

expect(diff).toBe('02:20');
});
});
22 changes: 22 additions & 0 deletions src/app/modules/shared/pipes/substract-date/substract-date.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'substractDate'
})
export class SubstractDatePipe implements PipeTransform {

transform(fromDate: Date, substractDate: Date): string {
const difference = fromDate.valueOf() - substractDate.valueOf();

const minutes = Math.floor((difference / (1000 * 60)) % 60);
const hours = Math.floor(difference / (1000 * 60 * 60) % 24);

return `${this.formatTime(hours)}:${this.formatTime(minutes)}`;
}

formatTime(time: number): string {
const formattedTime = (time < 10) ? '0' + time : time.toString();
return formattedTime;
}

}