Created
January 26, 2024 12:57
-
-
Save cesarkohl/c39311989389b086e1dcc088d226636f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Update Event Logs convertedTime | |
*/ | |
function convertToCST(utcTimestamp) { | |
// Parse the UTC timestamp string into a Date object | |
const date = new Date(utcTimestamp); | |
// Check if daylight saving time (DST) is in effect | |
const isDST = () => { | |
const january = new Date(date.getFullYear(), 0, 1); | |
const july = new Date(date.getFullYear(), 6, 1); | |
return date.getTimezoneOffset() < Math.max(january.getTimezoneOffset(), july.getTimezoneOffset()); | |
}; | |
// Adjust the date for daylight saving time | |
if (isDST()) { | |
date.setHours(date.getHours() + 1); | |
} | |
// Convert to America/Chicago timezone | |
const cstTime = new Intl.DateTimeFormat('en-US', { | |
timeZone: 'America/Chicago', | |
hour12: false, // 24-hour format | |
year: 'numeric', | |
month: 'numeric', | |
day: 'numeric', | |
hour: 'numeric', | |
minute: 'numeric', | |
second: 'numeric', | |
}).format(date); | |
return cstTime; | |
} | |
angular | |
.element('.unqorkio-form') | |
.scope() | |
.$watchGroup(["submission.data.eventLog"], | |
(eventLogs, _) => { | |
if (eventLogs == undefined) { | |
return; | |
} | |
eventLogs[0].map((eventLog, i) => { | |
angular.element('.unqorkio-form').scope().submission.data.eventLog[i].convertedTimeStamp = convertToCST(eventLog.created) + " CST"; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment