Debian Codegraph @

R/ISOweek-internal.R

raw
1 #' Weekday as integer number (0-6, Monday is 0)
2 #'
3 #' This internal function returns the weekday of a given date.
4 #'
5 #' The week starts on Monday and ends on Sunday.
6 #'
7 #' @param date Vector which can be coerced to class \code{Date}
8 #' @return An integer vector of weekdays (0-6, Monday is 0)
9 #' @seealso \code{\link{ISOweekday}}
10 #' @keywords internal
11 weekday0 <- function(date) {
12 return(ISOweekday(date) - 1L)
13 }
14
15 #' Date of the nearest Thursday of a given date
16 #'
17 #' This internal function returns the date of the Thursday of the week in which the given date is located.
18 #'
19 #' The week starts on Monday and ends on Sunday.
20 #'
21 #' @param date Vector which can be coerced to class \code{Date}
22 #' @return A vector of dates of the nearest Thursdays
23 #' @keywords internal
24 thursday0 <- function(date) {
25 date <- as.Date(date)
26 return(date - weekday0(date) + 3)
27 }
28
29 #' Calendar year of a given date
30 #'
31 #' This internal function returns the year with century as integer.
32 #'
33 #' @param date Vector which can be coerced to class \code{Date}
34 #' @return An integer vector of years
35 #' @keywords internal
36 year0 <- function(date) {
37 date <- as.Date(date)
38 return(as.integer(format(date, "%Y")))
39 }