Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ add_dependencies(${GFLAGS_LIBRARY} gflags-proj)
ExternalProject_Add(mgclient-proj
PREFIX mgclient
GIT_REPOSITORY https://github.com/memgraph/mgclient.git
GIT_TAG v1.4.4
GIT_TAG v1.5.0
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>"
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
Expand Down
36 changes: 36 additions & 0 deletions src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cstdint>
#include <ios>
#include <iostream>
#include <iomanip>
#include <ostream>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -290,6 +291,35 @@ void PrintValue(std::ostream &os, const mg_local_date_time *local_date_time) {
PrintValue(os, time);
}

void PrintDateTimeComponents(std::ostream &os, int64_t seconds, int64_t nanoseconds) {
namespace chrono = std::chrono;
auto const secs = chrono::seconds(seconds);
auto const days = chrono::duration_cast<date::days>(secs);
auto const date = mg_date_make(days.count());

auto const nanos =
chrono::duration_cast<chrono::nanoseconds>(secs) - chrono::duration_cast<chrono::nanoseconds>(days);
auto const time = mg_local_time_make(nanos.count() + nanoseconds);

PrintValue(os, date);
os << " ";
PrintValue(os, time);
}

void PrintValue(std::ostream &os, const mg_date_time *date_time) {
PrintDateTimeComponents(os, mg_date_time_seconds(date_time), mg_date_time_nanoseconds(date_time));
auto const minutes = mg_date_time_tz_offset_minutes(date_time);
os << (minutes >= 0 ? '+' : '-') << std::setfill('0') << std::setw(2) << (std::abs(minutes) / 60) << ":"
<< std::setfill('0') << std::setw(2) << (std::abs(minutes) % 60);
}

void PrintValue(std::ostream &os, const mg_date_time_zone_id *date_time_zone_id) {
PrintDateTimeComponents(os, mg_date_time_zone_id_seconds(date_time_zone_id), mg_date_time_zone_id_nanoseconds(date_time_zone_id));
os << "[";
PrintStringUnescaped(os, mg_date_time_zone_id_timezone_name(date_time_zone_id));
os << "]";
}

void PrintSeconds(std::ostream &os, std::chrono::seconds ss, std::chrono::microseconds mis) {
if (ss.count() == 0 && mis.count() < 0) {
os << '-';
Expand Down Expand Up @@ -403,6 +433,12 @@ void PrintValue(std::ostream &os, const mg_value *value) {
case MG_VALUE_TYPE_POINT_3D:
PrintValue(os, mg_value_point_3d(value));
return;
case MG_VALUE_TYPE_DATE_TIME:
PrintValue(os, mg_value_date_time(value));
return;
case MG_VALUE_TYPE_DATE_TIME_ZONE_ID:
PrintValue(os, mg_value_date_time_zone_id(value));
return;
default:
os << "{unknown value}";
break;
Expand Down
7 changes: 7 additions & 0 deletions tests/input_output/input/temporal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ RETURN localdatetime({year: 2000, day: 23, hour: 12, second: 21});
RETURN duration({day: 23, hour: 100, second: 21});
RETURN duration({second: 0, microsecond: -123});
RETURN duration("P1DT48H61M79.123S");
RETURN datetime("2024-04-21T14:15:00-07:00[America/Los_Angeles]");
RETURN datetime("2024-04-21T14:15:00+07:30");
RETURN datetime("2024-04-21T14:15:00-05:45");
RETURN datetime("2021-04-21T14:15:00Z");
RETURN datetime({year: 2024, month: 4, day: 21, hour: 14, minute: 15, timezone: "America/Los_Angeles"});
RETURN datetime({year: 2021, month: 4, day: 21, hour: 14, minute: 15, timezone: -60});
RETURN datetime({year: 2021, month: 4, day: 21, hour: 14, minute: 15, timezone: 90});
14 changes: 14 additions & 0 deletions tests/input_output/output_csv/temporal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@
"P-0.000123S"
"duration(""P1DT48H61M79.123S"")"
"P3DT1H2M19.123000S"
"datetime(""2024-04-21T14:15:00-07:00[America/Los_Angeles]"")"
"2024-04-21 14:15:00.000000000[America/Los_Angeles]"
"datetime(""2024-04-21T14:15:00+07:30"")"
"2024-04-21 14:15:00.000000000+07:30"
"datetime(""2024-04-21T14:15:00-05:45"")"
"2024-04-21 14:15:00.000000000-05:45"
"datetime(""2021-04-21T14:15:00Z"")"
"2021-04-21 14:15:00.000000000[Etc/UTC]"
"datetime({year: 2024, month: 4, day: 21, hour: 14, minute: 15, timezone: ""America/Los_Angeles""})"
"2024-04-21 14:15:00.000000000[America/Los_Angeles]"
"datetime({year: 2021, month: 4, day: 21, hour: 14, minute: 15, timezone: -60})"
"2021-04-21 14:15:00.000000000-01:00"
"datetime({year: 2021, month: 4, day: 21, hour: 14, minute: 15, timezone: 90})"
"2021-04-21 14:15:00.000000000+01:30"
35 changes: 35 additions & 0 deletions tests/input_output/output_tabular/temporal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,38 @@
+-------------------------------+
| P3DT1H2M19.123000S |
+-------------------------------+
+------------------------------------------------------------+
| datetime("2024-04-21T14:15:00-07:00[America/Los_Angeles]") |
+------------------------------------------------------------+
| 2024-04-21 14:15:00.000000000[America/Los_Angeles] |
+------------------------------------------------------------+
+---------------------------------------+
| datetime("2024-04-21T14:15:00+07:30") |
+---------------------------------------+
| 2024-04-21 14:15:00.000000000+07:30 |
+---------------------------------------+
+---------------------------------------+
| datetime("2024-04-21T14:15:00-05:45") |
+---------------------------------------+
| 2024-04-21 14:15:00.000000000-05:45 |
+---------------------------------------+
+----------------------------------------+
| datetime("2021-04-21T14:15:00Z") |
+----------------------------------------+
| 2021-04-21 14:15:00.000000000[Etc/UTC] |
+----------------------------------------+
+--------------------------------------------------------------------------------------------------+
| datetime({year: 2024, month: 4, day: 21, hour: 14, minute: 15, timezone: "America/Los_Angeles"}) |
+--------------------------------------------------------------------------------------------------+
| 2024-04-21 14:15:00.000000000[America/Los_Angeles] |
+--------------------------------------------------------------------------------------------------+
+--------------------------------------------------------------------------------+
| datetime({year: 2021, month: 4, day: 21, hour: 14, minute: 15, timezone: -60}) |
+--------------------------------------------------------------------------------+
| 2021-04-21 14:15:00.000000000-01:00 |
+--------------------------------------------------------------------------------+
+-------------------------------------------------------------------------------+
| datetime({year: 2021, month: 4, day: 21, hour: 14, minute: 15, timezone: 90}) |
+-------------------------------------------------------------------------------+
| 2021-04-21 14:15:00.000000000+01:30 |
+-------------------------------------------------------------------------------+
1 change: 1 addition & 0 deletions tests/input_output/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ $memgraph_binary --bolt-port 7687 \
--data-recovery-on-startup=false \
--storage-snapshot-on-exit=false \
--telemetry-enabled=false \
--timezone=UTC \
--log-file='' &

pid=$!
Expand Down
Loading