Skip to content
Merged
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: add flag to check end_date is defined #399
  • Loading branch information
Angeluz-07 committed Jun 24, 2020
commit c0193b2708d669aceda849c87b2a601e338aad16
10 changes: 5 additions & 5 deletions src/app/modules/time-entries/pages/time-entries.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ export class TimeEntriesComponent implements OnInit {
}

doSave(event: SaveEntryEvent) {
const endDateIsDefined = event.entry.end_date !== null && event.entry.end_date !== undefined;
if (this.entryId) {
const startDateChanged = this.entry.start_date !== event.entry.start_date;
const endDateChanged = this.entry.end_date !== event.entry.end_date;

if (startDateChanged) {
const startDate = new Date(event.entry.start_date);
Copy link
Contributor

@juanultimate juanultimate Jun 23, 2020

Choose a reason for hiding this comment

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

Lines 71, 72, 73 are the same than 89,90,91. Do not you think it would be great if we extract them to a method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your're right. I thought the same. I just didn't know the code style to include functions. I will ask for help to Rene for this and also to fix the tests. Thanks for pointing it out.

startDate.setSeconds(1, 0);
event.entry.start_date = startDate.toISOString();
}

if (endDateChanged) {
if (event.entry.end_date !== null && event.entry.end_date !== undefined) {
if (endDateIsDefined) {
const endDateChanged = this.entry.end_date !== event.entry.end_date;
if (endDateChanged) {
const endDate = new Date(event.entry.end_date);
endDate.setSeconds(0, 0);
event.entry.end_date = endDate.toISOString();
Expand All @@ -90,7 +90,7 @@ export class TimeEntriesComponent implements OnInit {
startDate.setSeconds(1, 0);
event.entry.start_date = startDate.toISOString();

if (event.entry.end_date !== null && event.entry.end_date !== undefined) {
if (endDateIsDefined) {
const endDate = new Date(event.entry.end_date);
endDate.setSeconds(0, 0);
event.entry.end_date = endDate.toISOString();
Expand Down