posit-dev / posit-dev/py-shiny

datetime slider returns UTC, regardless of timezone specified

Open
#556 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.8k
Forks
135
Avg merge
2d 18h
Merged PRs (30d)
21

Description

Hello,

I've noticed that value of an input_slider always return utc datetimes.
The input_slider has a property timezone, but apparently this is only for display reasons.

I would expect to have the slider return datetimes in the chosen timezone, or, in case of a None value for timezone, in the local timezone, but this is not the case.

A sample app :

from shiny import *
from datetime import datetime, timedelta

app_ui = ui.page_fluid(
    ui.h2("Timerange Slider"),
    ui.input_slider(id="in_timerange",
                    label="Time Range",
                    min=datetime.now() - timedelta(hours=24),
                    max=datetime.now(),
                    step=timedelta(hours=1),
                    time_format="%d-%H:00",
                    value=[datetime.now() - timedelta(hours=6), datetime.now() - timedelta(hours=4)],
                    width="1600px",
                    drag_range=True
    ),
    ui.output_text_verbatim("out_timerange")
)


def server(input, output, session):
    @output
    @render.text
    def out_timerange():
        # add (datetime.now() - datetime.utcnow() to convert to local timezone
        # timerange = [t + (datetime.now() - datetime.utcnow()) for t in input.in_timerange()]
        timerange = input.in_timerange()

        return timerange


app = App(app_ui, server)

def main():
    run_app(app)

if __name__ == "__main__":
    main()

Kind Regards

Bart

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the sample app and tracing the value returned by input.in_timerange() from ui.input_slider. Inspect how the slider's timezone setting is applied, then verify that selected values use the chosen timezone or the local timezone when it is None.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.