Skip to content

Convert to given time zone for an expression of type Datetime.

Source code

Description

If converting from a time-zone-naive datetime, then conversion will happen as if converting from UTC, regardless of your system’s time zone.

Usage

<Expr>$dt$convert_time_zone(time_zone)

Arguments

time_zone String time zone from base::OlsonNames()

Value

Expr of i64

Examples

library(polars)

df = pl$DataFrame(
  date = pl$date_range(
    as.POSIXct("2020-03-01", tz = "UTC"),
    as.POSIXct("2020-05-01", tz = "UTC"),
    "1mo"
  )
)

df$select(
  "date",
  London = pl$col("date")$dt$convert_time_zone("Europe/London")
)
#> shape: (3, 2)
#> ┌─────────────────────────┬─────────────────────────────┐
#> │ date                    ┆ London                      │
#> │ ---                     ┆ ---                         │
#> │ datetime[ms, UTC]       ┆ datetime[ms, Europe/London] │
#> ╞═════════════════════════╪═════════════════════════════╡
#> │ 2020-03-01 00:00:00 UTC ┆ 2020-03-01 00:00:00 GMT     │
#> │ 2020-04-01 00:00:00 UTC ┆ 2020-04-01 01:00:00 BST     │
#> │ 2020-05-01 00:00:00 UTC ┆ 2020-05-01 01:00:00 BST     │
#> └─────────────────────────┴─────────────────────────────┘