Skip to content

updateDateRangeInput doesn't honor timzone of POSIXct #4317

@ismirsehregal

Description

@ismirsehregal

Currently updateDateRangeInput doesn't honor the timzone of POSIXct arguments, which for some timezones leads to "wrong" dates being displayed (please see the below example - in my actual app the user can choose the timezone).

I think the issue is the underlying call to dateYMD() using as.Date() which applies tz = "UTC" by default.

Maybe this can be resolved by introducing a tz argument for dateRangeInput and updateDateRangeInput or by using lubridate::as_date instead:

Called on a POSIXct object, as_date() uses the tzone attribute of the object to return the same date as indicated by the printed representation of the object. This differs from as.Date, which ignores the attribute and uses only the tz argument to as.Date() ("UTC" by default).

Sys.setenv(TZ = "Europe/London")
Sys.time()

library(shiny)

ui <- fluidPage(
  # results in start 2025-11-17 to end 2025-11-17
  # If NULL (the default), will use the current date in the client's time zone.
  dateRangeInput(
    inputId = "TZtest",
    label = "TZ test"
  )
)

server <- function(input, output, session) {
  updateDateRangeInput(
    inputId = "TZtest",
    label = "TZ test",
    start = as.POSIXct("2025-11-17 23:59:59", tz = "Asia/Tokyo"),
    end = as.POSIXct("2025-11-18 00:01:59", tz = "Asia/Tokyo"),
    min = as.POSIXct("2025-11-17 23:59:59", tz = "Asia/Tokyo"),
    max = as.POSIXct("2025-11-18 00:01:59", tz = "Asia/Tokyo")
  )
}

shinyApp(ui, server)

Result:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions