Skip to content

Commit

Permalink
Update style
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiromagno committed Nov 22, 2023
1 parent 53d8b5a commit 763f6da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
1 change: 0 additions & 1 deletion R/dtc_create_iso8601.R
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ format_iso8601 <- function(m, .cutoff_2000 = 68L) {
#'
#' @export
create_iso8601 <- function(..., .format, .fmt_c = fmt_cmp(), .na = NULL, .cutoff_2000 = 68L, .check_format = FALSE) {

assert_fmt_c(.fmt_c)

dots <- rlang::dots_list(...)
Expand Down
33 changes: 17 additions & 16 deletions R/parse_dttm_fmt.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,17 @@ fmt_cmp <- function(sec = "S+",
mday = "d+",
mon = "m+",
year = "y+") {
structure(list(
sec = sec,
min = min,
hour = hour,
mday = mday,
mon = mon,
year = year
),
class = "fmt_c")

structure(
list(
sec = sec,
min = min,
hour = hour,
mday = mday,
mon = mon,
year = year
),
class = "fmt_c"
)
}

assert_fmt_c <- function(x) {
Expand Down Expand Up @@ -297,17 +298,16 @@ fmt_dttmc <-
len = len,
ord = ord
)

}

#' @rdname parse_dttm_fmt
parse_dttm_fmt_ <- function(fmt, pattern) {

admiraldev::assert_character_scalar(fmt)
admiraldev::assert_character_scalar(pattern)

if (identical(nchar(pattern), 0L))
if (identical(nchar(pattern), 0L)) {
rlang::abort("`pattern` must be a literal string of at least one char.")
}

match_data <- regexpr(pattern, fmt)
match <- reg_matches(fmt, match_data)
Expand Down Expand Up @@ -378,14 +378,16 @@ parse_dttm_fmt <- function(fmt, patterns = fmt_cmp()) {

# Check if patterns have matching overlap, i.e. whether they are not
# mutually exclusive (as they should).
if (anyDuplicated(pseq(fmt_dttmc$start, fmt_dttmc$end)))
if (anyDuplicated(pseq(fmt_dttmc$start, fmt_dttmc$end))) {
rlang::abort("Patterns in `fmt_c` have overlapping matches.")
}

# Get captures' ranks while leaving NA as NA (`rank()` won't do this.)
fmt_dttmc$ord <- dplyr::row_number(fmt_dttmc$start)

if (identical(nrow(fmt_dttmc), 0L))
if (identical(nrow(fmt_dttmc), 0L)) {
return(fmt_dttmc())
}

fmt_len <- nchar(fmt)

Expand Down Expand Up @@ -437,7 +439,6 @@ parse_dttm_fmt <- function(fmt, patterns = fmt_cmp()) {
#'
#' @keywords internal
dttm_fmt_to_regex <- function(fmt, fmt_regex = fmt_rg(), fmt_c = fmt_cmp(), anchored = TRUE) {

tbl_fmt_c <- parse_dttm_fmt(fmt, patterns = fmt_c)

fmt_regex <-
Expand Down
5 changes: 0 additions & 5 deletions tests/testthat/test-parse_dttm_fmt.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
test_that("`parse_dttm_fmt_`: empty fmt", {

x <-
tibble::tibble(
pat = character(),
Expand All @@ -18,7 +17,6 @@ test_that("`parse_dttm_fmt_`: empty pattern", {
})

test_that("`parse_dttm_fmt_`: basic usage", {

fmt1 <- "y m d"
fmt2 <- "y-m-d"

Expand Down Expand Up @@ -58,7 +56,6 @@ test_that("`parse_dttm_fmt_`: basic usage", {
})

test_that("`parse_dttm_fmt_`: pattern variations", {

fmt <- "HH:MM:SS"

x1 <-
Expand Down Expand Up @@ -94,7 +91,6 @@ test_that("`parse_dttm_fmt_`: pattern variations", {
})

test_that("`parse_dttm_fmt_`: only the first match is returned", {

fmt <- "H M S H"

x1 <-
Expand Down Expand Up @@ -130,7 +126,6 @@ test_that("`parse_dttm_fmt_`: only the first match is returned", {
})

test_that("`parse_dttm_fmt`: empty fmt", {

expect_identical(fmt_dttmc(), parse_dttm_fmt("", pattern = "y"))
expect_error(parse_dttm_fmt_(character(), pattern = "y"))
})

0 comments on commit 763f6da

Please sign in to comment.