Skip to content

Commit

Permalink
Fix Invalid Date
Browse files Browse the repository at this point in the history
  • Loading branch information
juankaromo committed Jun 25, 2019
1 parent a989067 commit e1ccb55
Showing 1 changed file with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,46 +1,56 @@
define(['../module'], function(module) {
'use strict'
'use strict';

class DateDiffService {
constructor() {
this.start = null
this.end = null
this.start = null;
this.end = null;
}

/**
* Returns the difference between dates
*/
getDateDiff(start, end) {
this.start = new Date(start)
this.end = new Date(end)
this.start = new Date(start);
this.end = new Date(end);
const result = {
duration: 'Unknown',
inProgress: false,
end: this.end || 'Unknown',
start: this.start || 'Unknown'
}
};
if (this.end && this.start) {
result.duration = (this.end - this.start) / 1000 / 60
result.duration = Math.round(result.duration * 100) / 100
result.duration = (this.end - this.start) / 1000 / 60;
result.duration = Math.round(result.duration * 100) / 100;
if (result.duration <= 0) {
result.inProgress = true
result.inProgress = true;
}
}
return result
return result;
}

setBrowserOffset(d) {
try {
const date = new Date(d)
const offset = new Date().getTimezoneOffset()
const offsetTime = new Date(date.getTime() - offset * 60000)
const result = offsetTime.toLocaleString('en-ZA').replace(',', '')
return result
const [day, time] = d.indexOf('T') !== -1 ? d.split('T') : d.split(' ');
const [year, month, monthDay] =
d.indexOf('-') !== -1 ? day.split('-') : day.split('/');
const [hour, minute, seconds] = time.split(':');
const date = new Date(
year,
parseInt(month) - 1,
monthDay,
hour,
minute,
seconds.split('.')[0]
);
const offset = new Date().getTimezoneOffset();
const offsetTime = new Date(date.getTime() - offset * 60000);
return offsetTime.toLocaleString('en-ZA').replace(',', '');
} catch (error) {
return Promise.reject(error)
return Promise.reject(error);
}
}
}

module.service('$dateDiffService', DateDiffService)
})
module.service('$dateDiffService', DateDiffService);
});

0 comments on commit e1ccb55

Please sign in to comment.