-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a989067
commit e1ccb55
Showing
1 changed file
with
28 additions
and
18 deletions.
There are no files selected for viewing
46 changes: 28 additions & 18 deletions
46
SplunkAppForWazuh/appserver/static/js/services/date-diff/dateDiffService.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |