Skip to content

Commit

Permalink
Improve tmToString and relating document (#8250)
Browse files Browse the repository at this point in the history
Summary:
Add examples for `skipTrailingZeros` and `zeroPaddingYear`. Skip an extra
branch when `skipTrailingZeros` is disabled.

Pull Request resolved: #8250

Reviewed By: amitkdutta

Differential Revision: D52531337

Pulled By: mbasmanova

fbshipit-source-id: b0a866962c9631fbf21b1a8f3634f581a498c7fa
  • Loading branch information
rui-mo authored and facebook-github-bot committed Jan 4, 2024
1 parent 0e25d47 commit a289ac7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 1 addition & 5 deletions velox/type/Timestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,7 @@ std::string Timestamp::tmToString(
}
} else {
while (nanos > 0) {
if (nanos % 10 == 0) {
out += '0';
} else {
out += '0' + nanos % 10;
}
out += '0' + nanos % 10;
nanos /= 10;
}
}
Expand Down
8 changes: 6 additions & 2 deletions velox/type/Timestamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ struct TimestampToStringOptions {
// Whether to add a leading '+' when year is greater than 9999.
bool leadingPositiveSign = false;

// Whether to skip trailing zeros of fractional part.
/// Whether to skip trailing zeros of fractional part. E.g. when true,
/// '2000-01-01 12:21:56.129000' becomes '2000-01-01 12:21:56.129'.
bool skipTrailingZeros = false;

// Whether padding zeros are added when the digits of year is less than 4.
/// Whether padding zeros are added when the digits of year is less than 4.
/// E.g. when true, '1-01-01 05:17:32.000' becomes '0001-01-01 05:17:32.000',
/// '-03-24 13:20:00.000' becomes '0000-03-24 13:20:00.000', and '-1-11-29
/// 19:33:20.000' becomes '-0001-11-29 19:33:20.000'.
bool zeroPaddingYear = false;

// The separator of date and time.
Expand Down

0 comments on commit a289ac7

Please sign in to comment.