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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fixed several issues with `page_navbar()` styling. (#1124)
* Fixed `Renderer.output_id` to not contain the module namespace prefix, only the output id. (#1130)
* Fixed gap-driven spacing between children in fillable `nav_panel()` containers. (#1152)
* Fixed #1138: An empty value in a date or date range input would cause an error; now it is treated as `None`. (#1139)

### Other changes

Expand Down
21 changes: 16 additions & 5 deletions shiny/input_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,24 @@ def _(value, name, session):
@input_handlers.add("shiny.date")
def _(
value: str | list[str], name: ResolvedId, session: Session
) -> date | tuple[date, date]:
) -> date | None | tuple[date | None, date | None]:

if isinstance(value, str):
return _safe_strptime_date(value)
else:
return (
_safe_strptime_date(value[0]),
_safe_strptime_date(value[1]),
)


def _safe_strptime_date(value: str | None) -> date | None:
if value is None:
return None
try:
return datetime.strptime(value, "%Y-%m-%d").date()
return (
datetime.strptime(value[0], "%Y-%m-%d").date(),
datetime.strptime(value[1], "%Y-%m-%d").date(),
)
except ValueError:
return None


@input_handlers.add("shiny.datetime")
Expand Down