You are not logged in.
Pages: 1
I'm not a coder and was wondering how to add a minutes +- variable to the hoursspan script as well as the existing hours variable. I'm trying to syncronize photos taken fron several cameras that have different internal clock settings. This tool works great for everything else.
Thanks
Offline
I stumbled around and figured out how to make it work. Maybe you should update your script as well.
// This script reads dates from filenames in format: yyyy-mm-dd hh-nn-ss.JPG
// then adds/subtracts N hours and/or minutes from the date and prints the new date in the
// format defined by DateOutputFormat variable. HoursSpan variable defines
// how many hours should be added/subtracted (use minus for subtraction).
// MinutesSpan variable defines how many minutes should be added/subtracted
// (use minus for subtraction).
const
HoursSpan = 0; // amount of hours to add or subtract!!
DateOutputFormat = 'yyyy-mm-dd-hh-nn-ss'; // output date format!!
HoursPerDay = 24; // do not change this!!
MinutesSpan = 0; // amount of mins to add or subtract!!
MinsPerDay = 1440; // do not change this!!
var
iYear, iMonth, iDay, iHour, iMin, iSec: Integer;
Date, Time, DateTime: TDateTime;
procedure AddMinutes(var ADateTime: TDateTime; const ANumberOfMinutes: Integer);
begin
ADateTime := ((aDateTime *MinsPerDay) +aNumberOfMinutes) /MinsPerDay
end;
procedure AddHours(var ADateTime: TDateTime; const ANumberOfHours: Integer);
begin
ADateTime := ((ADateTime * HoursPerDay) + ANumberOfHours) / HoursPerDay;
end;
begin
// extract date-time variables as integers
iYear := StrToIntDef(Copy(FileName, 1, 4), -1);
iMonth := StrToIntDef(Copy(FileName, 6, 2), -1);
iDay := StrToIntDef(Copy(FileName, 9, 2), -1);
iHour := StrToIntDef(Copy(FileName, 12, 2), -1);
iMin := StrToIntDef(Copy(FileName, 15, 2), -1);
iSec := StrToIntDef(Copy(FileName, 18, 2), -1);
// process only if all variables are correctly converted
if (iYear >= 0) and (iMonth >= 0) and (iDay >= 0) and
(iHour >= 0) and (iMin >= 0) and (iSec >= 0) then
begin
// create a new date-time variable
Date := EncodeDate(iYear, iMonth, iDay);
Time := EncodeTime(iHour, iMin, iSec, 0);
DateTime := Date + Time;
// add hours (use minus for subtracting)
AddMinutes(DateTime, MinutesSpan);
AddHours(DateTime, HoursSpan);
// concatenate the rest of the filename and the new date
FileName := Copy(FileName, 20, Length(FileName));
FileName := FormatDateTime(DateOutputFormat, DateTime) + FileName;
end
// something went wrong
else FileName := 'INVALID INPUT';
end.
Offline
You could have used:
DateTime := EncodeDate(iYear, iMonth, iDay) + EncodeTime(iHour, iMin, iSec, 0);
DateTime := IncHour(DateTime, HoursSpan);
DateTime := IncMinute(DateTime, MinutesSpan);
Last edited by SafetyCar (2012-03-27 10:21)
If this software has helped you, consider getting your pro version. :)
Offline
I received a reply on my mailbox, I'll reply here.
What I was refering to is replacing your functions for the default ones just like in the code below.
But if your code was already working you could keep using it as it was
const
HoursSpan = 0; // amount of hours to add or subtract!!
MinutesSpan = 0; // amount of mins to add or subtract!!
DateOutputFormat = 'yyyy-mm-dd-hh-nn-ss'; // output date format!!
var
iYear, iMonth, iDay, iHour, iMin, iSec: Integer;
DateTime: TDateTime;
begin
// extract date-time variables as integers
iYear := StrToIntDef(Copy(FileName, 1, 4), -1);
iMonth := StrToIntDef(Copy(FileName, 6, 2), -1);
iDay := StrToIntDef(Copy(FileName, 9, 2), -1);
iHour := StrToIntDef(Copy(FileName, 12, 2), -1);
iMin := StrToIntDef(Copy(FileName, 15, 2), -1);
iSec := StrToIntDef(Copy(FileName, 18, 2), -1);
// process only if all variables are correctly converted
if (iYear >= 0) and (iMonth >= 0) and (iDay >= 0) and
(iHour >= 0) and (iMin >= 0) and (iSec >= 0) then
begin
// create a new date-time variable
DateTime := EncodeDate(iYear, iMonth, iDay) + EncodeTime(iHour, iMin, iSec, 0);
// add hours (use minus for subtracting)
DateTime := IncHour(DateTime, HoursSpan);
DateTime := IncMinute(DateTime, MinutesSpan);
// concatenate the rest of the filename and the new date
FileName := Copy(FileName, 20, Length(FileName));
FileName := FormatDateTime(DateOutputFormat, DateTime) + FileName;
end
// something went wrong
else FileName := 'INVALID INPUT';
end.
If this software has helped you, consider getting your pro version. :)
Offline
Pages: 1