diff --git a/.Rbuildignore b/.Rbuildignore index 7c2ab61d..024e9860 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,5 +1,4 @@ -^messydatesDev\.Rproj$ -^devmessydates\.Rproj$ +^dev_messydates\.Rproj$ ^\.Rproj\.user$ ^README\.Rmd$ ^LICENSE\.md$ diff --git a/DESCRIPTION b/DESCRIPTION index 1b887e65..896c8d0f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,8 +9,8 @@ Description: Contains a set of tools for constructing and coercing date ranges, and sets of dates. This is useful for describing and analysing temporal information, whether historical or recent, where date precision may vary. -Version: 0.5.3 -Date: 2025-03-18 +Version: 0.5.4 +Date: 2025-06-02 Authors@R: c(person(given = "James", family = "Hollway", diff --git a/NEWS.md b/NEWS.md index 76a1bcb6..600de701 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# messydates 0.5.4 + +## Coercion + +- Improved how `as_messydates()` handles text with dates in American format, +e.g. October 10, 2010 (fixes #86) + # messydates 0.5.3 ## Components diff --git a/R/coerce_to_messydate.R b/R/coerce_to_messydate.R index 3003b80d..7d059fcd 100644 --- a/R/coerce_to_messydate.R +++ b/R/coerce_to_messydate.R @@ -441,6 +441,12 @@ extract_from_text <- function(v) { # get ordinal and numeric dates spelled and replace in text out <- stri_squish(stringi::stri_replace_all_regex(v, "\\,|\\.|of | on | and|the | this| | day|year|month", " ")) + #reorder American dates + if(length(out)==1 && grepl("^[A-z]", out)){ + out <- paste(stringi::stri_split_fixed(out, " ")[[1]][c(2,1,3)], + collapse = " ") + } + for (k in seq_len(nrow(text_to_number))) { out <- gsub(paste0(text_to_number$text[k]), paste0(text_to_number$numeric[k]), diff --git a/devmessydates.Rproj b/dev_messydates.Rproj similarity index 100% rename from devmessydates.Rproj rename to dev_messydates.Rproj diff --git a/tests/testthat/test-coerce_to.R b/tests/testthat/test-coerce_to.R index 0d37b39a..a748ae7e 100644 --- a/tests/testthat/test-coerce_to.R +++ b/tests/testthat/test-coerce_to.R @@ -5,7 +5,8 @@ test_that("Coercion from other date classes into messydt works", { character <- "2010-10-10" character2 <- "AD2010-10-10" character3 <- "{BC2010-10-10,BC2010-10-11,BC2010-10-12}" - month_text <- "10 October 2010" + dmy_text <- "10 October 2010" + mdy_text <- "October 10, 2010" messy <- as_messydate("2010-10-10") messyneg <- as_messydate("{-2010-10-10,-2010-10-11,-2010-10-12}") expect_equal(as_messydate(date), messy) @@ -14,14 +15,15 @@ test_that("Coercion from other date classes into messydt works", { expect_equal(as_messydate(character), messy) expect_equal(as_messydate(character2), messy) expect_equal(as_messydate(character3), messyneg) - expect_equal(as_messydate(month_text), messy) + expect_equal(as_messydate(dmy_text), messy) + expect_equal(as_messydate(mdy_text), messy) expect_equal(mdate(date), messy) expect_equal(mdate(POSIXct), messy) expect_equal(mdate(POSIXlt), messy) expect_equal(mdate(character), messy) expect_equal(mdate(character2), messy) expect_equal(mdate(character3), messyneg) - expect_equal(mdate(month_text), messy) + expect_equal(mdate(dmy_text), messy) }) test_that("Coercion of unespecified date components are properly handled", {