Kùzu C++ API
Loading...
Searching...
No Matches
dtime_t.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <string>
5
6#include "api.h"
7
8namespace kuzu {
9namespace common {
10
11// Type used to represent time (microseconds)
13 int64_t micros;
14
16 explicit dtime_t(int64_t micros_p);
17 dtime_t& operator=(int64_t micros_p);
18
19 // explicit conversion
20 explicit operator int64_t() const;
21 explicit operator double() const;
22
23 // comparison operators
24 bool operator==(const dtime_t& rhs) const;
25 bool operator!=(const dtime_t& rhs) const;
26 bool operator<=(const dtime_t& rhs) const;
27 bool operator<(const dtime_t& rhs) const;
28 bool operator>(const dtime_t& rhs) const;
29 bool operator>=(const dtime_t& rhs) const;
30};
31
32// Note: Aside from some minor changes, this implementation is copied from DuckDB's source code:
33// https://github.com/duckdb/duckdb/blob/master/src/include/duckdb/common/types/time.hpp.
34// https://github.com/duckdb/duckdb/blob/master/src/common/types/time.cpp.
35// For example, instead of using their idx_t type to refer to indices, we directly use uint64_t,
36// which is the actual type of idx_t (so we say uint64_t len instead of idx_t len). When more
37// functionality is needed, we should first consult these DuckDB links.
38class Time {
39public:
40 // Convert a string in the format "hh:mm:ss" to a time object
41 KUZU_API static dtime_t fromCString(const char* buf, uint64_t len);
42 KUZU_API static bool tryConvertInterval(const char* buf, uint64_t len, uint64_t& pos,
43 dtime_t& result);
44 KUZU_API static bool tryConvertTime(const char* buf, uint64_t len, uint64_t& pos,
45 dtime_t& result);
46
47 // Convert a time object to a string in the format "hh:mm:ss"
48 KUZU_API static std::string toString(dtime_t time);
49
50 KUZU_API static dtime_t fromTime(int32_t hour, int32_t minute, int32_t second,
51 int32_t microseconds = 0);
52
53 // Extract the time from a given timestamp object
54 KUZU_API static void convert(dtime_t time, int32_t& out_hour, int32_t& out_min,
55 int32_t& out_sec, int32_t& out_micros);
56
57 KUZU_API static bool isValid(int32_t hour, int32_t minute, int32_t second,
58 int32_t milliseconds);
59
60private:
61 static bool tryConvertInternal(const char* buf, uint64_t len, uint64_t& pos, dtime_t& result);
62 static dtime_t fromTimeInternal(int32_t hour, int32_t minute, int32_t second,
63 int32_t microseconds = 0);
64};
65
66} // namespace common
67} // namespace kuzu
#define KUZU_API
Definition api.h:25
Definition dtime_t.h:38
static KUZU_API void convert(dtime_t time, int32_t &out_hour, int32_t &out_min, int32_t &out_sec, int32_t &out_micros)
static KUZU_API bool tryConvertInterval(const char *buf, uint64_t len, uint64_t &pos, dtime_t &result)
static KUZU_API std::string toString(dtime_t time)
static KUZU_API dtime_t fromTime(int32_t hour, int32_t minute, int32_t second, int32_t microseconds=0)
static KUZU_API bool isValid(int32_t hour, int32_t minute, int32_t second, int32_t milliseconds)
static KUZU_API bool tryConvertTime(const char *buf, uint64_t len, uint64_t &pos, dtime_t &result)
static KUZU_API dtime_t fromCString(const char *buf, uint64_t len)
Definition alter_type.h:5
Definition dtime_t.h:12
int64_t micros
Definition dtime_t.h:13
bool operator>=(const dtime_t &rhs) const
dtime_t(int64_t micros_p)
dtime_t & operator=(int64_t micros_p)
bool operator<=(const dtime_t &rhs) const
bool operator!=(const dtime_t &rhs) const
bool operator==(const dtime_t &rhs) const
bool operator>(const dtime_t &rhs) const
bool operator<(const dtime_t &rhs) const