Skip to contents

Tests if a date is a weekday or not.

Usage

isWeekday(x, wday = 1:5)
isWeekend(x, wday = 1:5)

Arguments

x

an object of class "timeDate".

wday

Specify which days should be considered as weekdays. By default from Mondays to Fridays.

Value

a logical vector indicating if a date is a weekday or a weekend day

Examples

## Dates in April, currentYear:
   currentYear = getRmetricsOptions("currentYear")
   tS = timeSequence(
      from = paste(currentYear, "-03-01", sep = ""),
      to = paste(currentYear, "-04-30", sep = ""))
   tS
#> GMT
#>  [1] [2023-03-01] [2023-03-02] [2023-03-03] [2023-03-04] [2023-03-05]
#>  [6] [2023-03-06] [2023-03-07] [2023-03-08] [2023-03-09] [2023-03-10]
#> [11] [2023-03-11] [2023-03-12] [2023-03-13] [2023-03-14] [2023-03-15]
#> [16] [2023-03-16] [2023-03-17] [2023-03-18] [2023-03-19] [2023-03-20]
#> [21] [2023-03-21] [2023-03-22] [2023-03-23] [2023-03-24] [2023-03-25]
#> [26] [2023-03-26] [2023-03-27] [2023-03-28] [2023-03-29] [2023-03-30]
#> [31] [2023-03-31] [2023-04-01] [2023-04-02] [2023-04-03] [2023-04-04]
#> [36] [2023-04-05] [2023-04-06] [2023-04-07] [2023-04-08] [2023-04-09]
#> [41] [2023-04-10] [2023-04-11] [2023-04-12] [2023-04-13] [2023-04-14]
#> [46] [2023-04-15] [2023-04-16] [2023-04-17] [2023-04-18] [2023-04-19]
#> [51] [2023-04-20] [2023-04-21] [2023-04-22] [2023-04-23] [2023-04-24]
#> [56] [2023-04-25] [2023-04-26] [2023-04-27] [2023-04-28] [2023-04-29]
#> [61] [2023-04-30]

## Subset of Weekends:
   isWeekend(tS)
#> 2023-03-01 2023-03-02 2023-03-03 2023-03-04 2023-03-05 2023-03-06 2023-03-07 
#>      FALSE      FALSE      FALSE       TRUE       TRUE      FALSE      FALSE 
#> 2023-03-08 2023-03-09 2023-03-10 2023-03-11 2023-03-12 2023-03-13 2023-03-14 
#>      FALSE      FALSE      FALSE       TRUE       TRUE      FALSE      FALSE 
#> 2023-03-15 2023-03-16 2023-03-17 2023-03-18 2023-03-19 2023-03-20 2023-03-21 
#>      FALSE      FALSE      FALSE       TRUE       TRUE      FALSE      FALSE 
#> 2023-03-22 2023-03-23 2023-03-24 2023-03-25 2023-03-26 2023-03-27 2023-03-28 
#>      FALSE      FALSE      FALSE       TRUE       TRUE      FALSE      FALSE 
#> 2023-03-29 2023-03-30 2023-03-31 2023-04-01 2023-04-02 2023-04-03 2023-04-04 
#>      FALSE      FALSE      FALSE       TRUE       TRUE      FALSE      FALSE 
#> 2023-04-05 2023-04-06 2023-04-07 2023-04-08 2023-04-09 2023-04-10 2023-04-11 
#>      FALSE      FALSE      FALSE       TRUE       TRUE      FALSE      FALSE 
#> 2023-04-12 2023-04-13 2023-04-14 2023-04-15 2023-04-16 2023-04-17 2023-04-18 
#>      FALSE      FALSE      FALSE       TRUE       TRUE      FALSE      FALSE 
#> 2023-04-19 2023-04-20 2023-04-21 2023-04-22 2023-04-23 2023-04-24 2023-04-25 
#>      FALSE      FALSE      FALSE       TRUE       TRUE      FALSE      FALSE 
#> 2023-04-26 2023-04-27 2023-04-28 2023-04-29 2023-04-30 
#>      FALSE      FALSE      FALSE       TRUE       TRUE 
   tS[isWeekend(tS)]
#> GMT
#>  [1] [2023-03-04] [2023-03-05] [2023-03-11] [2023-03-12] [2023-03-18]
#>  [6] [2023-03-19] [2023-03-25] [2023-03-26] [2023-04-01] [2023-04-02]
#> [11] [2023-04-08] [2023-04-09] [2023-04-15] [2023-04-16] [2023-04-22]
#> [16] [2023-04-23] [2023-04-29] [2023-04-30]