Skip to content

Commit 347c3dd

Browse files
authored
chore: Remove deprecated datetime method calls (#1142)
1 parent 6705788 commit 347c3dd

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +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)
2021

2122

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

shiny/input_handler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
__all__ = ("input_handlers",)
66

7-
from datetime import date, datetime
7+
from datetime import date, datetime, timezone
88
from typing import TYPE_CHECKING, Any, Callable, Dict
99

1010
if TYPE_CHECKING:
@@ -113,10 +113,10 @@ def _(
113113
value: int | float | list[int] | list[float], name: ResolvedId, session: Session
114114
) -> datetime | tuple[datetime, datetime]:
115115
if isinstance(value, (int, float)):
116-
return datetime.utcfromtimestamp(value)
116+
return datetime.fromtimestamp(value, timezone.utc)
117117
return (
118-
datetime.utcfromtimestamp(value[0]),
119-
datetime.utcfromtimestamp(value[1]),
118+
datetime.fromtimestamp(value[0], timezone.utc),
119+
datetime.fromtimestamp(value[1], timezone.utc),
120120
)
121121

122122

shiny/plotutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def near_points(
312312
if all_rows:
313313
# Add selected_ column if needed
314314
new_df["selected_"] = False
315-
new_df.iloc[
315+
new_df.iloc[ # pyright: ignore[reportArgumentType]
316316
keep_idx,
317317
new_df.columns.get_loc( # pyright: ignore[reportUnknownMemberType]
318318
"selected_"

tests/playwright/shiny/inputs/input_task_button/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
from datetime import datetime
2+
from datetime import datetime, timezone
33

44
from shiny import reactive, render
55
from shiny.express import input, ui
@@ -10,7 +10,7 @@
1010
@render.text()
1111
def current_time() -> str:
1212
reactive.invalidate_later(0.1)
13-
return str(datetime.now().utcnow())
13+
return str(datetime.now(timezone.utc).isoformat())
1414

1515

1616
with ui.p():

0 commit comments

Comments
 (0)