Fix handling empty ID3v2 record date fields to avoid year "0001" in this case
This commit is contained in:
parent
a6ca3183b3
commit
87357af974
|
@ -362,8 +362,10 @@ void Id3v2Tag::convertOldRecordDateFields(const std::string &diagContext, Diagno
|
|||
}
|
||||
|
||||
// parse values of lYear/lRecordingDates/lDate/lTime/sYear/sRecordingDates/sDate/sTime fields
|
||||
bool hasAnyValue = false;
|
||||
int year = 1, month = 1, day = 1, hour = 0, minute = 0;
|
||||
if (const auto &v = value(Id3v2FrameIds::lYear)) {
|
||||
hasAnyValue = true;
|
||||
try {
|
||||
year = v.toInteger();
|
||||
} catch (const ConversionException &e) {
|
||||
|
@ -371,6 +373,7 @@ void Id3v2Tag::convertOldRecordDateFields(const std::string &diagContext, Diagno
|
|||
}
|
||||
}
|
||||
if (const auto &v = value(Id3v2FrameIds::lDate)) {
|
||||
hasAnyValue = true;
|
||||
try {
|
||||
auto str = v.toString();
|
||||
if (str.size() != 4) {
|
||||
|
@ -383,6 +386,7 @@ void Id3v2Tag::convertOldRecordDateFields(const std::string &diagContext, Diagno
|
|||
}
|
||||
}
|
||||
if (const auto &v = value(Id3v2FrameIds::lTime)) {
|
||||
hasAnyValue = true;
|
||||
try {
|
||||
auto str = v.toString();
|
||||
if (str.size() != 4) {
|
||||
|
@ -396,6 +400,9 @@ void Id3v2Tag::convertOldRecordDateFields(const std::string &diagContext, Diagno
|
|||
}
|
||||
|
||||
// set the field values as DateTime
|
||||
if (!hasAnyValue) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
setValue(Id3v2FrameIds::lRecordingTime, TagValue(DateTime::fromDateAndTime(year, month, day, hour, minute)));
|
||||
} catch (const ConversionException &e) {
|
||||
|
|
Loading…
Reference in New Issue