Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Add the parser to parse time. #249

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8223d65
Add the parser to parse time.
Shylock-Hg Sep 24, 2020
a004ba9
Add a test case about parse datatime.
Shylock-Hg Sep 29, 2020
bfaea61
Merge branch 'master' into feature/time-parser
Shylock-Hg Oct 22, 2020
bfcd005
Merge branch 'master' of github.com:vesoft-inc/nebula-common into fea…
Shylock-Hg Oct 26, 2020
35a5bd2
Using the parser to parse time literal.
Shylock-Hg Oct 26, 2020
4a4bdfc
Merge branch 'master' into feature/time-parser
Shylock-Hg Nov 17, 2020
e2c3737
Merge branch 'master' into feature/time-parser
Shylock-Hg Mar 5, 2021
b8e55f0
Merge branch 'master' into feature/time-parser
Shylock-Hg Apr 23, 2021
e4529dc
Add the offset support.
Shylock-Hg Apr 23, 2021
14fd406
Add the time zone name support.
Shylock-Hg Apr 25, 2021
00f0f35
Merge branch 'master' into feature/time-parser
Shylock-Hg Apr 25, 2021
37901ac
Split the time zone datebase and time zone initialization.
Shylock-Hg Apr 25, 2021
c66681b
Store the info by Context in parser.
Shylock-Hg Apr 25, 2021
8bc521d
Support the time zone name and utc offset together.
Shylock-Hg Apr 26, 2021
0fdab55
Fix the compile error.
Shylock-Hg Apr 26, 2021
2832152
Merge branch 'master' into feature/time-parser
Shylock-Hg Apr 29, 2021
796505e
Merge branch 'master' into feature/time-parser
Shylock-Hg May 8, 2021
dbb1256
Merge branch 'master' into feature/time-parser
Shylock-Hg May 12, 2021
89eb0ca
Merge branch 'master' into feature/time-parser
Shylock-Hg May 25, 2021
a97cbde
Merge branch 'master' into feature/time-parser
Shylock-Hg Jun 3, 2021
b7f0842
Process the sub second.
Shylock-Hg Jun 3, 2021
51999d6
Merge branch 'feature/time-parser' of github.com:Shylock-Hg/nebula-co…
Shylock-Hg Jun 3, 2021
81cb326
Fix the compile warning.
Shylock-Hg Jun 3, 2021
e804419
Merge branch 'master' into feature/time-parser
Shylock-Hg Jun 4, 2021
d542021
Merge branch 'master' into feature/time-parser
Shylock-Hg Jun 17, 2021
82bc034
Merge branch 'master' into feature/time-parser
Shylock-Hg Jun 18, 2021
cdc71e6
Merge branch 'master' into feature/time-parser
Shylock-Hg Jul 5, 2021
6901222
Merge branch 'master' into feature/time-parser
Shylock-Hg Jul 19, 2021
390c5ec
Correct the timezone conversion.
Shylock-Hg Jul 19, 2021
0211404
Fix the case.
Shylock-Hg Jul 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/common/algorithm/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
nebula_add_test(
NAME reservoir_sampling_test
SOURCES ReservoirSamplingTest.cpp
OBJECTS $<TARGET_OBJECTS:time_obj>
OBJECTS
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:time_obj>
LIBRARIES gtest gtest_main
)
1 change: 1 addition & 0 deletions src/common/concurrent/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ nebula_add_test(
SOURCES
BarrierTest.cpp LatchTest.cpp
OBJECTS
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:concurrent_obj>
$<TARGET_OBJECTS:thread_obj>
$<TARGET_OBJECTS:time_obj>
Expand Down
15 changes: 12 additions & 3 deletions src/common/datatypes/Date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

namespace nebula {

static inline std::string decimal(const std::string &number) {
auto find = std::find(number.begin(), number.end(), '.');
return std::string(find, number.end());
}

const int64_t kDaysSoFar[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
const int64_t kLeapDaysSoFar[] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366};

Expand Down Expand Up @@ -101,21 +106,25 @@ std::string Date::toString() const {
}

std::string Time::toString() const {
auto microsecStr = folly::stringPrintf("%.9f", static_cast<uint32_t>(microsec) / 1000000.0);
auto decimalPart = decimal(microsecStr);
// It's in current timezone already
return folly::stringPrintf("%02d:%02d:%02d.%06d", hour, minute, sec, microsec);
return folly::stringPrintf("%02d:%02d:%02d%s", hour, minute, sec, decimalPart.c_str());
}

std::string DateTime::toString() const {
auto microsecStr = folly::stringPrintf("%.9f", static_cast<uint32_t>(microsec) / 1000000.0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we keep 9 digits for ms instead of 6? Nebula's time precision is different from openCypher.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference? They are both fraction of second.

auto decimalPart = decimal(microsecStr);
// It's in current timezone already
return folly::stringPrintf("%hd-%02hhu-%02hhu"
"T%02hhu:%02hhu:%02hhu.%u",
"T%02hhu:%02hhu:%02hhu%s",
static_cast<int16_t>(year),
static_cast<uint8_t>(month),
static_cast<uint8_t>(day),
static_cast<uint8_t>(hour),
static_cast<uint8_t>(minute),
static_cast<uint8_t>(sec),
static_cast<uint32_t>(microsec));
decimalPart.c_str());
}

} // namespace nebula
Expand Down
2 changes: 1 addition & 1 deletion src/common/function/test/FunctionManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ TEST_F(FunctionManagerTest, functionCall) {
TEST_FUNCTION(toString, args_["toString_bool"], "true");
TEST_FUNCTION(toString, args_["string"], "AbcDeFG");
TEST_FUNCTION(toString, args_["date"], "1984-10-11");
TEST_FUNCTION(toString, args_["datetime"], "1984-10-11T12:31:14.341");
TEST_FUNCTION(toString, args_["datetime"], "1984-10-11T12:31:14.000341000");
TEST_FUNCTION(toString, args_["nullvalue"], Value::kNullValue);
}
{
Expand Down
1 change: 1 addition & 0 deletions src/common/thread/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ nebula_add_test(
GenericWorkerTest.cpp
GenericThreadPoolTest.cpp
OBJECTS
$<TARGET_OBJECTS:base_obj>
$<TARGET_OBJECTS:thread_obj>
$<TARGET_OBJECTS:concurrent_obj>
$<TARGET_OBJECTS:time_obj>
Expand Down
1 change: 1 addition & 0 deletions src/common/time/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ nebula_add_library(
time_utils_obj OBJECT
TimeUtils.cpp
TimezoneInfo.cpp
TimeParser.cpp
TimeConversion.cpp
)

Expand Down
Loading