Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Other changes

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


## [0.7.1] - 2024-02-05
Expand Down
18 changes: 12 additions & 6 deletions shiny/input_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,20 @@ def _(

@input_handlers.add("shiny.datetime")
def _(
value: int | float | list[int] | list[float], name: ResolvedId, session: Session
value: int | float | list[int] | list[float],
name: ResolvedId,
session: Session,
) -> datetime | tuple[datetime, datetime]:
def as_utc_date(x: int | float) -> datetime:
dt = datetime.fromtimestamp(x, timezone.utc)
# Remove hour offset from print method by removing the timezone
# Ex: 2021-08-01T00:00:00+00:00 -> 2021-08-01T00:00:00
# This is done as all dates are in UTC
return dt.replace(tzinfo=None)

if isinstance(value, (int, float)):
return datetime.fromtimestamp(value, timezone.utc)
return (
datetime.fromtimestamp(value[0], timezone.utc),
datetime.fromtimestamp(value[1], timezone.utc),
)
return as_utc_date(value)
return (as_utc_date(value[0]), as_utc_date(value[1]))


@input_handlers.add("shiny.action")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def check_case(

page.goto(local_app.url)

start_time = "2023-07-01 00:00:00+00:00"
end_time = "2023-07-01 01:00:00+00:00"
start_time = "2023-07-01 00:00:00"
end_time = "2023-07-01 01:00:00"

check_case("one", value=(start_time, end_time))
check_case(
Expand Down