Skip to content

Commit

Permalink
Merge pull request #1 from kazuyanagimoto/dev
Browse files Browse the repository at this point in the history
v0.0.2
  • Loading branch information
kazuyanagimoto authored May 21, 2024
2 parents 82390e2 + 4b8697c commit 054752f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: typstcv
Type: Package
Title: CV for Quarto & Typst
Version: 0.0.1
Version: 0.0.2
Authors@R:
person(given = "Kazuharu",
family = "Yanagimoto",
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## 0.0.2

Bug Fixes:

- `format_date()` now correctly sorts after the formatting step. This was causing the dates to be sorted as strings, rather than as dates.

## 0.0.1

- Initial GitHub submission
31 changes: 20 additions & 11 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
#' @export
#'
#' @examples
#' work <- data.frame(
#' title = c("Technical Assistant", "Junior Professor", "Associate Professor"),
#' location = c("Bern, Switzerland", "Bern, Switzerland", "Zürich, Switzerland"),
#' start = as.Date(c("1902-01-01", "1908-01-01", "1909-01-01")),
#' end = as.Date(c("1908-01-01", "1909-01-01", "1911-01-01")),
#' description = c("Federal Patent Office", "University of Bern", "University of Zürich")
#' )
#'
#' work |>
#' format_date(end = "end", date_format = "%Y", sort_by = "start") |>
#' resume_entry()
Expand All @@ -29,6 +37,18 @@ format_date <- function(data,
sort_by = "none",
decreasing = TRUE) {

# Sort
if (sort_by == "start") {
data <- data[order(data[[start]], decreasing = decreasing), ]
} else if (sort_by == "end" && !is.null(end)) {
data <- data[order(data[[end]], decreasing = decreasing), ]
} else if (sort_by == "none") {
# Do nothing
} else {
stop("Invalid sort_by value. Use 'none', 'start' or 'end'")
}

# Format start date
data[[start]] <- format(data[[start]], date_format)
data[[start]][is.na(data[[start]])] <- replace_na

Expand All @@ -41,16 +61,5 @@ format_date <- function(data,
data[[colname_date]] <- paste(data[[start]], data[[end]], sep = sep)
}

# Sort
if (sort_by == "start") {
data <- data[order(data[[start]], decreasing = decreasing), ]
} else if (sort_by == "end" && !is.null(end)) {
data <- data[order(data[[end]], decreasing = decreasing), ]
} else if (sort_by == "none") {
# Do nothing
} else {
stop("Invalid sort_by value. Use 'none', 'start' or 'end'")
}

return(data)
}
8 changes: 8 additions & 0 deletions man/format_date.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 054752f

Please sign in to comment.