Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
^messydatesDev\.Rproj$
^devmessydates\.Rproj$
^dev_messydates\.Rproj$
^\.Rproj\.user$
^README\.Rmd$
^LICENSE\.md$
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions R/coerce_to_messydate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
File renamed without changes.
8 changes: 5 additions & 3 deletions tests/testthat/test-coerce_to.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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", {
Expand Down
Loading