Skip to content

Commit

Permalink
Fix(executor): use timezone-aware object to represent datetime in UTC (
Browse files Browse the repository at this point in the history
…#3447)

* Fix(executor): use timezone-aware object to represent datetime in UTC

* Fixup
  • Loading branch information
georgesittas committed May 9, 2024
1 parent baf39e7 commit 0927ae3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion sqlglot/executor/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,7 @@ def jsonextract(this, expression):
for x in range(0, len(args), 2)
if (args[x + 1] is not None and args[x] is not None)
},
"UNIXTOTIME": null_if_any(lambda arg: datetime.datetime.utcfromtimestamp(arg)),
"UNIXTOTIME": null_if_any(
lambda arg: datetime.datetime.fromtimestamp(arg, datetime.timezone.utc)
),
}
10 changes: 8 additions & 2 deletions tests/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,15 @@ def test_scalar_functions(self):
("ROUND(1.2)", 1),
("ROUND(1.2345, 2)", 1.23),
("ROUND(NULL)", None),
("UNIXTOTIME(1659981729)", datetime.datetime(2022, 8, 8, 18, 2, 9)),
(
"UNIXTOTIME(1659981729)",
datetime.datetime(2022, 8, 8, 18, 2, 9, tzinfo=datetime.timezone.utc),
),
("TIMESTRTOTIME('2013-04-05 01:02:03')", datetime.datetime(2013, 4, 5, 1, 2, 3)),
("UNIXTOTIME(40 * 365 * 86400)", datetime.datetime(2009, 12, 22, 00, 00, 00)),
(
"UNIXTOTIME(40 * 365 * 86400)",
datetime.datetime(2009, 12, 22, 00, 00, 00, tzinfo=datetime.timezone.utc),
),
(
"STRTOTIME('08/03/2024 12:34:56', '%d/%m/%Y %H:%M:%S')",
datetime.datetime(2024, 3, 8, 12, 34, 56),
Expand Down

0 comments on commit 0927ae3

Please sign in to comment.