Replace fields of a Temporal value
Source:R/temporal.R, R/duration.R, R/plain-date-time.R, and 5 more
temporal_with.Rdtemporal_with() is Temporal's with(): it returns a copy of x with
the named fields replaced and the rest kept, resolving the result with
overflow. temporal_with_plain_time() is withPlainTime(),
temporal_with_time_zone() is withTimeZone() (the same instant read
in another zone), and temporal_with_calendar() is withCalendar(),
which accepts only "iso8601" in this version.
Usage
temporal_with(x, ..., overflow = "constrain")
# S3 method for class 'zutempo_duration'
temporal_with(x, ..., overflow = "constrain")
# S3 method for class 'zutempo_plain_date_time'
temporal_with(x, ..., overflow = "constrain")
# S3 method for class 'zutempo_plain_date_time'
temporal_with_plain_time(x, time = NULL)
# S3 method for class 'zutempo_plain_date_time'
temporal_with_calendar(x, calendar)
# S3 method for class 'zutempo_plain_date'
temporal_with(x, ..., overflow = "constrain")
# S3 method for class 'zutempo_plain_date'
temporal_with_calendar(x, calendar)
# S3 method for class 'zutempo_plain_month_day'
temporal_with(x, ..., overflow = "constrain")
# S3 method for class 'zutempo_plain_time'
temporal_with(x, ..., overflow = "constrain")
# S3 method for class 'zutempo_plain_year_month'
temporal_with(x, ..., overflow = "constrain")
temporal_with_plain_time(x, time = NULL)
temporal_with_calendar(x, calendar)
# S3 method for class 'zutempo_zoned_date_time'
temporal_with(
x,
...,
disambiguation = "compatible",
offset = "prefer",
overflow = "constrain"
)
# S3 method for class 'zutempo_zoned_date_time'
temporal_with_plain_time(x, time = NULL)
temporal_with_time_zone(x, time_zone)
# S3 method for class 'zutempo_zoned_date_time'
temporal_with_time_zone(x, time_zone)
# S3 method for class 'zutempo_zoned_date_time'
temporal_with_calendar(x, calendar)Arguments
- x
A zutempo value.
- ...
Fields to replace, named:
year,month,month_code,day,hour,minute,second,millisecond,microsecond,nanosecond, as the type allows, andoffset_stringfor azoned_date_time(). At least one is required. Givingmonthormonth_codediscards the other fromx; giving both requires them to agree.- overflow
"constrain"(the default) clamps out-of-range fields,"reject"raises azutempo_range_errorfor them. Aduration()has nothing to clamp: the value is checked and has no effect.- time
A
plain_time(), a string aplain_time()reads, orNULLfor midnight.- calendar
A calendar identifier; only
"iso8601"is supported.- disambiguation, offset
For a
zoned_date_time(): how to resolve the new local time, as forzoned_date_time();offsetdefaults to"prefer"here.- time_zone
For
temporal_with_time_zone(): the new zone of each value, recycled.
Examples
temporal_with(plain_date("2026-01-31"), month = 2)
#> <zutempo_plain_date[1]>
#> [1] 2026-02-28
try(temporal_with(plain_date("2026-01-31"), month = 2, overflow = "reject"))
#> Error : 2026-02-31 is not a valid date (element 1)
temporal_with_plain_time(plain_date_time("2026-01-31T12:00"), "08:30")
#> <zutempo_plain_date_time[1]>
#> [1] 2026-01-31T08:30:00