diff options
author | Marco Nelissen <marcone@google.com> | 2015-05-29 14:49:03 -0700 |
---|---|---|
committer | Marco Nelissen <marcone@google.com> | 2015-05-29 14:49:03 -0700 |
commit | b2c890044ed975ab091db0443665ecce293515d4 (patch) | |
tree | ee8898892822cbfc56ee83159965be5b78f21b3e /media/java/android/media/ExifInterface.java | |
parent | 25fc117a358ecef3b97787c0847265d7f363ccae (diff) | |
download | frameworks_base-b2c890044ed975ab091db0443665ecce293515d4.zip frameworks_base-b2c890044ed975ab091db0443665ecce293515d4.tar.gz frameworks_base-b2c890044ed975ab091db0443665ecce293515d4.tar.bz2 |
Update ExifInterface.getDateTime to support subseconds
Also document that it returns local time.
Bug: 20638367
Change-Id: I6a1c35925e0555bcdcb079be0ca5b19a279a05a6
Diffstat (limited to 'media/java/android/media/ExifInterface.java')
-rw-r--r-- | media/java/android/media/ExifInterface.java | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java index 9db35fc..aa5d43a 100644 --- a/media/java/android/media/ExifInterface.java +++ b/media/java/android/media/ExifInterface.java @@ -59,6 +59,11 @@ public class ExifInterface { public static final String TAG_ISO = "ISOSpeedRatings"; /** + * @hide + */ + public static final String TAG_SUBSECTIME = "SubSecTime"; + + /** * The altitude (in meters) based on the reference in TAG_GPS_ALTITUDE_REF. * Type is rational. */ @@ -346,7 +351,7 @@ public class ExifInterface { } /** - * Returns number of milliseconds since Jan. 1, 1970, midnight. + * Returns number of milliseconds since Jan. 1, 1970, midnight local time. * Returns -1 if the date time information if not available. * @hide */ @@ -356,9 +361,24 @@ public class ExifInterface { ParsePosition pos = new ParsePosition(0); try { + // The exif field is in local time. Parsing it as if it is UTC will yield time + // since 1/1/1970 local time Date datetime = sFormatter.parse(dateTimeString, pos); if (datetime == null) return -1; - return datetime.getTime(); + long msecs = datetime.getTime(); + + String subSecs = mAttributes.get(TAG_SUBSECTIME); + if (subSecs != null) { + try { + long sub = Long.valueOf(subSecs); + while (sub > 1000) { + sub /= 10; + } + msecs += sub; + } catch (NumberFormatException e) { + } + } + return msecs; } catch (IllegalArgumentException ex) { return -1; } @@ -375,7 +395,6 @@ public class ExifInterface { if (date == null || time == null) return -1; String dateTimeString = date + ' ' + time; - if (dateTimeString == null) return -1; ParsePosition pos = new ParsePosition(0); try { |