Using negative numbers to adjust datetime

Started by odog502, June 30, 2016, 12:53:25 AM

Previous topic - Next topic

odog502

Is there a simple way to use negative numbers for adjusting Date/Time fields?  I know the traditional way is using one of the following.

If it's a decrease:
exiftool -overwrite_original -Quicktime:CreateDate-=

If it's an increase:
exiftool -overwrite_original -Quicktime:CreateDate+=

However, Im attempting to run this command from within a script and the value Im passing could be positive OR negative.  I could test the number before hand and if its negative use "CreateDate-=" and if its positive use "CreateDate+=" but that seems kludgy.

Is there an easier way that Im missing?

EDIT: Thought about it for a bit and am guessing that I should probably be using the full ExifTool Perl install, instead of running the command line exe from the script.  But ill leave this post here in case theres any additional tips on the matter.

Hayo Baan

Have you already tried simply adding a negative value?

(Note: I really do not see a need to install the full perl library for this only)
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

Unfortunately the negative value won't work because the +- is used as a separator for the time zone, so anything after a + or - in the shift string will shift the time zone.

To do this in a script, you would need to use a signed value and put the "=" after the sign when inserting it into the ExifTool command line.

In Perl:


$val = "+$val" unless $val =~ /^[-+]/;  # add a "+" sign if necessary
$val =~ s/([-+])/$1=/;                  # insert the "="
$cmd = "exiftool '-Quicktime:CreateDate$val' ...";


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

odog502

Hayo Bean, I had tried that and a few other variations and it couldn't get it to work, as confirmed by Phil's statement.  I also considered adjusting the date in perl BEFORE applying it to the command but that would require the DateTime module since date math can get complex.  And I would prefer to use plain vanilla Perl if possible.

Thanks for the code Phil.  I will use that for now.

Would this warrant a new feature for exiftool?  Ideally it would be nice if I could apply a time to one of one of the UTC assumed date/time fields like this:
exiftool -overwrite_original -Quicktime:CreateDate="2001:02:03 04:05:06+01:00"
And instead of it just chopping off the timezone it actually converts the time to UTC.  So the result would be:
[QuickTime]     Create Date                     : 2001:02:03 03:05:06

Could that be added as part of the -api QuickTimeUTC option?

Phil Harvey

#4
That sounds like a reasonable request.  I'll put it on the list and think about it more when I get a chance.

- Phil

Edit:  I did a quick test, and ExifTool is already consistent when writing QuickTime date/time values with the QuickTimeUTC option, so I am happy with the way things are:

> exiftool a.mov -quicktime:modifydate='2001:02:03 04:05:06+07:00'
    1 image files updated
> exiftool a.mov -quicktime:modifydate
Modify Date                     : 2001:02:03 04:05:06 <-- CORRECT, and time zone information is lost
> exiftool a.mov -quicktime:modifydate -api quicktimeutc
Modify Date                     : 2001:02:02 23:05:06-05:00 <-- WRONG, as expected
> exiftool a.mov -quicktime:modifydate='2001:02:03 04:05:06+07:00' -api quicktimeutc
    1 image files updated
> exiftool a.mov -quicktime:modifydate -api quicktimeutc
Modify Date                     : 2001:02:02 16:05:06-05:00 <-- CORRECT, and converted to local time
> exiftool a.mov -quicktime:modifydate
Modify Date                     : 2001:02:02 21:05:06 <-- WRONG, as expected
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Quote from: odog502 on June 30, 2016, 03:22:33 PM
...since date math can get complex.

I always like this Computerphile video when it comes to explaining how complicated date math can get.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Oh, and I should have mentioned that you may use the ExifTool Date/time shift module to do the math for you.  I should document the function so other people can use it.

You use 'Image/ExifTool/Shift.pl', then call Image::ExifTool::ShiftTime() with the following arguments:

# 0) date/time string
# 1) shift string
# 2) shift direction (+1 or -1), or 0 or undef to take shift direction from sign of shift
# Returns: error string, or undef on success and date/time string is updated


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

odog502

Quote from: Phil Harvey on June 30, 2016, 03:48:27 PMEdit:  I did a quick test, and ExifTool is already consistent when writing QuickTime date/time values with the QuickTimeUTC option
Thats great! The api option appears to already work the way I wanted it.  I assumed it was an option used for reading only and so I didn't even try it.

Thanks for writing the steps out for ShiftTime.  When I saw that module earlier during my research that's when I figured I probably needed to do the full ExifTool perl install.

I liked the video StarGeek.  Watched the whole thing and can relate to the guy. We should do away with timezones, DST, gregorian calendars completely and just start using stardates. :)