Skip to contents

This function provides a sequence (seq()) method for messydates. This can be used with ranges or unspecified dates, and is particularly useful for defining a sequence of dates before the common era or between eras.

Usage

# S3 method for class 'mdate'
seq(from, to, by = "days", ...)

Arguments

from

A messydate or range. If 'from' is a range and 'to' is not specified, 'from' will be the minimum of the range and 'to' will be maximum.

to

A messydate.

by

Increment of the sequence. By default "days". Use a sub-day unit ("hour", "min", or "sec") for a date-time sequence.

...

Arguments passed to or from methods.

Details

If from/to (or by) carry a time of day, the sequence is generated at the requested sub-day granularity (e.g. by = "hour") via POSIXct, and each element of the result keeps a time of day. Otherwise, dates are sequenced by calendar day (or another day-based by, e.g. "week" or "month"). Because years are numbered astronomically (proleptic Gregorian, with a year zero), a sequence that spans the BCE/CE boundary passes through the astronomical year zero (= 1 BCE) rather than jumping straight from -0001 to 0001.

Examples

seq(mdate("-0001-12-20"), mdate("0001-01-10"))
#>   [1] "-0001-12-20" "-0001-12-21" "-0001-12-22" "-0001-12-23" "-0001-12-24"
#>   [6] "-0001-12-25" "-0001-12-26" "-0001-12-27" "-0001-12-28" "-0001-12-29"
#>  [11] "-0001-12-30" "-0001-12-31" "0000-01-01"  "0000-01-02"  "0000-01-03" 
#>  [16] "0000-01-04"  "0000-01-05"  "0000-01-06"  "0000-01-07"  "0000-01-08" 
#>  [21] "0000-01-09"  "0000-01-10"  "0000-01-11"  "0000-01-12"  "0000-01-13" 
#>  [26] "0000-01-14"  "0000-01-15"  "0000-01-16"  "0000-01-17"  "0000-01-18" 
#>  [31] "0000-01-19"  "0000-01-20"  "0000-01-21"  "0000-01-22"  "0000-01-23" 
#>  [36] "0000-01-24"  "0000-01-25"  "0000-01-26"  "0000-01-27"  "0000-01-28" 
#>  [41] "0000-01-29"  "0000-01-30"  "0000-01-31"  "0000-02-01"  "0000-02-02" 
#>  [46] "0000-02-03"  "0000-02-04"  "0000-02-05"  "0000-02-06"  "0000-02-07" 
#>  [51] "0000-02-08"  "0000-02-09"  "0000-02-10"  "0000-02-11"  "0000-02-12" 
#>  [56] "0000-02-13"  "0000-02-14"  "0000-02-15"  "0000-02-16"  "0000-02-17" 
#>  [61] "0000-02-18"  "0000-02-19"  "0000-02-20"  "0000-02-21"  "0000-02-22" 
#>  [66] "0000-02-23"  "0000-02-24"  "0000-02-25"  "0000-02-26"  "0000-02-27" 
#>  [71] "0000-02-28"  "0000-02-29"  "0000-03-01"  "0000-03-02"  "0000-03-03" 
#>  [76] "0000-03-04"  "0000-03-05"  "0000-03-06"  "0000-03-07"  "0000-03-08" 
#>  [81] "0000-03-09"  "0000-03-10"  "0000-03-11"  "0000-03-12"  "0000-03-13" 
#>  [86] "0000-03-14"  "0000-03-15"  "0000-03-16"  "0000-03-17"  "0000-03-18" 
#>  [91] "0000-03-19"  "0000-03-20"  "0000-03-21"  "0000-03-22"  "0000-03-23" 
#>  [96] "0000-03-24"  "0000-03-25"  "0000-03-26"  "0000-03-27"  "0000-03-28" 
#> [101] "0000-03-29"  "0000-03-30"  "0000-03-31"  "0000-04-01"  "0000-04-02" 
#> [106] "0000-04-03"  "0000-04-04"  "0000-04-05"  "0000-04-06"  "0000-04-07" 
#> [111] "0000-04-08"  "0000-04-09"  "0000-04-10"  "0000-04-11"  "0000-04-12" 
#> [116] "0000-04-13"  "0000-04-14"  "0000-04-15"  "0000-04-16"  "0000-04-17" 
#> [121] "0000-04-18"  "0000-04-19"  "0000-04-20"  "0000-04-21"  "0000-04-22" 
#> [126] "0000-04-23"  "0000-04-24"  "0000-04-25"  "0000-04-26"  "0000-04-27" 
#> [131] "0000-04-28"  "0000-04-29"  "0000-04-30"  "0000-05-01"  "0000-05-02" 
#> [136] "0000-05-03"  "0000-05-04"  "0000-05-05"  "0000-05-06"  "0000-05-07" 
#> [141] "0000-05-08"  "0000-05-09"  "0000-05-10"  "0000-05-11"  "0000-05-12" 
#> [146] "0000-05-13"  "0000-05-14"  "0000-05-15"  "0000-05-16"  "0000-05-17" 
#> [151] "0000-05-18"  "0000-05-19"  "0000-05-20"  "0000-05-21"  "0000-05-22" 
#> [156] "0000-05-23"  "0000-05-24"  "0000-05-25"  "0000-05-26"  "0000-05-27" 
#> [161] "0000-05-28"  "0000-05-29"  "0000-05-30"  "0000-05-31"  "0000-06-01" 
#> [166] "0000-06-02"  "0000-06-03"  "0000-06-04"  "0000-06-05"  "0000-06-06" 
#> [171] "0000-06-07"  "0000-06-08"  "0000-06-09"  "0000-06-10"  "0000-06-11" 
#> [176] "0000-06-12"  "0000-06-13"  "0000-06-14"  "0000-06-15"  "0000-06-16" 
#> [181] "0000-06-17"  "0000-06-18"  "0000-06-19"  "0000-06-20"  "0000-06-21" 
#> [186] "0000-06-22"  "0000-06-23"  "0000-06-24"  "0000-06-25"  "0000-06-26" 
#> [191] "0000-06-27"  "0000-06-28"  "0000-06-29"  "0000-06-30"  "0000-07-01" 
#> [196] "0000-07-02"  "0000-07-03"  "0000-07-04"  "0000-07-05"  "0000-07-06" 
#> [201] "0000-07-07"  "0000-07-08"  "0000-07-09"  "0000-07-10"  "0000-07-11" 
#> [206] "0000-07-12"  "0000-07-13"  "0000-07-14"  "0000-07-15"  "0000-07-16" 
#> [211] "0000-07-17"  "0000-07-18"  "0000-07-19"  "0000-07-20"  "0000-07-21" 
#> [216] "0000-07-22"  "0000-07-23"  "0000-07-24"  "0000-07-25"  "0000-07-26" 
#> [221] "0000-07-27"  "0000-07-28"  "0000-07-29"  "0000-07-30"  "0000-07-31" 
#> [226] "0000-08-01"  "0000-08-02"  "0000-08-03"  "0000-08-04"  "0000-08-05" 
#> [231] "0000-08-06"  "0000-08-07"  "0000-08-08"  "0000-08-09"  "0000-08-10" 
#> [236] "0000-08-11"  "0000-08-12"  "0000-08-13"  "0000-08-14"  "0000-08-15" 
#> [241] "0000-08-16"  "0000-08-17"  "0000-08-18"  "0000-08-19"  "0000-08-20" 
#> [246] "0000-08-21"  "0000-08-22"  "0000-08-23"  "0000-08-24"  "0000-08-25" 
#> [251] "0000-08-26"  "0000-08-27"  "0000-08-28"  "0000-08-29"  "0000-08-30" 
#> [256] "0000-08-31"  "0000-09-01"  "0000-09-02"  "0000-09-03"  "0000-09-04" 
#> [261] "0000-09-05"  "0000-09-06"  "0000-09-07"  "0000-09-08"  "0000-09-09" 
#> [266] "0000-09-10"  "0000-09-11"  "0000-09-12"  "0000-09-13"  "0000-09-14" 
#> [271] "0000-09-15"  "0000-09-16"  "0000-09-17"  "0000-09-18"  "0000-09-19" 
#> [276] "0000-09-20"  "0000-09-21"  "0000-09-22"  "0000-09-23"  "0000-09-24" 
#> [281] "0000-09-25"  "0000-09-26"  "0000-09-27"  "0000-09-28"  "0000-09-29" 
#> [286] "0000-09-30"  "0000-10-01"  "0000-10-02"  "0000-10-03"  "0000-10-04" 
#> [291] "0000-10-05"  "0000-10-06"  "0000-10-07"  "0000-10-08"  "0000-10-09" 
#> [296] "0000-10-10"  "0000-10-11"  "0000-10-12"  "0000-10-13"  "0000-10-14" 
#> [301] "0000-10-15"  "0000-10-16"  "0000-10-17"  "0000-10-18"  "0000-10-19" 
#> [306] "0000-10-20"  "0000-10-21"  "0000-10-22"  "0000-10-23"  "0000-10-24" 
#> [311] "0000-10-25"  "0000-10-26"  "0000-10-27"  "0000-10-28"  "0000-10-29" 
#> [316] "0000-10-30"  "0000-10-31"  "0000-11-01"  "0000-11-02"  "0000-11-03" 
#> [321] "0000-11-04"  "0000-11-05"  "0000-11-06"  "0000-11-07"  "0000-11-08" 
#> [326] "0000-11-09"  "0000-11-10"  "0000-11-11"  "0000-11-12"  "0000-11-13" 
#> [331] "0000-11-14"  "0000-11-15"  "0000-11-16"  "0000-11-17"  "0000-11-18" 
#> [336] "0000-11-19"  "0000-11-20"  "0000-11-21"  "0000-11-22"  "0000-11-23" 
#> [341] "0000-11-24"  "0000-11-25"  "0000-11-26"  "0000-11-27"  "0000-11-28" 
#> [346] "0000-11-29"  "0000-11-30"  "0000-12-01"  "0000-12-02"  "0000-12-03" 
#> [351] "0000-12-04"  "0000-12-05"  "0000-12-06"  "0000-12-07"  "0000-12-08" 
#> [356] "0000-12-09"  "0000-12-10"  "0000-12-11"  "0000-12-12"  "0000-12-13" 
#> [361] "0000-12-14"  "0000-12-15"  "0000-12-16"  "0000-12-17"  "0000-12-18" 
#> [366] "0000-12-19"  "0000-12-20"  "0000-12-21"  "0000-12-22"  "0000-12-23" 
#> [371] "0000-12-24"  "0000-12-25"  "0000-12-26"  "0000-12-27"  "0000-12-28" 
#> [376] "0000-12-29"  "0000-12-30"  "0000-12-31"  "0001-01-01"  "0001-01-02" 
#> [381] "0001-01-03"  "0001-01-04"  "0001-01-05"  "0001-01-06"  "0001-01-07" 
#> [386] "0001-01-08"  "0001-01-09"  "0001-01-10" 
# a range's endpoints are used when only 'from' is given
seq(as_messydate("2012-01-01..2012-01-05"))
#> [1] "2012-01-01" "2012-01-02" "2012-01-03" "2012-01-04" "2012-01-05"
# date-time sequences use a sub-day 'by'
seq(as_messydate("2019-03-01 09:00"), as_messydate("2019-03-01 12:00"),
    by = "hour")
#> [1] "2019-03-01 09:00:00" "2019-03-01 10:00:00" "2019-03-01 11:00:00"
#> [4] "2019-03-01 12:00:00"