Adjust Date by 5 Hours

Advanced Renamer forum
#1 : 21/01-24 14:43
Ryan W
Ryan W
Posts: 3
I have a script that someone helpfully provided to adjust the time of photos by 5 hours. It was working in an older version of the program. Now that I have updated to the newest version (3.92p) I am having issues with the script.

The files that I am working with have the following format:

YYYY-MM-DD_hh-mm-ss.######.jpg

Here is the script I am working with:

match = item.name.match(/^(\d{4}-\d{2}-\d{2})_(\d{2})-(\d{2})-(\d{2})$/);
if (match[0]) {
epoch = Date.parse(match[1] + 'T' + match[2]+ ':' + match[3] + ':' + match[4]);
date = new Date(epoch - 5 * 3600000);
return date.getUTCFullYear()
+ "-" + ("0" + (date.getUTCMonth() + 1)).slice(-2)
+ "-" + ("0" + date.getUTCDate()).slice(-2)
+ "_" + ("0" + date.getUTCHours()).slice(-2)
+ "-" + ("0" + date.getUTCMinutes()).slice(-2)
+ "-" + ("0" + date.getUTCSeconds()).slice(-2);
}

Please let me know how to update. Thanks!


21/01-24 14:43
#2 : 22/01-24 12:50
Kim Jensen
Kim Jensen
Administrator
Posts: 906
Reply to #1:
Instead of
match = item.name.match(/^(\d{4}-\d{2}-\d{2})_(\d{2})-(\d{2})-(\d{2})$/);

Have you tried
match = item.name.match(/^(\d{4}-\d{2}-\d{2})_(\d{2})-(\d{2})-(\d{2})/);
Without the ending $

When the $ is in the expression, the file name can only be formatted like this: YYYY-MM-DD_hh-mm-ss.jpg. If the filename contains any other characters, it will not match.


22/01-24 12:50