This function operates as the opposite of expand(). It contracts a list of dates into the abbreviated annotation of messy dates.

contract(x, collapse = TRUE)

Arguments

x

A list of dates

collapse

Do you want ranges to be collapsed? TRUE by default. If FALSE ranges are returned in compact format.

Value

A mdate vector

Details

The ´contract()´ function first expand() 'mdate' objects to then display their most succinct representation.

Examples

d <- as_messydate(c("2001-01-01", "2001-01", "2001",
"2001-01-01..2001-02-02", "{2001-10-01,2001-10-04}",
"{2001-01,2001-02-02}", "28 BC", "-2000-01-01",
"{2001-01-01, 2001-01-02, 2001-01-03}"))
tibble::tibble(d, contract(d))
#> # A tibble: 9 × 2
#>   d                                  `contract(d)`          
#>   <mdate>                            <mdate>                
#> 1 2001-01-01                         2001-01-01             
#> 2 2001-01                            2001-01                
#> 3 2001                               2001                   
#> 4 2001-01-01..2001-02-02             2001-01-01..2001-02-02 
#> 5 {2001-10-01,2001-10-04}            {2001-10-01,2001-10-04}
#> 6 {2001-01,2001-02-02}               {2001-01,2001-02-02}   
#> 7 -0028                              -0028                  
#> 8 -2000-01-01                        -2000-01-01            
#> 9 {2001-01-01,2001-01-02,2001-01-03} 2001-01-01..2001-01-03