Skip to content

Commit 6a23679

Browse files
committed
Add vec-ptype method for weekday
1 parent 40d710d commit 6a23679

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ S3method(vec_proxy_compare,clock_year_month_weekday)
433433
S3method(vec_ptype,clock_iso_year_week_day)
434434
S3method(vec_ptype,clock_naive_time)
435435
S3method(vec_ptype,clock_sys_time)
436+
S3method(vec_ptype,clock_weekday)
436437
S3method(vec_ptype,clock_year_month_day)
437438
S3method(vec_ptype,clock_year_month_weekday)
438439
S3method(vec_ptype,clock_year_quarter_day)

R/weekday.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ vec_ptype_abbr.clock_weekday <- function(x, ...) {
157157

158158
# ------------------------------------------------------------------------------
159159

160+
#' @export
161+
vec_ptype.clock_weekday <- function(x, ...) {
162+
clock_empty_weekday
163+
}
164+
160165
#' @export
161166
vec_ptype2.clock_weekday.clock_weekday <- function(x, y, ...) {
162167
x
@@ -506,3 +511,11 @@ reencode_western_to_iso <- function(code) {
506511
code[code == 0L] <- 7L
507512
code
508513
}
514+
515+
# ------------------------------------------------------------------------------
516+
517+
clock_init_weekday_utils <- function(env) {
518+
assign("clock_empty_weekday", weekday(integer()), envir = env)
519+
520+
invisible(NULL)
521+
}

R/zzz.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
clock_init_sys_time_utils(clock_ns)
1616
clock_init_naive_time_utils(clock_ns)
1717
clock_init_zoned_time_utils(clock_ns)
18+
clock_init_weekday_utils(clock_ns)
1819

1920
vctrs::s3_register("pillar::pillar_shaft", "clock_calendar", pillar_shaft.clock_calendar)
2021
vctrs::s3_register("pillar::pillar_shaft", "clock_time_point", pillar_shaft.clock_time_point)

tests/testthat/test-weekday.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,10 @@ test_that("can't compare or order weekdays (#153)", {
173173
expect_snapshot_error(xtfrm(weekday(1:2)))
174174
expect_snapshot_error(vec_order(weekday(1:2)))
175175
})
176+
177+
# ------------------------------------------------------------------------------
178+
# vec_ptype()
179+
180+
test_that("ptype is correct", {
181+
expect_identical(vec_ptype(weekday(1:7)), weekday(integer()))
182+
})

0 commit comments

Comments
 (0)