Comparing Dates

Started by robertoleonardo, November 17, 2018, 02:15:52 PM

Previous topic - Next topic

robertoleonardo

Hi - first off, exiftool is amazing and makes my little big OCD heart so happy - thank you, Phil.  Second, have been working with exiftool for a few months so am getting OKAY with it - but i am an attorney and not a programmer - so bear with me (and related: have searched aroun but don't see an answer to this exact question).  With that, and sorry for the length but some explanation seems necessary:

I'm trying to clean up the metadata from the masters folder of my apple photos library before a clean start with far superior lightroom.  One of the issues I haven't fully resolved is dates. For this example i'll stick with DateTimeOriginal and JPGs (i should be competent to modify any answers for other extensions/tags).  So I've got 4 types of JPGs:
(1) No DateTimeOriginal
(2) DateTimeOriginal matches folder [as i'm sure you know, apple organizes masters folders with YYYYMMDD-hhmmss as any given images parent folder. Not entirely clear to me how it generates this but i find that most of the time it's accurate enough for me - but not always, hence this question]
(3) DateTimeOriginal is shifted--presumably relating to timezones inconsistently being applied--x number of hours from parent folder.
(4) DateTimeOriginal is entirely different from parent folder.  I'm not exactly sure how many these are, and i'll probably just have to evaluate 1 by 1 and see which i go with, but if i have to do it in bulk i would sasy i'm more inclined to trust datetimeoriginal

For type 1, I'm trying to add from parent folder name - I figured out (-DateTimeOriginal<${directory;s/.+\/\b|\///g}).  And i've figured out how to ignore parent folder to the extent datetimeoriginal exists.  But what I can't figure out is the conditionals for the remaining three types.  I think it has to do with formatting of parent folder string vs DTO date [and also i'm just having trouble with the regular expressions].

Can anyone help me with a template for (1) datetimeoriginal exactly equals parent folder date (2) datetimeoriginal is x number of hours shifted (i'll just work step by step from -8 to +8 and adjust these as needed) and (3) datetimeoriginal is more than 8 hours different from folder date?

(FYI - don't worry, i have this all backed up.  I also added custom tags to each of the subject files of FolderDate and OldDate ["old" = current datetimeoriginal, but will be old if i end up changing it]).

Thanks!

Phil Harvey

I would do this with a user-defined Composite tag, similar to this post.

Here is a config file that should give you a good start, but I don't know what you want to do in cases 3 and 4:

%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyDate => {
            Require => {
                0 => 'Directory',
            },
            Desire => {
                1 => 'DateTimeOriginal',
            },
            ValueConv => q{
                return undef unless $val[0] =~ /(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})(\d{2})/;
                my $folderTime = "$1:$2:$3 $4:$5:$6";
                # case 1) no DateTimeOriginal
                return $folderTime unless $val[1];
                my $diff = GetUnixTime($val[1]) - GetUnixTime($folderTime);
                my $hours = $diff / 3600;
                # case 2) folder time is the same as DateTimeOriginal
                return undef if $diff == 0; # all good if no difference
                if (abs($hours) <= 8 and $hours == int($hours)) {
                    # case 3) time zone difference
                    # - don't know what you want to do here
                } else {
                    # case 4) times are different
                    # - don't know what you want to do here
                }
                return undef;
            },
        },
    },
);
1; #end


With this config file, the command would be

exiftool -config my.config "-datetimeoriginal<mydate" -r DIR

Note that DateTimeOriginal won't be set if the MyDate ValueConv returns undef.  Otherwise, it will be set to whatever date/time this is returned.

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

robertoleonardo

I'm slammed at work so won't get around to tinkering for a minute, but I see this reply so just wanted to say ahead of time - thank you so much! I'll mess around with this when i can.  Appreciate everything!