Representative String for Part of Timestamp
intervalKey(tstamps, itype)
tstamps | (vector of) timestamp(s) of type POSXIXt |
---|---|
itype | one of 'y' (year), 'q' (quarter in year), 'm' (month in year), 'd' (day in month in year), 'w' (week in year), 'D' (weekday in month in year), 'qo' (quarter only), 'mo' (month only), 'do' (day only), 'dm' (day in month), 'wo' (week only), 'Do' (weekday only), 'Dy' (weekday in year) |
# Define a sequence of times times <- as.POSIXct(kwb.datetime::sequenceOfTimestamps( "2017-11-04 22:00:00", "2017-11-05 02:00:00", step.s = 3000 )) # Apply all different defined types and print the result for (type in rownames(kwb.datetime:::.timestamp_type_info())) { kwb.utils::printIf(TRUE, intervalKey(times, type), paste("\ntype:", type)) }#> #> type: y: #> [1] "2017" "2017" "2017" "2017" "2017" #> #> type: q: #> [1] "2017-Q4" "2017-Q4" "2017-Q4" "2017-Q4" "2017-Q4" #> #> type: m: #> [1] "2017-11 (November 2017)" "2017-11 (November 2017)" #> [3] "2017-11 (November 2017)" "2017-11 (November 2017)" #> [5] "2017-11 (November 2017)" #> #> type: d: #> [1] "2017-11-04" "2017-11-04" "2017-11-04" "2017-11-05" "2017-11-05" #> #> type: w: #> [1] "2017-W44" "2017-W44" "2017-W44" "2017-W45" "2017-W45" #> #> type: D: #> [1] "2017-11-WD6 (Saturday)" "2017-11-WD6 (Saturday)" "2017-11-WD6 (Saturday)" #> [4] "2017-11-WD0 (Sunday)" "2017-11-WD0 (Sunday)" #> #> type: qo: #> [1] "Q4" "Q4" "Q4" "Q4" "Q4" #> #> type: mo: #> [1] "11 (November)" "11 (November)" "11 (November)" "11 (November)" #> [5] "11 (November)" #> #> type: do: #> [1] "04" "04" "04" "05" "05" #> #> type: dm: #> [1] "11-04 (November 04)" "11-04 (November 04)" "11-04 (November 04)" #> [4] "11-05 (November 05)" "11-05 (November 05)" #> #> type: wo: #> [1] "W44 (week 44)" "W44 (week 44)" "W44 (week 44)" "W45 (week 45)" #> [5] "W45 (week 45)" #> #> type: Do: #> [1] "WD6 (Saturday)" "WD6 (Saturday)" "WD6 (Saturday)" "WD0 (Sunday)" #> [5] "WD0 (Sunday)" #> #> type: Dy: #> [1] "2017-WD6 (Saturday)" "2017-WD6 (Saturday)" "2017-WD6 (Saturday)" #> [4] "2017-WD0 (Sunday)" "2017-WD0 (Sunday)"