@@ -15,61 +15,42 @@ module;
15
15
#include < chrono>
16
16
module current_timestamp;
17
17
import stl;
18
+ import config;
18
19
import catalog;
19
20
import status;
20
21
import logical_type;
22
+ import infinity_context;
21
23
import infinity_exception;
22
24
import scalar_function;
23
25
import scalar_function_set;
24
26
import third_party;
25
27
import internal_types;
26
28
import data_type;
27
29
import column_vector;
30
+ import query_context;
28
31
29
32
namespace infinity {
30
33
using namespace std ::chrono;
31
34
struct CurrentTimestampFunction {
32
- const char * defaultTZ = " Asia/Shanghai" ;
33
35
template <typename TA, typename TB>
34
36
static inline void Run (TA &left, TB &result) {
35
37
Status status = Status::NotSupport (" Not implemented" );
36
38
RecoverableError (status);
37
39
}
38
- static inline void TimeZoneConvertHelper (VarcharT &left) {
39
- const char * tzValue = std::getenv (" TZ" );
40
- const std::string str = left.ToString ();
41
- const char * newTZ = str.c_str ();
42
- if ( tzValue == newTZ) {
43
- return ;
44
- }
45
- if (setenv (" TZ" , newTZ, 1 ) != 0 ) {
46
- const char * newTZ = " Asia/Shanghai" ;
47
- setenv (" TZ" , newTZ, 1 );
48
- }
49
- tzset ();
50
- return ;
51
- }
52
-
53
- static inline void TimeZoneResetHelper () {
54
- const char * tzValue = std::getenv (" TZ" );
55
- if (tzValue == CurrentTimestampFunction ().defaultTZ ) {
56
- return ;
57
- }
58
- setenv (" TZ" , CurrentTimestampFunction ().defaultTZ , 1 );
59
- tzset ();
60
- return ;
61
- }
62
40
};
63
41
64
42
template <>
65
43
inline void CurrentTimestampFunction::Run (VarcharT &left, TimestampT &result) {
66
- TimeZoneConvertHelper (left);
67
- auto now = system_clock::now ();
68
- auto sys_days = std::chrono::floor <std::chrono::days>(now);
69
- auto sys_secs = std::chrono::floor <std::chrono::seconds>(now);
70
- result.time .value = static_cast <i32>(sys_secs.time_since_epoch ().count () - sys_days.time_since_epoch ().count ());
71
- result.date .value = static_cast <i32>(sys_days.time_since_epoch ().count ());
72
- TimeZoneResetHelper ();
44
+ String tz_str = left.ToString ();
45
+ InfinityContext& infinityContext = InfinityContext::instance ();
46
+ Config* config = infinityContext.config ();
47
+ auto offset = config->TimeZoneBias ();
48
+ hours offset_hour (offset);
49
+ auto now = system_clock::now () + offset_hour;
50
+ auto sys_days = std::chrono::floor <std::chrono::days>(now);
51
+ auto sys_secs = std::chrono::floor <std::chrono::seconds>(now);
52
+ result.time .value = static_cast <i32>(sys_secs.time_since_epoch ().count () - sys_days.time_since_epoch ().count ());
53
+ result.date .value = static_cast <i32>(sys_days.time_since_epoch ().count ());
73
54
}
74
55
75
56
void RegisterCurrentTimestampFunction (const UniquePtr<Catalog> &catalog_ptr) {
0 commit comments