Ignore:
Timestamp:
2016-08-20T20:58:03+02:00 (8 years ago)
Author:
Don-vip
Message:

update to metadata-extractor 2.9.1

File:
1 edited

Legend:

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

    r8243 r10862  
    11/*
    2  * Copyright 2002-2015 Drew Noakes
     2 * Copyright 2002-2016 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    2626import com.drew.lang.annotations.Nullable;
    2727
     28import java.text.DateFormat;
     29import java.text.ParseException;
     30import java.text.SimpleDateFormat;
     31import java.util.Date;
    2832import java.util.HashMap;
     33import java.util.Locale;
    2934
    3035/**
     
    164169    public GeoLocation getGeoLocation()
    165170    {
    166         Rational[] latitudes = getRationalArray(GpsDirectory.TAG_LATITUDE);
    167         Rational[] longitudes = getRationalArray(GpsDirectory.TAG_LONGITUDE);
    168         String latitudeRef = getString(GpsDirectory.TAG_LATITUDE_REF);
    169         String longitudeRef = getString(GpsDirectory.TAG_LONGITUDE_REF);
     171        Rational[] latitudes = getRationalArray(TAG_LATITUDE);
     172        Rational[] longitudes = getRationalArray(TAG_LONGITUDE);
     173        String latitudeRef = getString(TAG_LATITUDE_REF);
     174        String longitudeRef = getString(TAG_LONGITUDE_REF);
    170175
    171176        // Make sure we have the required values
     
    186191        return new GeoLocation(lat, lon);
    187192    }
     193
     194    /**
     195     * Parses the date stamp tag and the time stamp tag to obtain a single Date object representing the
     196     * date and time when this image was captured.
     197     *
     198     * @return A Date object representing when this image was captured, if possible, otherwise null
     199     */
     200    @Nullable
     201    public Date getGpsDate()
     202    {
     203        String date = getString(TAG_DATE_STAMP);
     204        Rational[] timeComponents = getRationalArray(TAG_TIME_STAMP);
     205
     206        // Make sure we have the required values
     207        if (date == null)
     208            return null;
     209        if (timeComponents == null || timeComponents.length != 3)
     210            return null;
     211
     212        String dateTime = String.format(Locale.US, "%s %02d:%02d:%02.3f UTC",
     213            date, timeComponents[0].intValue(), timeComponents[1].intValue(), timeComponents[2].doubleValue());
     214        try {
     215            DateFormat parser = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss.S z");
     216            return parser.parse(dateTime);
     217        } catch (ParseException e) {
     218            return null;
     219        }
     220    }
    188221}
Note: See TracChangeset for help on using the changeset viewer.