Ignore:
Timestamp:
2019-07-07T01:56:46+02:00 (6 years ago)
Author:
Don-vip
Message:

see #17848 - update to metadata-extractor 2.12.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/drew/metadata/exif/ExifSubIFDDirectory.java

    r13061 r15217  
    11/*
    2  * Copyright 2002-2017 Drew Noakes
     2 * Copyright 2002-2019 Drew Noakes and contributors
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    2323import com.drew.lang.annotations.NotNull;
    2424import com.drew.lang.annotations.Nullable;
     25import com.drew.metadata.Directory;
    2526
    2627import java.util.Date;
     
    6768
    6869    /**
    69      * Parses the date/time tag and the subsecond tag to obtain a single Date object with milliseconds
    70      * representing the date and time when this image was captured.  Attempts will be made to parse the
    71      * values as though it is in the GMT {@link TimeZone}.
     70     * Parses the date/time tag, the subsecond tag and the time offset tag to obtain a single Date
     71     * object with milliseconds representing the date and time when this image was modified.  If
     72     * the time offset tag does not exist, attempts will be made to parse the values as though it is
     73     * in the GMT {@link TimeZone}.
     74     *
     75     * @return A Date object representing when this image was modified, if possible, otherwise null
     76     */
     77    @Nullable
     78    public Date getDateModified()
     79    {
     80        return getDateModified(null);
     81    }
     82
     83    /**
     84     * Parses the date/time tag, the subsecond tag and the time offset tag to obtain a single Date
     85     * object with milliseconds representing the date and time when this image was modified.  If
     86     * the time offset tag does not exist, attempts will be made to parse the values as though it is
     87     * in the {@link TimeZone} represented by the {@code timeZone} parameter (if it is non-null).
     88     *
     89     * @param timeZone the time zone to use
     90     * @return A Date object representing when this image was modified, if possible, otherwise null
     91     */
     92    @Nullable
     93    public Date getDateModified(@Nullable TimeZone timeZone)
     94    {
     95        Directory parent = getParent();
     96        if (parent instanceof ExifIFD0Directory) {
     97            TimeZone timeZoneModified = getTimeZone(TAG_OFFSET_TIME);
     98            return parent.getDate(TAG_DATETIME, getString(TAG_SUBSECOND_TIME),
     99                (timeZoneModified != null) ? timeZoneModified : timeZone);
     100        } else {
     101            return null;
     102        }
     103    }
     104
     105    /**
     106     * Parses the date/time tag, the subsecond tag and the time offset tag to obtain a single Date
     107     * object with milliseconds representing the date and time when this image was captured.  If
     108     * the time offset tag does not exist, attempts will be made to parse the values as though it is
     109     * in the GMT {@link TimeZone}.
    72110     *
    73111     * @return A Date object representing when this image was captured, if possible, otherwise null
     
    80118
    81119    /**
    82      * Parses the date/time tag and the subsecond tag to obtain a single Date object with milliseconds
    83      * representing the date and time when this image was captured.  Attempts will be made to parse the
    84      * values as though it is in the {@link TimeZone} represented by the {@code timeZone} parameter
    85      * (if it is non-null).
     120     * Parses the date/time tag, the subsecond tag and the time offset tag to obtain a single Date
     121     * object with milliseconds representing the date and time when this image was captured.  If
     122     * the time offset tag does not exist, attempts will be made to parse the values as though it is
     123     * in the {@link TimeZone} represented by the {@code timeZone} parameter (if it is non-null).
    86124     *
    87125     * @param timeZone the time zone to use
     
    91129    public Date getDateOriginal(@Nullable TimeZone timeZone)
    92130    {
    93         return getDate(TAG_DATETIME_ORIGINAL, getString(TAG_SUBSECOND_TIME_ORIGINAL), timeZone);
     131        TimeZone timeZoneOriginal = getTimeZone(TAG_OFFSET_TIME_ORIGINAL);
     132        return getDate(TAG_DATETIME_ORIGINAL, getString(TAG_SUBSECOND_TIME_ORIGINAL),
     133            (timeZoneOriginal != null) ? timeZoneOriginal : timeZone);
    94134    }
    95135
    96136    /**
    97      * Parses the date/time tag and the subsecond tag to obtain a single Date object with milliseconds
    98      * representing the date and time when this image was digitized.  Attempts will be made to parse the
    99      * values as though it is in the GMT {@link TimeZone}.
     137     * Parses the date/time tag, the subsecond tag and the time offset tag to obtain a single Date
     138     * object with milliseconds representing the date and time when this image was digitized.  If
     139     * the time offset tag does not exist, attempts will be made to parse the values as though it is
     140     * in the GMT {@link TimeZone}.
    100141     *
    101142     * @return A Date object representing when this image was digitized, if possible, otherwise null
     
    108149
    109150    /**
    110      * Parses the date/time tag and the subsecond tag to obtain a single Date object with milliseconds
    111      * representing the date and time when this image was digitized.  Attempts will be made to parse the
    112      * values as though it is in the {@link TimeZone} represented by the {@code timeZone} parameter
    113      * (if it is non-null).
     151     * Parses the date/time tag, the subsecond tag and the time offset tag to obtain a single Date
     152     * object with milliseconds representing the date and time when this image was digitized.  If
     153     * the time offset tag does not exist, attempts will be made to parse the values as though it is
     154     * in the {@link TimeZone} represented by the {@code timeZone} parameter (if it is non-null).
    114155     *
    115156     * @param timeZone the time zone to use
     
    119160    public Date getDateDigitized(@Nullable TimeZone timeZone)
    120161    {
    121         return getDate(TAG_DATETIME_DIGITIZED, getString(TAG_SUBSECOND_TIME_DIGITIZED), timeZone);
     162        TimeZone timeZoneDigitized = getTimeZone(TAG_OFFSET_TIME_DIGITIZED);
     163        return getDate(TAG_DATETIME_DIGITIZED, getString(TAG_SUBSECOND_TIME_DIGITIZED),
     164            (timeZoneDigitized != null) ? timeZoneDigitized : timeZone);
     165    }
     166
     167    @Nullable
     168    private TimeZone getTimeZone(int tagType)
     169    {
     170        String timeOffset = getString(tagType);
     171        if (timeOffset != null && timeOffset.matches("[\\+\\-]\\d\\d:\\d\\d")) {
     172            return TimeZone.getTimeZone("GMT" + timeOffset);
     173        } else {
     174            return null;
     175        }
    122176    }
    123177}
Note: See TracChangeset for help on using the changeset viewer.