mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 15:42:14 +00:00
Error checks
This commit is contained in:
parent
dca746ad08
commit
5e5866ba21
1 changed files with 12 additions and 0 deletions
|
@ -1152,6 +1152,9 @@ DateInfo StandardFunctions::DateTime::createDateInfoFromString(const UnicodeStri
|
|||
if (!hasTimeZone) {
|
||||
// No time zone; parse the date and time
|
||||
absoluteDate = tryPatterns(sourceStr, errorCode);
|
||||
if (U_FAILURE(errorCode)) {
|
||||
return {};
|
||||
}
|
||||
} else {
|
||||
// Try to split into time zone and non-time-zone parts
|
||||
UnicodeString dateTimePart;
|
||||
|
@ -1170,9 +1173,15 @@ DateInfo StandardFunctions::DateTime::createDateInfoFromString(const UnicodeStri
|
|||
if (isGMT) {
|
||||
dateTimePart += UnicodeString("GMT");
|
||||
absoluteDate = tryTimeZonePatterns(dateTimePart, errorCode);
|
||||
if (U_FAILURE(errorCode)) {
|
||||
return {};
|
||||
}
|
||||
} else {
|
||||
// Try to parse time zone in offset format: [+-]nn:nn
|
||||
absoluteDate = tryTimeZonePatterns(sourceStr, errorCode);
|
||||
if (U_FAILURE(errorCode)) {
|
||||
return {};
|
||||
}
|
||||
offsetPart = sourceStr.tempSubString(indexOfSign, sourceStr.length());
|
||||
}
|
||||
}
|
||||
|
@ -1186,6 +1195,9 @@ DateInfo StandardFunctions::DateTime::createDateInfoFromString(const UnicodeStri
|
|||
tzID += offsetPart;
|
||||
}
|
||||
TimeZone::getCanonicalID(tzID, canonicalID, errorCode);
|
||||
if (U_FAILURE(errorCode)) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
return { absoluteDate, canonicalID };
|
||||
|
|
Loading…
Add table
Reference in a new issue