These functions expand on date ranges, sets of dates, and unspecified or approximate dates (annotated with '..', '', 'XX' or '~'). As these messydates may refer to several possible dates, the function "opens" these values to reveal a vector of all the possible dates implied. Imprecise dates (dates only containing information on year and/or month) are also expanded to include possible dates within that year and/or month. The function removes the annotation from dates with unreliable sources ('?'), before being expanded normally as though they were incomplete.
Arguments
- x
A
mdateobject. If not an 'mdate' object, conversion is handled first with ´as_messydate()´.- approx_range
Range to expand approximate dates, or date components, annotated with '~', by default 0. That is, removes signs for approximate dates and treats these dates as precise dates. If 3, for example, adds 3 days for day approximation, 3 months for month approximation, 3 years for year/whole date approximation, 3 years and 3 months for year-month approximation, and 3 months and 3 days for month-day approximation.
- by
Granularity of enumeration, "day" by default. To avoid combinatorial explosion, ranges are enumerated at day granularity and any time-of-day components on ranges are dropped. Precise date-times (i.e. non-ranges) keep their time. Set
byto a sub-day unit ("hour", "min", or "sec") to opt in to finer enumeration of precise date-time ranges.
Examples
d <- as_messydate(c("2008-03-25", "-2012-02-27", "2001-01?", "~2001",
"2001-01-01..2001-02-02", "{2001-01-01,2001-02-02}", "{2001-01,2001-02-02}",
"2008-XX-31", "..2002-02-03", "2001-01-03..", "28 BC"))
expand(d)
#> [[1]]
#> [1] "2008-03-25"
#>
#> [[2]]
#> [1] "-2012-02-27"
#>
#> [[3]]
#> [1] "2001-01-01" "2001-01-02" "2001-01-03" "2001-01-04" "2001-01-05"
#> [6] "2001-01-06" "2001-01-07" "2001-01-08" "2001-01-09" "2001-01-10"
#> [11] "2001-01-11" "2001-01-12" "2001-01-13" "2001-01-14" "2001-01-15"
#> [16] "2001-01-16" "2001-01-17" "2001-01-18" "2001-01-19" "2001-01-20"
#> [21] "2001-01-21" "2001-01-22" "2001-01-23" "2001-01-24" "2001-01-25"
#> [26] "2001-01-26" "2001-01-27" "2001-01-28" "2001-01-29" "2001-01-30"
#> [31] "2001-01-31"
#>
#> [[4]]
#> [1] "2001-01-01" "2001-01-02" "2001-01-03" "2001-01-04" "2001-01-05"
#> [6] "2001-01-06" "2001-01-07" "2001-01-08" "2001-01-09" "2001-01-10"
#> [11] "2001-01-11" "2001-01-12" "2001-01-13" "2001-01-14" "2001-01-15"
#> [16] "2001-01-16" "2001-01-17" "2001-01-18" "2001-01-19" "2001-01-20"
#> [21] "2001-01-21" "2001-01-22" "2001-01-23" "2001-01-24" "2001-01-25"
#> [26] "2001-01-26" "2001-01-27" "2001-01-28" "2001-01-29" "2001-01-30"
#> [31] "2001-01-31" "2001-02-01" "2001-02-02" "2001-02-03" "2001-02-04"
#> [36] "2001-02-05" "2001-02-06" "2001-02-07" "2001-02-08" "2001-02-09"
#> [41] "2001-02-10" "2001-02-11" "2001-02-12" "2001-02-13" "2001-02-14"
#> [46] "2001-02-15" "2001-02-16" "2001-02-17" "2001-02-18" "2001-02-19"
#> [51] "2001-02-20" "2001-02-21" "2001-02-22" "2001-02-23" "2001-02-24"
#> [56] "2001-02-25" "2001-02-26" "2001-02-27" "2001-02-28" "2001-03-01"
#> [61] "2001-03-02" "2001-03-03" "2001-03-04" "2001-03-05" "2001-03-06"
#> [66] "2001-03-07" "2001-03-08" "2001-03-09" "2001-03-10" "2001-03-11"
#> [71] "2001-03-12" "2001-03-13" "2001-03-14" "2001-03-15" "2001-03-16"
#> [76] "2001-03-17" "2001-03-18" "2001-03-19" "2001-03-20" "2001-03-21"
#> [81] "2001-03-22" "2001-03-23" "2001-03-24" "2001-03-25" "2001-03-26"
#> [86] "2001-03-27" "2001-03-28" "2001-03-29" "2001-03-30" "2001-03-31"
#> [91] "2001-04-01" "2001-04-02" "2001-04-03" "2001-04-04" "2001-04-05"
#> [96] "2001-04-06" "2001-04-07" "2001-04-08" "2001-04-09" "2001-04-10"
#> [101] "2001-04-11" "2001-04-12" "2001-04-13" "2001-04-14" "2001-04-15"
#> [106] "2001-04-16" "2001-04-17" "2001-04-18" "2001-04-19" "2001-04-20"
#> [111] "2001-04-21" "2001-04-22" "2001-04-23" "2001-04-24" "2001-04-25"
#> [116] "2001-04-26" "2001-04-27" "2001-04-28" "2001-04-29" "2001-04-30"
#> [121] "2001-05-01" "2001-05-02" "2001-05-03" "2001-05-04" "2001-05-05"
#> [126] "2001-05-06" "2001-05-07" "2001-05-08" "2001-05-09" "2001-05-10"
#> [131] "2001-05-11" "2001-05-12" "2001-05-13" "2001-05-14" "2001-05-15"
#> [136] "2001-05-16" "2001-05-17" "2001-05-18" "2001-05-19" "2001-05-20"
#> [141] "2001-05-21" "2001-05-22" "2001-05-23" "2001-05-24" "2001-05-25"
#> [146] "2001-05-26" "2001-05-27" "2001-05-28" "2001-05-29" "2001-05-30"
#> [151] "2001-05-31" "2001-06-01" "2001-06-02" "2001-06-03" "2001-06-04"
#> [156] "2001-06-05" "2001-06-06" "2001-06-07" "2001-06-08" "2001-06-09"
#> [161] "2001-06-10" "2001-06-11" "2001-06-12" "2001-06-13" "2001-06-14"
#> [166] "2001-06-15" "2001-06-16" "2001-06-17" "2001-06-18" "2001-06-19"
#> [171] "2001-06-20" "2001-06-21" "2001-06-22" "2001-06-23" "2001-06-24"
#> [176] "2001-06-25" "2001-06-26" "2001-06-27" "2001-06-28" "2001-06-29"
#> [181] "2001-06-30" "2001-07-01" "2001-07-02" "2001-07-03" "2001-07-04"
#> [186] "2001-07-05" "2001-07-06" "2001-07-07" "2001-07-08" "2001-07-09"
#> [191] "2001-07-10" "2001-07-11" "2001-07-12" "2001-07-13" "2001-07-14"
#> [196] "2001-07-15" "2001-07-16" "2001-07-17" "2001-07-18" "2001-07-19"
#> [201] "2001-07-20" "2001-07-21" "2001-07-22" "2001-07-23" "2001-07-24"
#> [206] "2001-07-25" "2001-07-26" "2001-07-27" "2001-07-28" "2001-07-29"
#> [211] "2001-07-30" "2001-07-31" "2001-08-01" "2001-08-02" "2001-08-03"
#> [216] "2001-08-04" "2001-08-05" "2001-08-06" "2001-08-07" "2001-08-08"
#> [221] "2001-08-09" "2001-08-10" "2001-08-11" "2001-08-12" "2001-08-13"
#> [226] "2001-08-14" "2001-08-15" "2001-08-16" "2001-08-17" "2001-08-18"
#> [231] "2001-08-19" "2001-08-20" "2001-08-21" "2001-08-22" "2001-08-23"
#> [236] "2001-08-24" "2001-08-25" "2001-08-26" "2001-08-27" "2001-08-28"
#> [241] "2001-08-29" "2001-08-30" "2001-08-31" "2001-09-01" "2001-09-02"
#> [246] "2001-09-03" "2001-09-04" "2001-09-05" "2001-09-06" "2001-09-07"
#> [251] "2001-09-08" "2001-09-09" "2001-09-10" "2001-09-11" "2001-09-12"
#> [256] "2001-09-13" "2001-09-14" "2001-09-15" "2001-09-16" "2001-09-17"
#> [261] "2001-09-18" "2001-09-19" "2001-09-20" "2001-09-21" "2001-09-22"
#> [266] "2001-09-23" "2001-09-24" "2001-09-25" "2001-09-26" "2001-09-27"
#> [271] "2001-09-28" "2001-09-29" "2001-09-30" "2001-10-01" "2001-10-02"
#> [276] "2001-10-03" "2001-10-04" "2001-10-05" "2001-10-06" "2001-10-07"
#> [281] "2001-10-08" "2001-10-09" "2001-10-10" "2001-10-11" "2001-10-12"
#> [286] "2001-10-13" "2001-10-14" "2001-10-15" "2001-10-16" "2001-10-17"
#> [291] "2001-10-18" "2001-10-19" "2001-10-20" "2001-10-21" "2001-10-22"
#> [296] "2001-10-23" "2001-10-24" "2001-10-25" "2001-10-26" "2001-10-27"
#> [301] "2001-10-28" "2001-10-29" "2001-10-30" "2001-10-31" "2001-11-01"
#> [306] "2001-11-02" "2001-11-03" "2001-11-04" "2001-11-05" "2001-11-06"
#> [311] "2001-11-07" "2001-11-08" "2001-11-09" "2001-11-10" "2001-11-11"
#> [316] "2001-11-12" "2001-11-13" "2001-11-14" "2001-11-15" "2001-11-16"
#> [321] "2001-11-17" "2001-11-18" "2001-11-19" "2001-11-20" "2001-11-21"
#> [326] "2001-11-22" "2001-11-23" "2001-11-24" "2001-11-25" "2001-11-26"
#> [331] "2001-11-27" "2001-11-28" "2001-11-29" "2001-11-30" "2001-12-01"
#> [336] "2001-12-02" "2001-12-03" "2001-12-04" "2001-12-05" "2001-12-06"
#> [341] "2001-12-07" "2001-12-08" "2001-12-09" "2001-12-10" "2001-12-11"
#> [346] "2001-12-12" "2001-12-13" "2001-12-14" "2001-12-15" "2001-12-16"
#> [351] "2001-12-17" "2001-12-18" "2001-12-19" "2001-12-20" "2001-12-21"
#> [356] "2001-12-22" "2001-12-23" "2001-12-24" "2001-12-25" "2001-12-26"
#> [361] "2001-12-27" "2001-12-28" "2001-12-29" "2001-12-30" "2001-12-31"
#>
#> [[5]]
#> [1] "2001-01-01" "2001-01-02" "2001-01-03" "2001-01-04" "2001-01-05"
#> [6] "2001-01-06" "2001-01-07" "2001-01-08" "2001-01-09" "2001-01-10"
#> [11] "2001-01-11" "2001-01-12" "2001-01-13" "2001-01-14" "2001-01-15"
#> [16] "2001-01-16" "2001-01-17" "2001-01-18" "2001-01-19" "2001-01-20"
#> [21] "2001-01-21" "2001-01-22" "2001-01-23" "2001-01-24" "2001-01-25"
#> [26] "2001-01-26" "2001-01-27" "2001-01-28" "2001-01-29" "2001-01-30"
#> [31] "2001-01-31" "2001-02-01" "2001-02-02"
#>
#> [[6]]
#> [1] "2001-01-01" "2001-02-02"
#>
#> [[7]]
#> [1] "2001-01-01" "2001-01-02" "2001-01-03" "2001-01-04" "2001-01-05"
#> [6] "2001-01-06" "2001-01-07" "2001-01-08" "2001-01-09" "2001-01-10"
#> [11] "2001-01-11" "2001-01-12" "2001-01-13" "2001-01-14" "2001-01-15"
#> [16] "2001-01-16" "2001-01-17" "2001-01-18" "2001-01-19" "2001-01-20"
#> [21] "2001-01-21" "2001-01-22" "2001-01-23" "2001-01-24" "2001-01-25"
#> [26] "2001-01-26" "2001-01-27" "2001-01-28" "2001-01-29" "2001-01-30"
#> [31] "2001-01-31" "2001-02-02"
#>
#> [[8]]
#> [1] "2008-01-31" "2008-02-28" "2008-03-31" "2008-04-30" "2008-05-31"
#> [6] "2008-06-30" "2008-07-31" "2008-08-31" "2008-09-30" "2008-10-31"
#> [11] "2008-11-30" "2008-12-31"
#>
#> [[9]]
#> [1] "2002-02-03"
#>
#> [[10]]
#> [1] "2001-01-03"
#>
#> [[11]]
#> [1] "-0027-01-01" "-0027-01-02" "-0027-01-03" "-0027-01-04" "-0027-01-05"
#> [6] "-0027-01-06" "-0027-01-07" "-0027-01-08" "-0027-01-09" "-0027-01-10"
#> [11] "-0027-01-11" "-0027-01-12" "-0027-01-13" "-0027-01-14" "-0027-01-15"
#> [16] "-0027-01-16" "-0027-01-17" "-0027-01-18" "-0027-01-19" "-0027-01-20"
#> [21] "-0027-01-21" "-0027-01-22" "-0027-01-23" "-0027-01-24" "-0027-01-25"
#> [26] "-0027-01-26" "-0027-01-27" "-0027-01-28" "-0027-01-29" "-0027-01-30"
#> [31] "-0027-01-31" "-0027-02-01" "-0027-02-02" "-0027-02-03" "-0027-02-04"
#> [36] "-0027-02-05" "-0027-02-06" "-0027-02-07" "-0027-02-08" "-0027-02-09"
#> [41] "-0027-02-10" "-0027-02-11" "-0027-02-12" "-0027-02-13" "-0027-02-14"
#> [46] "-0027-02-15" "-0027-02-16" "-0027-02-17" "-0027-02-18" "-0027-02-19"
#> [51] "-0027-02-20" "-0027-02-21" "-0027-02-22" "-0027-02-23" "-0027-02-24"
#> [56] "-0027-02-25" "-0027-02-26" "-0027-02-27" "-0027-02-28" "-0027-03-01"
#> [61] "-0027-03-02" "-0027-03-03" "-0027-03-04" "-0027-03-05" "-0027-03-06"
#> [66] "-0027-03-07" "-0027-03-08" "-0027-03-09" "-0027-03-10" "-0027-03-11"
#> [71] "-0027-03-12" "-0027-03-13" "-0027-03-14" "-0027-03-15" "-0027-03-16"
#> [76] "-0027-03-17" "-0027-03-18" "-0027-03-19" "-0027-03-20" "-0027-03-21"
#> [81] "-0027-03-22" "-0027-03-23" "-0027-03-24" "-0027-03-25" "-0027-03-26"
#> [86] "-0027-03-27" "-0027-03-28" "-0027-03-29" "-0027-03-30" "-0027-03-31"
#> [91] "-0027-04-01" "-0027-04-02" "-0027-04-03" "-0027-04-04" "-0027-04-05"
#> [96] "-0027-04-06" "-0027-04-07" "-0027-04-08" "-0027-04-09" "-0027-04-10"
#> [101] "-0027-04-11" "-0027-04-12" "-0027-04-13" "-0027-04-14" "-0027-04-15"
#> [106] "-0027-04-16" "-0027-04-17" "-0027-04-18" "-0027-04-19" "-0027-04-20"
#> [111] "-0027-04-21" "-0027-04-22" "-0027-04-23" "-0027-04-24" "-0027-04-25"
#> [116] "-0027-04-26" "-0027-04-27" "-0027-04-28" "-0027-04-29" "-0027-04-30"
#> [121] "-0027-05-01" "-0027-05-02" "-0027-05-03" "-0027-05-04" "-0027-05-05"
#> [126] "-0027-05-06" "-0027-05-07" "-0027-05-08" "-0027-05-09" "-0027-05-10"
#> [131] "-0027-05-11" "-0027-05-12" "-0027-05-13" "-0027-05-14" "-0027-05-15"
#> [136] "-0027-05-16" "-0027-05-17" "-0027-05-18" "-0027-05-19" "-0027-05-20"
#> [141] "-0027-05-21" "-0027-05-22" "-0027-05-23" "-0027-05-24" "-0027-05-25"
#> [146] "-0027-05-26" "-0027-05-27" "-0027-05-28" "-0027-05-29" "-0027-05-30"
#> [151] "-0027-05-31" "-0027-06-01" "-0027-06-02" "-0027-06-03" "-0027-06-04"
#> [156] "-0027-06-05" "-0027-06-06" "-0027-06-07" "-0027-06-08" "-0027-06-09"
#> [161] "-0027-06-10" "-0027-06-11" "-0027-06-12" "-0027-06-13" "-0027-06-14"
#> [166] "-0027-06-15" "-0027-06-16" "-0027-06-17" "-0027-06-18" "-0027-06-19"
#> [171] "-0027-06-20" "-0027-06-21" "-0027-06-22" "-0027-06-23" "-0027-06-24"
#> [176] "-0027-06-25" "-0027-06-26" "-0027-06-27" "-0027-06-28" "-0027-06-29"
#> [181] "-0027-06-30" "-0027-07-01" "-0027-07-02" "-0027-07-03" "-0027-07-04"
#> [186] "-0027-07-05" "-0027-07-06" "-0027-07-07" "-0027-07-08" "-0027-07-09"
#> [191] "-0027-07-10" "-0027-07-11" "-0027-07-12" "-0027-07-13" "-0027-07-14"
#> [196] "-0027-07-15" "-0027-07-16" "-0027-07-17" "-0027-07-18" "-0027-07-19"
#> [201] "-0027-07-20" "-0027-07-21" "-0027-07-22" "-0027-07-23" "-0027-07-24"
#> [206] "-0027-07-25" "-0027-07-26" "-0027-07-27" "-0027-07-28" "-0027-07-29"
#> [211] "-0027-07-30" "-0027-07-31" "-0027-08-01" "-0027-08-02" "-0027-08-03"
#> [216] "-0027-08-04" "-0027-08-05" "-0027-08-06" "-0027-08-07" "-0027-08-08"
#> [221] "-0027-08-09" "-0027-08-10" "-0027-08-11" "-0027-08-12" "-0027-08-13"
#> [226] "-0027-08-14" "-0027-08-15" "-0027-08-16" "-0027-08-17" "-0027-08-18"
#> [231] "-0027-08-19" "-0027-08-20" "-0027-08-21" "-0027-08-22" "-0027-08-23"
#> [236] "-0027-08-24" "-0027-08-25" "-0027-08-26" "-0027-08-27" "-0027-08-28"
#> [241] "-0027-08-29" "-0027-08-30" "-0027-08-31" "-0027-09-01" "-0027-09-02"
#> [246] "-0027-09-03" "-0027-09-04" "-0027-09-05" "-0027-09-06" "-0027-09-07"
#> [251] "-0027-09-08" "-0027-09-09" "-0027-09-10" "-0027-09-11" "-0027-09-12"
#> [256] "-0027-09-13" "-0027-09-14" "-0027-09-15" "-0027-09-16" "-0027-09-17"
#> [261] "-0027-09-18" "-0027-09-19" "-0027-09-20" "-0027-09-21" "-0027-09-22"
#> [266] "-0027-09-23" "-0027-09-24" "-0027-09-25" "-0027-09-26" "-0027-09-27"
#> [271] "-0027-09-28" "-0027-09-29" "-0027-09-30" "-0027-10-01" "-0027-10-02"
#> [276] "-0027-10-03" "-0027-10-04" "-0027-10-05" "-0027-10-06" "-0027-10-07"
#> [281] "-0027-10-08" "-0027-10-09" "-0027-10-10" "-0027-10-11" "-0027-10-12"
#> [286] "-0027-10-13" "-0027-10-14" "-0027-10-15" "-0027-10-16" "-0027-10-17"
#> [291] "-0027-10-18" "-0027-10-19" "-0027-10-20" "-0027-10-21" "-0027-10-22"
#> [296] "-0027-10-23" "-0027-10-24" "-0027-10-25" "-0027-10-26" "-0027-10-27"
#> [301] "-0027-10-28" "-0027-10-29" "-0027-10-30" "-0027-10-31" "-0027-11-01"
#> [306] "-0027-11-02" "-0027-11-03" "-0027-11-04" "-0027-11-05" "-0027-11-06"
#> [311] "-0027-11-07" "-0027-11-08" "-0027-11-09" "-0027-11-10" "-0027-11-11"
#> [316] "-0027-11-12" "-0027-11-13" "-0027-11-14" "-0027-11-15" "-0027-11-16"
#> [321] "-0027-11-17" "-0027-11-18" "-0027-11-19" "-0027-11-20" "-0027-11-21"
#> [326] "-0027-11-22" "-0027-11-23" "-0027-11-24" "-0027-11-25" "-0027-11-26"
#> [331] "-0027-11-27" "-0027-11-28" "-0027-11-29" "-0027-11-30" "-0027-12-01"
#> [336] "-0027-12-02" "-0027-12-03" "-0027-12-04" "-0027-12-05" "-0027-12-06"
#> [341] "-0027-12-07" "-0027-12-08" "-0027-12-09" "-0027-12-10" "-0027-12-11"
#> [346] "-0027-12-12" "-0027-12-13" "-0027-12-14" "-0027-12-15" "-0027-12-16"
#> [351] "-0027-12-17" "-0027-12-18" "-0027-12-19" "-0027-12-20" "-0027-12-21"
#> [356] "-0027-12-22" "-0027-12-23" "-0027-12-24" "-0027-12-25" "-0027-12-26"
#> [361] "-0027-12-27" "-0027-12-28" "-0027-12-29" "-0027-12-30" "-0027-12-31"
#>
# widen an approximate day (the '~' before the day) by 3 days either side
expand(as_messydate("2001-01-~15"), approx_range = 3)
#> [[1]]
#> [1] "2001-01-12" "2001-01-13" "2001-01-14" "2001-01-15" "2001-01-16"
#> [6] "2001-01-17" "2001-01-18"
#>
# a precise date-time is returned unchanged, keeping its time
expand(as_messydate("2012-01-01 14:30:00"))
#> [[1]]
#> [1] "2012-01-01 14:30:00"
#>
# a date-time range drops its time by default (day granularity)...
expand(as_messydate("2019-03-01 09:00..2019-03-01 12:00"))
#> [[1]]
#> [1] "2019-03-01"
#>
# ...unless a sub-day 'by' is requested
expand(as_messydate("2019-03-01 09:00..2019-03-01 12:00"), by = "hour")
#> [[1]]
#> [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"
#>