From 7412da55972439afec83bc43e1b154c2492f7317 Mon Sep 17 00:00:00 2001 From: Jan Marvin Garbuszus Date: Wed, 12 Jul 2023 21:21:13 +0200 Subject: [PATCH] pass datetime_created to genBaseCore() --- R/baseXML.R | 5 +++-- R/class-workbook.R | 12 ++++++------ tests/testthat/test-class-workbook-wrappers.R | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/R/baseXML.R b/R/baseXML.R index ebb65ce05..44578aa37 100644 --- a/R/baseXML.R +++ b/R/baseXML.R @@ -152,9 +152,10 @@ genBaseApp <- function() { ) } -genBaseCore <- function(creator = "", title = NULL, subject = NULL, category = NULL) { +genBaseCore <- function(creator = "", title = NULL, subject = NULL, category = NULL, datetimeCreated = NULL) { if (length(creator) > 1) creator <- paste0(creator, collapse = ";") + if (is.null(datetimeCreated)) datetimeCreated <- Sys.time() dc_creator <- xml_node_create("dc:creator", xml_children = creator) cp_lastMod <- xml_node_create("cp:lastModifiedBy", xml_children = creator) @@ -162,7 +163,7 @@ genBaseCore <- function(creator = "", title = NULL, subject = NULL, category = N xml_attributes = c( `xsi:type` = "dcterms:W3CDTF" ), - xml_children = format(as_POSIXct_utc(Sys.time()), "%Y-%m-%dT%H:%M:%SZ") + xml_children = format(as_POSIXct_utc(datetimeCreated), "%Y-%m-%dT%H:%M:%SZ") ) dc_title <- NULL diff --git a/R/class-workbook.R b/R/class-workbook.R index 0f282cd87..3bb15b82b 100644 --- a/R/class-workbook.R +++ b/R/class-workbook.R @@ -181,12 +181,12 @@ wbWorkbook <- R6::R6Class( #' @param ... additional arguments #' @return a `wbWorkbook` object initialize = function( - creator = NULL, - title = NULL, - subject = NULL, - category = NULL, + creator = NULL, + title = NULL, + subject = NULL, + category = NULL, datetime_created = Sys.time(), - theme = NULL, + theme = NULL, ... ) { @@ -7159,7 +7159,7 @@ wbWorkbook <- R6::R6Class( generate_base_core = function() { # how do self$datetimeCreated and genBaseCore time differ? - self$core <- genBaseCore(creator = self$creator, title = self$title, subject = self$subject, category = self$category) + self$core <- genBaseCore(creator = self$creator, title = self$title, subject = self$subject, category = self$category, datetimeCreated = self$datetimeCreated) invisible(self) }, diff --git a/tests/testthat/test-class-workbook-wrappers.R b/tests/testthat/test-class-workbook-wrappers.R index 107304fc2..849ee4875 100644 --- a/tests/testthat/test-class-workbook-wrappers.R +++ b/tests/testthat/test-class-workbook-wrappers.R @@ -133,7 +133,7 @@ test_that("wb_set_creators() is a wrapper", { test_that("wb_remove_creators() is a wrapper", { wb <- wb_workbook(creator = "myself") - expect_wrapper("remove_creators", params = list(creators = "myself")) + expect_wrapper("remove_creators", wb = wb, params = list(creators = "myself")) }) # wb_set_last_modified_by() ---------------------------------------------------