1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

only convert to 24 hour format if input is in correct format

This commit is contained in:
Luis Miguel Almánzar 2013-06-15 13:57:08 -04:00
parent cda277fed5
commit 0f5fc00544

View file

@ -273,19 +273,25 @@
function convertTo24HourFormat(time) { function convertTo24HourFormat(time) {
if (time == "") if (time == "")
return time; return time;
var hours = Number(time.match(/^(\d+)/)[1]); var match = time.match(/^(\d+):(\d+)(.*)$/);
var minutes = Number(time.match(/:(\d+)/)[1]); if (match)
var ampm = time.match(/\s(.*)$/)[1]; {
ampm = ampm.toUpperCase(); var hours = Number(match[1]);
if (ampm == "PM" && hours < 12) hours = hours + 12; var minutes = Number(match[2]);
if (ampm == "AM" && hours == 12) hours = 0; var ampm = $.trim(match[3]);
var sHours = hours.toString(); ampm = ampm.toUpperCase();
var sMinutes = minutes.toString(); if (ampm == "PM" && hours < 12) hours = hours + 12;
if (hours < 10) sHours = "0" + sHours; if (ampm == "AM" && hours == 12) hours = 0;
if (minutes < 10) sMinutes = "0" + sMinutes; var sHours = hours.toString();
return sHours + ":" + sMinutes; var sMinutes = minutes.toString();
if (hours < 10) sHours = "0" + sHours;
if (minutes < 10) sMinutes = "0" + sMinutes;
return sHours + ":" + sMinutes;
} else {
return time;
}
} }
function convertTo12HourFormat(time) { function convertTo12HourFormat(time) {
if (time == "") if (time == "")
return time; return time;