Skip to content

Commit 2dfc272

Browse files
committed
Merge branch 'main' into update_row_selection
* main: bug: Remove timezone info from `shiny.datetime` input handler (#1146)
2 parents c0c3c01 + 0123f09 commit 2dfc272

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
### Other changes
1818

1919
* Replaced use of `sys.stderr.write()` with `print(file=sys.stderr)`, because on some platforms `sys.stderr` can be `None`. (#1131)
20-
* Replaced deprecated `datetime` method calls with `datetime.fromtimestamp(tz=timezone.utc)` and `datetime.now(timezone.utc)`. (#1142)
20+
* Replaced soon-to-be deprecated `datetime` method calls when handling `shiny.datetime` inputs. (#1146)
2121

2222

2323
## [0.7.1] - 2024-02-05

shiny/input_handler.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,20 @@ def _(
110110

111111
@input_handlers.add("shiny.datetime")
112112
def _(
113-
value: int | float | list[int] | list[float], name: ResolvedId, session: Session
113+
value: int | float | list[int] | list[float],
114+
name: ResolvedId,
115+
session: Session,
114116
) -> datetime | tuple[datetime, datetime]:
117+
def as_utc_date(x: int | float) -> datetime:
118+
dt = datetime.fromtimestamp(x, timezone.utc)
119+
# Remove hour offset from print method by removing the timezone
120+
# Ex: 2021-08-01T00:00:00+00:00 -> 2021-08-01T00:00:00
121+
# This is done as all dates are in UTC
122+
return dt.replace(tzinfo=None)
123+
115124
if isinstance(value, (int, float)):
116-
return datetime.fromtimestamp(value, timezone.utc)
117-
return (
118-
datetime.fromtimestamp(value[0], timezone.utc),
119-
datetime.fromtimestamp(value[1], timezone.utc),
120-
)
125+
return as_utc_date(value)
126+
return (as_utc_date(value[0]), as_utc_date(value[1]))
121127

122128

123129
@input_handlers.add("shiny.action")

tests/playwright/shiny/bugs/0648-update-slider-datetime-value/test_update_slider_datetime_value.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def check_case(
3737

3838
page.goto(local_app.url)
3939

40-
start_time = "2023-07-01 00:00:00+00:00"
41-
end_time = "2023-07-01 01:00:00+00:00"
40+
start_time = "2023-07-01 00:00:00"
41+
end_time = "2023-07-01 01:00:00"
4242

4343
check_case("one", value=(start_time, end_time))
4444
check_case(

0 commit comments

Comments
 (0)