diff --git a/src/convert.cpp b/src/convert.cpp index f56a933150..038d86bfbb 100644 --- a/src/convert.cpp +++ b/src/convert.cpp @@ -855,68 +855,68 @@ namespace Exiv2 { XMP_DateTime datetime; try { SXMPUtils::ConvertToDate(value, &datetime); - char buf[30]; - if (std::string(to) != "Exif.GPSInfo.GPSTimeStamp") { - - SXMPUtils::ConvertToLocalTime(&datetime); - - snprintf(buf, sizeof(buf), "%4d:%02d:%02d %02d:%02d:%02d", - static_cast(datetime.year), - static_cast(datetime.month), - static_cast(datetime.day), - static_cast(datetime.hour), - static_cast(datetime.minute), - static_cast(datetime.second)); - buf[sizeof(buf) - 1] = 0; - (*exifData_)[to] = buf; - - if (datetime.nanoSecond) { - const char* subsecTag = 0; - if (std::string(to) == "Exif.Image.DateTime") { - subsecTag = "Exif.Photo.SubSecTime"; - } - else if (std::string(to) == "Exif.Photo.DateTimeOriginal") { - subsecTag = "Exif.Photo.SubSecTimeOriginal"; - } - else if (std::string(to) == "Exif.Photo.DateTimeDigitized") { - subsecTag = "Exif.Photo.SubSecTimeDigitized"; - } - if (subsecTag) { - prepareExifTarget(subsecTag, true); - (*exifData_)[subsecTag] = toString(datetime.nanoSecond); + char buf[30]; + if (std::string(to) != "Exif.GPSInfo.GPSTimeStamp") { + + SXMPUtils::ConvertToLocalTime(&datetime); + + snprintf(buf, sizeof(buf), "%4d:%02d:%02d %02d:%02d:%02d", + static_cast(datetime.year), + static_cast(datetime.month), + static_cast(datetime.day), + static_cast(datetime.hour), + static_cast(datetime.minute), + static_cast(datetime.second)); + buf[sizeof(buf) - 1] = 0; + (*exifData_)[to] = buf; + + if (datetime.nanoSecond) { + const char* subsecTag = 0; + if (std::string(to) == "Exif.Image.DateTime") { + subsecTag = "Exif.Photo.SubSecTime"; + } + else if (std::string(to) == "Exif.Photo.DateTimeOriginal") { + subsecTag = "Exif.Photo.SubSecTimeOriginal"; + } + else if (std::string(to) == "Exif.Photo.DateTimeDigitized") { + subsecTag = "Exif.Photo.SubSecTimeDigitized"; + } + if (subsecTag) { + prepareExifTarget(subsecTag, true); + (*exifData_)[subsecTag] = toString(datetime.nanoSecond); + } } } - } - else { // "Exif.GPSInfo.GPSTimeStamp" - - // Ignore the time zone, assuming the time is in UTC as it should be - - URational rhour(datetime.hour, 1); - URational rmin(datetime.minute, 1); - URational rsec(datetime.second, 1); - if (datetime.nanoSecond != 0) { - if (datetime.second != 0) { - // Add the seconds to rmin so that the ns fit into rsec - rmin.second = 60; - rmin.first *= 60; - rmin.first += datetime.second; + else { // "Exif.GPSInfo.GPSTimeStamp" + + // Ignore the time zone, assuming the time is in UTC as it should be + + URational rhour(datetime.hour, 1); + URational rmin(datetime.minute, 1); + URational rsec(datetime.second, 1); + if (datetime.nanoSecond != 0) { + if (datetime.second != 0) { + // Add the seconds to rmin so that the ns fit into rsec + rmin.second = 60; + rmin.first *= 60; + rmin.first += datetime.second; + } + rsec.second = 1000000000; + rsec.first = datetime.nanoSecond; } - rsec.second = 1000000000; - rsec.first = datetime.nanoSecond; - } - - std::ostringstream array; - array << rhour << " " << rmin << " " << rsec; - (*exifData_)[to] = array.str(); - prepareExifTarget("Exif.GPSInfo.GPSDateStamp", true); - snprintf(buf, sizeof(buf), "%4d:%02d:%02d", - static_cast(datetime.year), - static_cast(datetime.month), - static_cast(datetime.day)); - buf[sizeof(buf) - 1] = 0; - (*exifData_)["Exif.GPSInfo.GPSDateStamp"] = buf; - } + std::ostringstream array; + array << rhour << " " << rmin << " " << rsec; + (*exifData_)[to] = array.str(); + + prepareExifTarget("Exif.GPSInfo.GPSDateStamp", true); + snprintf(buf, sizeof(buf), "%4d:%02d:%02d", + static_cast(datetime.year), + static_cast(datetime.month), + static_cast(datetime.day)); + buf[sizeof(buf) - 1] = 0; + (*exifData_)["Exif.GPSInfo.GPSDateStamp"] = buf; + } } #ifndef SUPPRESS_WARNINGS catch (const XMP_Error& e) {