Rename by Date, round to minutes

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Rename by Date, round to minutes

Postby RickMcRock » Wed Dec 29, 2021 5:18 pm

Hi everybody, hope you had a good christmas time!
I have just started using BRU, looks really powerful. However i ran into my first problem.
I have two sets of files that were generated roughly 1minute apart. Now when i want to sync the two sets of files,
i get missaligned pairs, because some files will be generated 11:59:58 with the other part of the pair 12:00:05.
Is there any way i can round to the minute?
RickMcRock
 
Posts: 2
Joined: Wed Dec 29, 2021 5:12 pm

Re: Rename by Date, round to minutes

Postby RickMcRock » Wed Dec 29, 2021 6:52 pm

OK,
i think i found a solution. This code works:
My Date is formatted YYYY_MMDD_mmhhss

var coeff = 1000 * 60 * 1;
var date = exif("%d"); //or use any other date
var rounded = new Date(Math.round(date.getTime() / coeff) * coeff)
function pad2(n) { return n < 10 ? '0' + n : n }
var roundedName = ( rounded.getFullYear().toString() + "_" + pad2(rounded.getMonth() + 1) + pad2( rounded.getDate()) + "_" + pad2( rounded.getHours() ) + pad2( rounded.getMinutes() ) + "00" );
newName = roundedName
RickMcRock
 
Posts: 2
Joined: Wed Dec 29, 2021 5:12 pm


Return to Javascript Renaming