Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const TIME_SEP = "-";
- const AMPM_SEP = " ";
- const reTimeSplit = /(.*?)(\d{2})-(\d{2})-(\d{2})(.*)/;
- const FULL_RSLT = 0, BEF_TIME = 1, TIME_HR = 2, TIME_MIN = 3, TIME_SEC = 4, AFT_TIME = 5;
- const AM = 0, PM = 1;
- const AMPM = ["AM", "PM"];
- var aTime = [];
- // If the regex fails (return nothing) display an error and exit the script
- if (reTimeSplit.test(item.newBasename) == False) { return null; }
- aTime = reTimeSplit.exec(item.newBasename);
- if ( parseInt(aTime[TIME_HR]) > 12 ){
- return aTime[BEF_TIME] + zpad((parseInt(aTime[TIME_HR]) - 12).toString(), 2) + TIME_SEP + aTime[TIME_MIN] + TIME_SEP + aTime[TIME_SEC] + AMPM_SEP + AMPM[PM] + aTime[AFT_TIME];}
- else{
- return aTime[BEF_TIME] + aTime[TIME_HR] + TIME_SEP + aTime[TIME_MIN] + TIME_SEP + aTime[TIME_SEC] + AMPM_SEP + AMPM[AM] + aTime[AFT_TIME];
- }
- // Function that add leading zeros to any string
- function zpad(str, nb_digits)
- {
- if (str.length < nb_digits)
- { return (Array(nb_digits - str.length + 1).join('0') + str); }
- else
- { return str; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement