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
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ describe('DetailsFieldsComponent', () => {
description: '',
start_date: new Date('2020-02-05T00:00:01').toISOString(),
end_date: new Date('2020-02-05T00:01:01').toISOString(),
uri: ''
uri: '',
timezone_offset: new Date().getTimezoneOffset(),
},
shouldRestartEntry: false
};
Expand Down Expand Up @@ -276,6 +277,7 @@ describe('DetailsFieldsComponent', () => {
description: '',
start_date: new Date('2020-06-11T00:00:10').toISOString(),
uri: 'ticketUri',
timezone_offset: new Date().getTimezoneOffset(),
},
shouldRestartEntry: false
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {
start_date: new Date(`${entryDate}T${this.entryForm.value.start_hour.trim()}`).toISOString(),
end_date: new Date(`${entryDate}T${this.entryForm.value.end_hour.trim()}`).toISOString(),
uri: this.entryForm.value.uri,
timezone_offset: new Date().getTimezoneOffset(),
};
if (this.goingToWorkOnThis) {
delete entry.end_date;
Expand Down
1 change: 1 addition & 0 deletions src/app/modules/shared/models/entry.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export interface NewEntry {
technologies?: string[];
uri?: string;
activity_id?: string;
timezone_offset?: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,17 @@ describe('ProjectListHoverComponent', () => {
expect(component.projectsForm.setValue)
.toHaveBeenCalledWith({ project_id: 'customer - xyz'});
});

it('creates time-entry with timezone_offset property', () => {
spyOn(store, 'dispatch');
component.clockIn('1', 'customer', 'project');
expect(store.dispatch).toHaveBeenCalledWith(
new CreateEntry({
project_id: '1',
start_date: new Date().toISOString(),
timezone_offset: new Date().getTimezoneOffset()
})
);
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ export class ProjectListHoverComponent implements OnInit, OnDestroy {
}

clockIn(selectedProject, customerName, name) {
const entry = { project_id: selectedProject, start_date: new Date().toISOString() };
const entry = {
project_id: selectedProject,
start_date: new Date().toISOString(),
timezone_offset: new Date().getTimezoneOffset(),
};
this.store.dispatch(new entryActions.CreateEntry(entry));
this.projectsForm.setValue( { project_id: `${customerName} - ${name}`, } );
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/modules/time-clock/store/entry.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export class EntryEffects {
map((response) => {
const stopDateForEntry = new Date(response.end_date);
stopDateForEntry.setSeconds(stopDateForEntry.getSeconds() + 1 );
return new actions.CreateEntry({ project_id: action.idProjectSwitching, start_date: stopDateForEntry.toISOString() });
return new actions.CreateEntry({
project_id: action.idProjectSwitching,
start_date: stopDateForEntry.toISOString(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is not your change, but it seems something is wrong here:
start_date: stopDateForEntry.toISOString(),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to do with the logic of clocking out, when switching a project. The stopDate of the entry being clocked out is the startDate of the new time-entry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I get what you mean. In that case I would change line 23 to this:
const newTimeEntryStartDate = stopDateForEntry.setSeconds(stopDateForEntry.getSeconds() + 1 );
and line 26 to:
start_date: newTimeEntryStartDate.toISOString(),

In that way, it is easier to read.

timezone_offset: new Date().getTimezoneOffset(),
});
}),
catchError((error) => {
this.toastrService.warning(error.error.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ describe('TimeEntriesComponent', () => {
entry: {
project_id: 'project-id',
end_date: '2010-05-05T10:04',
start_date: null
start_date: null,
timezone_offset: 300,
}, shouldRestartEntry: false
};
component.activeTimeEntry = null;
Expand Down Expand Up @@ -303,6 +304,7 @@ describe('TimeEntriesComponent', () => {
description: 'description',
technologies: [],
uri: 'abc',
timezone_offset: 300,
}, shouldRestartEntry: false
};
component.entryId = undefined;
Expand Down