Skip to content

Commit

Permalink
[Fix #306] When needed double guess with preproc_wday=T
Browse files Browse the repository at this point in the history
  • Loading branch information
vspinu committed Apr 23, 2015
1 parent c78a652 commit cb3b6d5
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions R/guess.r
Expand Up @@ -89,12 +89,6 @@ guess_formats <- function(x, orders, locale = Sys.getlocale("LC_TIME"),
})
reg <- .get_loc_regs(locale)

if( preproc_wday ){
## replace short/long weak days in current locale
x <- gsub(reg$alpha_exact[["A"]], "%A", x, ignore.case = T, perl = T)
x <- gsub(reg$alpha_exact[["a"]], "%a", x , ignore.case = T, perl = T)
}

REGS <- unlist(lapply(osplits, function(fnames){
## fnames are letters representing an individual valid format, like a, A, b, z, OS, OZ
which <- ! fnames %in% c(names(reg$alpha_flex), names(reg$num_flex))
Expand All @@ -115,14 +109,32 @@ guess_formats <- function(x, orders, locale = Sys.getlocale("LC_TIME"),
print(do.call(cbind, c(list(x), subs)))
}

out <- mapply(
function(reg, name){
out <- .substitute_formats(reg, x)
if( !is.null(out) ) names(out) <- rep.int(name, length(out))
out
}, REGS, orders, SIMPLIFY= F, USE.NAMES= F)
names(out) <- NULL
unlist(out)
.mapords <- function(regs, orders, x){
out <- mapply(
function(reg, name){
out <- .substitute_formats(reg, x)
if( !is.null(out) ) names(out) <- rep.int(name, length(out))
out
}, REGS, orders, SIMPLIFY= F, USE.NAMES= F)
names(out) <- NULL
unlist(out)
}

if( preproc_wday ){
## replace short/long weak days in current locale
x2 <- gsub(reg$alpha_exact[["A"]], "%A", x, ignore.case = T, perl = T)
x2 <- gsub(reg$alpha_exact[["a"]], "%a", x2, ignore.case = T, perl = T)
formats <- .mapords(REGS, orders, x2)

## In some locales abreviated day (italian "gio") is part of month name
## ("maggio"). So check if %a or %A is present and append wday-less formats.
if (any(grepl("%[aA]", formats)))
c(formats, .mapords(REGS, orders, x))
else
formats
} else {
.mapords(REGS, orders, x)
}
}


Expand Down

0 comments on commit cb3b6d5

Please sign in to comment.