Skip to content

Commit beb8696

Browse files
author
Stefan Fleck
committed
fix parsing pattern for month == 10 in ym() and my()
1 parent cbc294b commit beb8696

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Type: Package
22
Package: dint
33
Title: A Toolkit for Year-Quarter, Year-Month and Year-Isoweek
44
Dates
5-
Version: 2.1.0.9002
5+
Version: 2.1.0.9003
66
Authors@R:
77
person(given = "Stefan",
88
family = "Fleck",

R/parser.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ ym <- function(x, quiet = FALSE){
6363
assert(is.character(x), "'x' must be a character vector")
6464
assert(is_scalar_bool(quiet))
6565

66-
r <- vapply(x, parse_ym, integer(1), pattern = "^[^0-9]*\\d{4}[^0-9]*((0[1-9])|11|12)[^0-9]*$", USE.NAMES = FALSE)
66+
r <- vapply(x, parse_ym, integer(1), pattern = "^[^0-9]*\\d{4}[^0-9]*((0[1-9])|10|11|12)[^0-9]*$", USE.NAMES = FALSE)
6767

6868
if (!quiet){
6969
failed <- sum(is.na(r)) - sum(is.na(x))
@@ -83,7 +83,7 @@ ym <- function(x, quiet = FALSE){
8383
#' @export
8484
my <- function(x, quiet = FALSE){
8585
assert(is.character(x), "'x' must be a character vector")
86-
r <- vapply(x, parse_my, integer(1), pattern = "^[^0-9]*((0[1-9])|11|12)[^0-9]*\\d{4}[^0-9]*$", USE.NAMES = FALSE)
86+
r <- vapply(x, parse_my, integer(1), pattern = "^[^0-9]*((0[1-9])|10|11|12)[^0-9]*\\d{4}[^0-9]*$", USE.NAMES = FALSE)
8787

8888
if (!quiet){
8989
failed <- sum(is.na(r)) - sum(is.na(x))
@@ -144,7 +144,7 @@ parse_ym <- function(x, pattern){
144144
as.integer(substr(string, pos, pos + length))
145145
}
146146

147-
pos_m <- regexpr("((0[1-9])|11|12)[^0-9]*$", x)
147+
pos_m <- regexpr("((0[1-9])|10|11|12)[^0-9]*$", x)
148148
month <- extr(x, pos_m, 1)
149149
x <- strtrim(x, pos_m - 1L)
150150

tests/testthat/test_parser.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test_that("yq/qy work as expected", {
3636

3737
test_that("ym/my work as expected", {
3838

39-
x <- c("dfw2018m02", "bl2017qasdg12sadgfas", "2017Q4", "blubb", "2017-2016", NA)
39+
x <- c("dfw2018m02", "bl2017qasdg12sadgfas", "2017Q4", "blubb", "2017-2016", NA, "gvship_ais_2019-M10.fst")
4040

4141
expect_warning(
4242
r <- as.integer(ym(x)),
@@ -45,7 +45,7 @@ test_that("ym/my work as expected", {
4545

4646
expect_identical(
4747
r,
48-
c(201802L, 201712L, NA_integer_, NA_integer_, NA_integer_, NA_integer_)
48+
c(201802L, 201712L, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 201910L)
4949
)
5050

5151

0 commit comments

Comments
 (0)