Skip to content

Commit

Permalink
Fix time service for IE and Safari (#1505)
Browse files Browse the repository at this point in the history
  • Loading branch information
juankaromo authored and Jesús Ángel committed Jun 6, 2019
1 parent 50b15be commit 4150478
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion public/controllers/agent/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ export class AgentsController {
try {
return text + this.timeService.offset(time);
} catch (error) {
return `${text}${time} (UTC)`;
return time !== '-' ? `${text}${time} (UTC)` : time;
}
}

Expand Down
2 changes: 1 addition & 1 deletion public/controllers/misc/reporting.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ReportingController {
try {
return this.timeService.offset(time);
} catch (error) {
return `${time} (UTC)`;
return time !== '-' ? `${time} (UTC)` : time;
}
}

Expand Down
5 changes: 4 additions & 1 deletion public/services/time-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export class TimeService {
*/
offset(d) {
try {
const date = new Date(d.replace('Z', ''));
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(',', '');
Expand Down

0 comments on commit 4150478

Please sign in to comment.