blob: 309ed9978f0106678ac55c24a835a4e1580ce114 [file] [log] [blame]
diff --git a/src/ptp-pack.c b/src/ptp-pack.c
index 5319525..1f8c2cb 100644
--- a/src/ptp-pack.c
+++ b/src/ptp-pack.c
@@ -675,6 +675,7 @@ ptp_unpack_PTPTIME (const char *str) {
char ptpdate[40];
char tmp[5];
size_t ptpdatelen;
+ size_t tzoffs;
struct tm tm;
if (!str)
@@ -711,6 +712,31 @@ ptp_unpack_PTPTIME (const char *str) {
tmp[2] = 0;
tm.tm_sec = atoi (tmp);
tm.tm_isdst = -1;
+ /* Check for optional '.s' (tenths of a second) and skip */
+ /* MTP spec v1.1 section 3.2.5 */
+ tzoffs = 15;
+ if (ptpdate[tzoffs] == '.' && ptpdate[tzoffs + 1] != '\0') {
+ tzoffs += 2;
+ }
+ /* Check for 'Z' (UTC time) */
+ if (ptpdate[tzoffs] == 'Z') {
+ return timegm (&tm);
+ }
+ /* Check for timezone offset [+/-HHMM] */
+ if (strlen(ptpdate + tzoffs) == 5) {
+ time_t tz = 0;
+ strncpy (tmp, ptpdate + tzoffs + 1, 2);
+ tmp[2] = 0;
+ tz = atoi (tmp) * 60 * 60;
+ strncpy (tmp, ptpdate + tzoffs + 3, 2);
+ tmp[2] = 0;
+ tz += atoi (tmp) * 60;
+ if (ptpdate[tzoffs] == '-') {
+ return timegm (&tm) + tz;
+ }
+ return timegm (&tm) - tz;
+ }
+ /* Unspecified timezone, use local time */
return mktime (&tm);
}
@@ -755,7 +781,7 @@ ptp_unpack_OI (PTPParams *params, unsigned char* data, PTPObjectInfo *oi, unsign
capture_date = ptp_unpack_string(params, data,
PTP_oi_filenamelen+filenamelen*2+1, len, &capturedatelen);
- /* subset of ISO 8601, without '.s' tenths of second and
+ /* subset of ISO 8601, with optional '.s' tenths of second and
* time zone
*/
oi->CaptureDate = ptp_unpack_PTPTIME(capture_date);