Skip to content

Commit

Permalink
support no month/day (oap-project#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
marin-ma authored and zhejiangxiaomai committed Mar 29, 2023
1 parent e092a41 commit b17a149
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions velox/type/TimestampConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,13 @@ bool tryParseDateString(
}
}

if (pos >= len) {
// No month or day.
if (pos == len) {
daysSinceEpoch = daysSinceEpochFromDate(year, 1, 1);
return true;
}

if (pos > len) {
return false;
}

Expand All @@ -207,7 +213,13 @@ bool tryParseDateString(
return false;
}

if (pos >= len) {
// No day.
if (pos == len) {
daysSinceEpoch = daysSinceEpochFromDate(year, month, 1);
return true;
}

if (pos > len) {
return false;
}

Expand Down Expand Up @@ -240,13 +252,25 @@ bool tryParseDateString(

// In strict mode, check remaining string for non-space characters.
if (strict) {
// Skip trailing spaces.
while (pos < len && characterIsSpace(buf[pos])) {
// Check for an optional trailing 'T' followed by optional digits.
if (pos < len && buf[pos] == 'T') {
pos++;
}
// Check position. if end was not reached, non-space chars remaining.
if (pos < len) {
return false;
while (pos < len && characterIsDigit(buf[pos])) {
pos++;
}
} else {
// Skip trailing spaces.
while (pos < len && characterIsSpace(buf[pos])) {
pos++;
}
// Skip trailing digits after spaces.
while (pos < len && characterIsDigit(buf[pos])) {
pos++;
}
// Check position. if end was not reached, non-space chars remaining.
if (pos < len) {
return false;
}
}
} else {
// In non-strict mode, check for any direct trailing digits.
Expand Down

0 comments on commit b17a149

Please sign in to comment.