Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix: TT-20 testing
  • Loading branch information
wobravo committed Apr 17, 2021
commit 6b10b828b0ecea464aac704e1a077c0578ca0a5e
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,23 @@ describe('DetailsFieldsComponent', () => {
expect(endDateInput.max).toEqual(expectedDate);
});

const params = [
{formatDate: 'YYY-MM-DD'},
{dateFormatHour: 'DD/MM/YYYY HH:mm'},
];
params.map((param) => {
fit('should return the difference if there is data in the time in and in the time out', () => {
const date = moment('2016-01-05');
expect(4).toEqual(component.getTimeDifference());
});
fit('should return the difference if there is data in the time in and in the time out', () => {
component.ngOnChanges();
const StartHour = '08:00';
const EndHour = '19:00';
const StartDate = '2021-04-14';
const EndDate = '2021-04-15';
const startDateInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#start_date');
const startHourInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#start_hour');
const endDateInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#end_date');
const endHourInput: HTMLInputElement = fixture.debugElement.nativeElement.querySelector('#end_hour');
startDateInput.value = StartDate;
startHourInput.value = StartHour;
endDateInput.value = EndDate;
endHourInput.value = EndHour;
spyOn(component, 'getTimeDifference');

expect(component.getTimeDifference).toHaveBeenCalled();
});

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { EntryActionTypes } from './../../../time-clock/store/entry.actions';
import { SaveEntryEvent } from './save-entry-event';
import { ProjectSelectedEvent } from './project-selected-event';
import { get } from 'lodash';
import { DATE_FORMAT, DATE_FORMAT_HOUR } from 'src/environments/environment';
import { DATE_FORMAT } from 'src/environments/environment';
import { TechnologiesComponent } from '../technologies/technologies.component';

type Merged = TechnologyState & ProjectState & ActivityState & EntryState;
Expand Down Expand Up @@ -130,17 +130,15 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
this.end_date.setValue($event);
}

getTimeDifference(){
const startDate = moment(`${this.start_date.value} ${this.start_hour.value}`).format(DATE_FORMAT_HOUR);
const endDate = moment(`${this.end_date.value} ${this.end_hour.value}`).format(DATE_FORMAT_HOUR);
if (this.end_hour.value !== '00:00') {
const diffDate = moment(endDate, DATE_FORMAT_HOUR).diff(moment(startDate, DATE_FORMAT_HOUR));
getTimeDifference() {
const startDate = moment(`${this.start_date.value} ${this.start_hour.value}`);
const endDate = moment(`${this.end_date.value} ${this.end_hour.value}`);
if (startDate <= endDate) {
const diffDate = endDate.diff(startDate);
const duration = moment.duration(diffDate);
const diferenceTime = Math.floor(duration.asHours()) + moment.utc(diffDate).format(':mm');
return diferenceTime;
} else {
return '0:00';
return moment.utc(duration.asMilliseconds()).format('HH:mm');
}
return '00:00';
}

ngOnChanges(): void {
Expand Down
1 change: 0 additions & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const STACK_EXCHANGE_ACCESS_TOKEN = keys.STACK_EXCHANGE_ACCESS_TOKEN;
export const AZURE_APP_CONFIGURATION_CONNECTION_STRING = keys.AZURE_APP_CONFIGURATION_CONNECTION_STRING;
export const DATE_FORMAT = 'yyyy-MM-dd';
export const DATE_FORMAT_YEAR = 'YYYY-MM-DD';
export const DATE_FORMAT_HOUR = 'DD/MM/YYYY HH:mm';
export const GROUPS = {
ADMIN: 'time-tracker-admin',
TESTER: 'time-tracker-tester',
Expand Down