From de04f68fcaccc3eec9a9187ebf52ad4aae91dfa5 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sat, 3 Aug 2024 12:27:26 -0400 Subject: [PATCH 1/4] Update documentation with current version of roxygen2 --- DESCRIPTION | 2 +- R/parsedate-package.r | 3 +-- man/parsedate-package.Rd | 9 +++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 453e19a..0d9c9ce 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,5 +14,5 @@ Suggests: withr URL: https://github.com/gaborcsardi/parsedate BugReports: https://github.com/gaborcsardi/parsedate/issues -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Encoding: UTF-8 diff --git a/R/parsedate-package.r b/R/parsedate-package.r index 828ad09..fa48404 100644 --- a/R/parsedate-package.r +++ b/R/parsedate-package.r @@ -14,11 +14,10 @@ #' a specific ISO 8601 format. #' } #' -#' @docType package #' @name parsedate-package #' @useDynLib parsedate, .registration = TRUE, .fixes = "C_" -NULL +"_PACKAGE" ## Some simple utility functions. We used to take them from lubridate, ## but that brings in plyr, Rcpp, etc. Better to keep dependencies light. diff --git a/man/parsedate-package.Rd b/man/parsedate-package.Rd index 599e646..0651df5 100644 --- a/man/parsedate-package.Rd +++ b/man/parsedate-package.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/parsedate-package.r \docType{package} \name{parsedate-package} +\alias{parsedate} \alias{parsedate-package} \title{Parse date from any format, including ISO 8601} \description{ @@ -18,3 +19,11 @@ Three useful functions to parse and format dates. a specific ISO 8601 format. } } +\seealso{ +Useful links: +\itemize{ + \item \url{https://github.com/gaborcsardi/parsedate} + \item Report bugs at \url{https://github.com/gaborcsardi/parsedate/issues} +} + +} From cd1a212cc116e301c5fcfb0447c56aefd0396e00 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sat, 3 Aug 2024 12:30:48 -0400 Subject: [PATCH 2/4] Initial enabling of testthat 3rd edition --- DESCRIPTION | 3 ++- tests/testthat.R | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0d9c9ce..6f43597 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,9 +10,10 @@ Description: Parse dates automatically, without the need of License: GPL-2 Suggests: covr, - testthat, + testthat (>= 3.0.0), withr URL: https://github.com/gaborcsardi/parsedate BugReports: https://github.com/gaborcsardi/parsedate/issues RoxygenNote: 7.3.2 Encoding: UTF-8 +Config/testthat/edition: 3 diff --git a/tests/testthat.R b/tests/testthat.R index b009c91..2bf700e 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,8 +1,18 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + library(testthat) library(parsedate) test_check("parsedate") +# Package-specific modifications below here + run <- function(tz) { source("testthat/helper.R") withr::local_timezone(tz) From 4400b0503988a5be4057ad4d9b2f65b0b958fc2e Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sat, 3 Aug 2024 12:33:02 -0400 Subject: [PATCH 3/4] Update all tests for testthat 3rd edition --- tests/testthat/test-corner-cases.R | 15 +++++++-------- tests/testthat/test-git.r | 5 ++--- tests/testthat/test-iso8601.r | 9 ++++----- tests/testthat/test-time-zones.R | 3 +-- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/tests/testthat/test-corner-cases.R b/tests/testthat/test-corner-cases.R index c280dea..f0e3fa4 100644 --- a/tests/testthat/test-corner-cases.R +++ b/tests/testthat/test-corner-cases.R @@ -1,5 +1,4 @@ - -context("Dates and empty strings") +# Dates and empty strings ---- test_that("Bug #10 is fixed", { @@ -21,7 +20,7 @@ test_that("Empty strings are replaced by NAs", { actual <- parse_date(dates) expect_equal(expected, actual) - + }) test_that("White-space string is replaced by NAs", { @@ -31,7 +30,7 @@ test_that("White-space string is replaced by NAs", { actual <- parse_date(date) expect_equal(expected, actual) - + }) test_that("White-spaces are gracefully removed", { @@ -41,18 +40,18 @@ test_that("White-spaces are gracefully removed", { actual <- parse_date(date) expect_equal(expected, actual) - + }) test_that("Non-sensical input is removed", { - + date <- "?=)(!$§#$%" expected <- .POSIXct(NA_real_, "UTC") actual <- parse_date(date) - + expect_equal(expected, actual) - + }) test_that("Approx parameter is passed on", { diff --git a/tests/testthat/test-git.r b/tests/testthat/test-git.r index 6115ebd..d8c81a8 100644 --- a/tests/testthat/test-git.r +++ b/tests/testthat/test-git.r @@ -1,5 +1,4 @@ - -context("Git dates") +# Git dates ---- test_that("Filling in is correct", { @@ -30,7 +29,7 @@ test_that("Issue #3 is resolved", { d1 <- parse_date("20070809 14:35:42") d2 <- parse_date("2007-08-09 14:35:42") expect_equal(d1, d2) - + }) test_that("Issue #4 is resolved", { diff --git a/tests/testthat/test-iso8601.r b/tests/testthat/test-iso8601.r index 48d5127..aaca13d 100644 --- a/tests/testthat/test-iso8601.r +++ b/tests/testthat/test-iso8601.r @@ -1,5 +1,4 @@ - -context("ISO 8601 moment.js") +# ISO 8601 moment.js ---- ## http://momentjs.com/docs/#/parsing/string/ ## Slightly modified, because it is _not_ allowed to @@ -51,7 +50,7 @@ test_that("Examples from moment.js", { }) -context("ISO 8601 Pelago") +# ISO 8601 Pelago ---- ## http://www.pelagodesign.com/blog/2009/05/20/ ## iso-8601-date-validation-that-doesnt-suck/ @@ -107,7 +106,7 @@ test_that("Pelago examples", { }) -context("ISO 8601 Pelago non-matching") +# ISO 8601 Pelago non-matching ---- test_that("Pelago non-matching", { @@ -146,7 +145,7 @@ test_that("Pelago non-matching", { }) -context("ISO week dates") +# ISO week dates ---- test_that("Exotic ISO week dates are OK", { diff --git a/tests/testthat/test-time-zones.R b/tests/testthat/test-time-zones.R index 3b7dd30..aa3bb89 100644 --- a/tests/testthat/test-time-zones.R +++ b/tests/testthat/test-time-zones.R @@ -1,5 +1,4 @@ - -context("time zones") +# time zones ---- test_that("output time zone is always UTC", { expect_equal( From 6b080d3d218b32b43ad0601ea2766110e4558bf3 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sat, 3 Aug 2024 12:39:08 -0400 Subject: [PATCH 4/4] Update CI and readme badges --- .github/workflows/R-CMD-check.yaml | 20 +++++--------------- .github/workflows/pkgdown.yaml | 10 +++++++--- .github/workflows/pr-commands.yaml | 12 +++++++++--- .github/workflows/test-coverage.yaml | 25 ++++++++++++++++++------- README.Rmd | 3 +-- README.md | 25 ++++++++++++------------- 6 files changed, 52 insertions(+), 43 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index ee65ccb..d46a617 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,16 +1,14 @@ # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help -# -# NOTE: This workflow is overkill for most R packages and -# check-standard.yaml is likely a better choice. -# usethis::use_github_action("check-standard") will install it. on: push: branches: [main, master] pull_request: branches: [main, master] -name: R-CMD-check +name: R-CMD-check.yaml + +permissions: read-all jobs: R-CMD-check: @@ -23,26 +21,17 @@ jobs: matrix: config: - {os: macos-latest, r: 'release'} - - {os: windows-latest, r: 'release'} - # Use 3.6 to trigger usage of RTools35 - - {os: windows-latest, r: '3.6'} - # use 4.1 to check with rtools40's older compiler - - {os: windows-latest, r: '4.1'} - - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - {os: ubuntu-latest, r: 'release'} - {os: ubuntu-latest, r: 'oldrel-1'} - - {os: ubuntu-latest, r: 'oldrel-2'} - - {os: ubuntu-latest, r: 'oldrel-3'} - - {os: ubuntu-latest, r: 'oldrel-4'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -60,3 +49,4 @@ jobs: - uses: r-lib/actions/check-r-package@v2 with: upload-snapshots: true + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 087f0b0..4bbce75 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -9,7 +9,9 @@ on: types: [published] workflow_dispatch: -name: pkgdown +name: pkgdown.yaml + +permissions: read-all jobs: pkgdown: @@ -19,8 +21,10 @@ jobs: group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-pandoc@v2 @@ -39,7 +43,7 @@ jobs: - name: Deploy to GitHub pages 🚀 if: github.event_name != 'pull_request' - uses: JamesIves/github-pages-deploy-action@v4.4.1 + uses: JamesIves/github-pages-deploy-action@v4.5.0 with: clean: false branch: gh-pages diff --git a/.github/workflows/pr-commands.yaml b/.github/workflows/pr-commands.yaml index 71f335b..2edd93f 100644 --- a/.github/workflows/pr-commands.yaml +++ b/.github/workflows/pr-commands.yaml @@ -4,7 +4,9 @@ on: issue_comment: types: [created] -name: Commands +name: pr-commands.yaml + +permissions: read-all jobs: document: @@ -13,8 +15,10 @@ jobs: runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/pr-fetch@v2 with: @@ -50,8 +54,10 @@ jobs: runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/pr-fetch@v2 with: diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 2c5bb50..9882260 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -6,7 +6,9 @@ on: pull_request: branches: [main, master] -name: test-coverage +name: test-coverage.yaml + +permissions: read-all jobs: test-coverage: @@ -15,7 +17,7 @@ jobs: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-r@v2 with: @@ -23,28 +25,37 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::covr + extra-packages: any::covr, any::xml2 needs: coverage - name: Test coverage run: | - covr::codecov( + cov <- covr::package_coverage( quiet = FALSE, clean = FALSE, - install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package") + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") ) + covr::to_cobertura(cov) shell: Rscript {0} + - uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }} + file: ./cobertura.xml + plugin: noop + disable_search: true + token: ${{ secrets.CODECOV_TOKEN }} + - name: Show testthat output if: always() run: | ## -------------------------------------------------------------------- - find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true + find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true shell: bash - name: Upload test results if: failure() - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: coverage-test-failures path: ${{ runner.temp }}/package diff --git a/README.Rmd b/README.Rmd index f3016c6..2aeed18 100644 --- a/README.Rmd +++ b/README.Rmd @@ -8,8 +8,7 @@ output: github_document [![R build status](https://github.com/gaborcsardi/parsedate/workflows/R-CMD-check/badge.svg)](https://github.com/gaborcsardi/parsedate/actions) [![](https://www.r-pkg.org/badges/version/parsedate)](https://www.r-pkg.org/pkg/parsedate) [![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/parsedate)](https://r-pkg.org/pkg/parsedate) -[![Codecov test coverage](https://codecov.io/gh/gaborcsardi/parsedate/branch/main/graph/badge.svg)](https://app.codecov.io/gh/gaborcsardi/parsedate?branch=main) -[![R-CMD-check](https://github.com/gaborcsardi/parsedate/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/gaborcsardi/parsedate/actions/workflows/R-CMD-check.yaml) +[![Codecov test coverage](https://codecov.io/gh/gaborcsardi/parsedate/graph/badge.svg)](https://app.codecov.io/gh/gaborcsardi/parsedate) This R package has three functions for dealing with dates. diff --git a/README.md b/README.md index df686dc..a2ee8ea 100644 --- a/README.md +++ b/README.md @@ -9,19 +9,18 @@ status](https://github.com/gaborcsardi/parsedate/workflows/R-CMD-check/badge.svg [![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/parsedate)](https://r-pkg.org/pkg/parsedate) [![Codecov test -coverage](https://codecov.io/gh/gaborcsardi/parsedate/branch/main/graph/badge.svg)](https://app.codecov.io/gh/gaborcsardi/parsedate?branch=main) -[![R-CMD-check](https://github.com/gaborcsardi/parsedate/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/gaborcsardi/parsedate/actions/workflows/R-CMD-check.yaml) +coverage](https://codecov.io/gh/gaborcsardi/parsedate/graph/badge.svg)](https://app.codecov.io/gh/gaborcsardi/parsedate) This R package has three functions for dealing with dates. -- `parse_iso_8601` recognizes and parses all valid ISO 8601 date and - time formats. It can also be used as an ISO 8601 validator. -- `parse_date` can parse a date when you don’t know which format it is - in. First it tries all ISO 8601 formats. Then it tries git’s - versatile date parser. Lastly, it tries `as.POSIXct`. -- `format_iso_8601` formats a date (and time) in specific ISO 8601 - format. +- `parse_iso_8601` recognizes and parses all valid ISO 8601 date and + time formats. It can also be used as an ISO 8601 validator. +- `parse_date` can parse a date when you don’t know which format it is + in. First it tries all ISO 8601 formats. Then it tries git’s versatile + date parser. Lastly, it tries `as.POSIXct`. +- `format_iso_8601` formats a date (and time) in specific ISO 8601 + format. ## Limitations @@ -39,13 +38,13 @@ parse_date("april 15 1971") parse_date("april 15 1969") ``` - ## [1] "2022-04-15 UTC" + ## [1] "2024-04-15 UTC" ``` r parse_date("april 15 2110") ``` - ## [1] "2022-04-15 UTC" + ## [1] "2024-04-15 UTC" ## Parsing ISO 8601 dates @@ -214,13 +213,13 @@ parse_date("11/12/99") parse_date("03/20") ``` - ## [1] "2022-03-20 UTC" + ## [1] "2024-03-20 UTC" ``` r parse_date("12") ``` - ## [1] "2022-01-12 UTC" + ## [1] "2024-08-12 UTC" But not for this, because this is ISO 8601.