ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: dd-b on April 30, 2022, 04:20:41 PM

Title: DateFormat not being applied to IPTC:DateCreated (or XMP:DateCreated)
Post by: dd-b on April 30, 2022, 04:20:41 PM
My test file is a Nikon D700 NEF file. I'm pretty sure it's been modified by PhotoMechanic, it would be in my normal workflow. (I don't have the camera any more, so I can't see if I can reproduce the problem in a completely clean file). I can't attach the file since it's bigger than the limit, but I can provide it some other way if necessary.

This is running on FreeBSD 11.3; the Image::ExifTool version is 12.

This Perl test program

#!/usr/bin/env perl

use v5.20;
use strictures 2;
use Image::ExifTool;
use Data::Dump qw ( pp dd );

my $ExifTool = Image::ExifTool->new;

$ExifTool->ExtractInfo('t_2dto.nef') or
  die "Error on 't_2dto.nef' metadata extract: " . $ExifTool->GetValue('Error');
# ExtractInfo respects a small list of options, not including these two.
$ExifTool->Options('PrintConv' => 1, 'DateFormat' => '%Y-%m-%d');

my $gv = $ExifTool->GetValue('IPTC:DateCreated', 'PrintConv');
pp "value: ", $gv;
my $e = $ExifTool->GetInfo('Error', 'Warning');
pp "Diagnostics: ", $e;


Produces this output from that test file:

$ ./t007.pl
("value: ", "2009:08:29")
("Diagnostics: ", {})


That's the date that exiftool shows in the file; the problem is that it's formatted with colons rather than dashes. The test program sets option DateFormat to a format using dashes, and specifies PrintConv. And for other date fields I have tried the formatting works correctly. But not for this one. (I'm using the parser in DateTime::Format::ISO8601 to parse the date extracted from the file in my actual application; this works when the DateFormat option is followed, but not on this one field for some reason.)

Obviously I can work around this easily enough, using brute force rather than DateFormat to change the date from EXIF date format to ISO8601 date format. But it seems like weird behavior, or even possibly a bug, so I'm reporting it.

Title: Re: DateFormat not being applied to IPTC:DateCreated (or XMP:DateCreated)
Post by: Phil Harvey on April 30, 2022, 05:45:27 PM
-d FMT (-dateFormat)
            Set the format for date/time tag values

So it doesn't apply to date-only or time-only tags.

So this does work for XMP:DateCreated if it contains a full date/time specification:

> exiftool a.jpg -datecreated -G1
[IPTC]          Date Created                    : 2022:04:30
[XMP-photoshop] Date Created                    : 2022:04:30 17:41:45-04:00
> exiftool a.jpg -datecreated -G1 -d %Y
[IPTC]          Date Created                    : 2022:04:30
[XMP-photoshop] Date Created                    : 2022


- Phil
Title: Re: DateFormat not being applied to IPTC:DateCreated (or XMP:DateCreated)
Post by: dd-b on April 30, 2022, 06:33:51 PM
I suppose at this point it would break the world to make it also apply to date values. I guess I'll drop back to handling the raw values directly, that'll take out a few layers of processing.

I'm trying to make DateTime objects from date or date/time information in various metadata fields (EXIF, IPTC, XMP at least), so that I can compare them, or see if a DateTime::Incomplete object includes the precise time given in another metadata object. I would have thought that wanting to go from metadata date and date/time fields to some of the various Perl date/time packages would have been a common use, but I'm not finding the tools to do it at all easily. Am I going at it completely wrong or something? I don't see any kind of sharp line between including time and not including time in actual applications.
Title: Re: DateFormat not being applied to IPTC:DateCreated (or XMP:DateCreated)
Post by: Phil Harvey on May 02, 2022, 11:14:20 AM
Quote from: dd-b on April 30, 2022, 06:33:51 PM
I suppose at this point it would break the world to make it also apply to date values.

I don't think it would break too much for people, but some of the date/time format codes don't apply to date-only values, and the date/time routines I use require a time.

QuoteI'm trying to make DateTime objects from date or date/time information in various metadata fields (EXIF, IPTC, XMP at least), so that I can compare them, or see if a DateTime::Incomplete object includes the precise time given in another metadata object. I would have thought that wanting to go from metadata date and date/time fields to some of the various Perl date/time packages would have been a common use, but I'm not finding the tools to do it at all easily. Am I going at it completely wrong or something? I don't see any kind of sharp line between including time and not including time in actual applications.

I don't know what to say about this.  Personally, I find incomplete date/time values a pain in the butt.

- Phil