Skip to content

Commit ae5051a

Browse files
appletreeisyellowalamb
authored andcommitted
feat: add UDF to_local_time() (apache#11347)
* feat: add UDF `to_local_time()` * chore: support column value in array * chore: lint * chore: fix conversion for us, ms, and s * chore: add more tests for daylight savings time * chore: add function description * refactor: update tests and add examples in description * chore: add description and example * chore: doc chore: doc chore: doc chore: doc chore: doc * chore: stop copying * chore: fix typo * chore: mention that the offset varies based on daylight savings time * refactor: parse timezone once and update examples in description * refactor: replace map..concat with flat_map * chore: add hard code timestamp value in test chore: doc chore: doc * chore: handle errors and remove panics * chore: move some test to slt * chore: clone time_value * chore: typo --------- Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
1 parent 0fdbd5e commit ae5051a

File tree

3 files changed

+751
-1
lines changed

3 files changed

+751
-1
lines changed

datafusion/functions/src/datetime/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub mod make_date;
3232
pub mod now;
3333
pub mod to_char;
3434
pub mod to_date;
35+
pub mod to_local_time;
3536
pub mod to_timestamp;
3637
pub mod to_unixtime;
3738

@@ -50,6 +51,7 @@ make_udf_function!(
5051
make_udf_function!(now::NowFunc, NOW, now);
5152
make_udf_function!(to_char::ToCharFunc, TO_CHAR, to_char);
5253
make_udf_function!(to_date::ToDateFunc, TO_DATE, to_date);
54+
make_udf_function!(to_local_time::ToLocalTimeFunc, TO_LOCAL_TIME, to_local_time);
5355
make_udf_function!(to_unixtime::ToUnixtimeFunc, TO_UNIXTIME, to_unixtime);
5456
make_udf_function!(to_timestamp::ToTimestampFunc, TO_TIMESTAMP, to_timestamp);
5557
make_udf_function!(
@@ -108,7 +110,13 @@ pub mod expr_fn {
108110
),(
109111
now,
110112
"returns the current timestamp in nanoseconds, using the same value for all instances of now() in same statement",
111-
),(
113+
),
114+
(
115+
to_local_time,
116+
"converts a timezone-aware timestamp to local time (with no offset or timezone information), i.e. strips off the timezone from the timestamp",
117+
args,
118+
),
119+
(
112120
to_unixtime,
113121
"converts a string and optional formats to a Unixtime",
114122
args,
@@ -277,6 +285,7 @@ pub fn functions() -> Vec<Arc<ScalarUDF>> {
277285
now(),
278286
to_char(),
279287
to_date(),
288+
to_local_time(),
280289
to_unixtime(),
281290
to_timestamp(),
282291
to_timestamp_seconds(),

0 commit comments

Comments
 (0)