You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feat: Make current_time aware of execution timezone. (#18040)
## Which issue does this PR close?
- Closes#17996.
## Rationale for this change
- The current_time() function currently uses UTC tz. This PR updates
current_time() to use the tz set in 'datafusion.execution.time_zone'
## What changes are included in this PR?
- current_time() returns a tz aware date via the
'datafusion.execution.time_zone' config option.
## Are these changes tested?
- Tested with Datafusion CLI with slt covering popular scenarios added.
Returns the current time in the session time zone.
34
36
35
37
The `current_time()` return value is determined at query time and will return the same time, no matter when in the query plan the function executes.
38
+
39
+
The session time zone can be set using the statement 'SET datafusion.execution.time_zone = desired time zone'. The time zone can be a value like +00:00, 'Europe/London' etc.
36
40
"#,
37
41
syntax_example = "current_time()"
38
42
)]
@@ -93,7 +97,20 @@ impl ScalarUDFImpl for CurrentTimeFunc {
93
97
info:&dynSimplifyInfo,
94
98
) -> Result<ExprSimplifyResult>{
95
99
let now_ts = info.execution_props().query_execution_start_time;
96
-
let nano = now_ts.timestamp_nanos_opt().map(|ts| ts % 86400000000000);
100
+
101
+
// Try to get timezone from config and convert to local time
Copy file name to clipboardExpand all lines: docs/source/user-guide/sql/scalar_functions.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2417,10 +2417,12 @@ current_date()
2417
2417
2418
2418
### `current_time`
2419
2419
2420
-
Returns the current UTC time.
2420
+
Returns the current time in the session time zone.
2421
2421
2422
2422
The `current_time()` return value is determined at query time and will return the same time, no matter when in the query plan the function executes.
2423
2423
2424
+
The session time zone can be set using the statement 'SET datafusion.execution.time_zone = desired time zone'. The time zone can be a value like +00:00, 'Europe/London' etc.
0 commit comments