Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
liujiayi771 committed Nov 1, 2024
1 parent 80e58d1 commit bee83b3
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions velox/type/TimestampConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,8 @@ inline bool characterIsDigit(char c) {
return c >= '0' && c <= '9';
}

inline bool
allCharactersIsDigit(std::string_view str, size_t start, size_t end) {
if (start > end || end >= str.size()) {
return false;
}
return std::all_of(
str.begin() + start, str.begin() + end + 1, characterIsDigit);
}

inline bool allCharactersIsDigit(std::string_view str) {
return allCharactersIsDigit(str, 0, str.length() - 1);
return std::all_of(str.begin(), str.end(), characterIsDigit);
}

bool parseDoubleDigit(
Expand Down Expand Up @@ -864,16 +855,16 @@ bool parseSparkTzWithPrefix(std::string& timeZoneName, Timestamp& ts) {
appendZeroMinutes = true;
} else if (
(offset.length() == 4 && allCharactersIsDigit(offset)) ||
(offset.length() == 5 && allCharactersIsDigit(offset, 0, 1) &&
allCharactersIsDigit(offset, 3, 4))) {
(offset.length() == 5 && allCharactersIsDigit(offset.substr(0, 2)) &&
allCharactersIsDigit(offset.substr(3, 2)))) {
// hh[:]mm
// TimeZoneMap::normalizeTimeZoneOffset will normalize hhmm to hh:mm
hm = offset;
} else if (
(offset.length() == 6 && allCharactersIsDigit(offset)) ||
(offset.length() == 8 && allCharactersIsDigit(offset, 0, 1) &&
allCharactersIsDigit(offset, 3, 4) &&
allCharactersIsDigit(offset, 6, 7))) {
(offset.length() == 8 && allCharactersIsDigit(offset.substr(0, 2)) &&
allCharactersIsDigit(offset.substr(3, 2)) &&
allCharactersIsDigit(offset.substr(6, 2)))) {
// hh:mm:ss, hhmmss
auto lastSep = offset.rfind(':');
if (lastSep == std::string::npos && offset.length() == 6) {
Expand Down Expand Up @@ -1046,7 +1037,7 @@ fromTimestampWithTimezoneString(
}

std::string_view timeZoneName(str + pos, timezonePos - pos);
std::string normalizeTzName = std::string{timeZoneName};
std::string normalizeTzName{timeZoneName};
if (parseMode == TimestampParseMode::kSparkCast &&
!normalizeSparkTimezone(normalizeTzName, resultTimestamp)) {
return folly::makeUnexpected(Status::UserError(
Expand Down

0 comments on commit bee83b3

Please sign in to comment.