Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 91c7aa74 authored by FadhilP's avatar FadhilP
Browse files

add error handling on time-util

parent cf280f17
No related branches found
No related tags found
1 merge request!64Fadhil
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September","October", "November", "December"];
function tConvert (time) {
// Check correct time format and split into components
time = time.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time];
if (time.length > 1) { // If time format correct
console.log(time)
time = time.slice (1, 4); // Remove full string match value
time[5] = +time[0] < 12 ? ' AM' : ' PM'; // Set AM/PM
time[0] = +time[0] % 12 || 12; // Adjust hours
}
return time.join (''); // return adjusted time or original string
try{
// Check correct time format and split into components
time = time.toString ().match (/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time];
if (time.length > 1) { // If time format correct
console.log(time)
time = time.slice (1, 4); // Remove full string match value
time[5] = +time[0] < 12 ? ' AM' : ' PM'; // Set AM/PM
time[0] = +time[0] % 12 || 12; // Adjust hours
}
return time.join (''); // return adjusted time or original string
} catch(error){}
}
function translate(time) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment