Skip to content

Commit

Permalink
enforce a fixed date
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Jul 20, 2023
1 parent dd76c6d commit 29c2ef5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
18 changes: 11 additions & 7 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,14 @@ wbWorkbook <- R6::R6Class(
# USERNAME may only be present for windows
Sys.getenv("USERNAME", Sys.getenv("USER"))

assert_class(self$creator, "character")
assert_class(title, "character", or_null = TRUE)
assert_class(subject, "character", or_null = TRUE)
assert_class(category, "character", or_null = TRUE)
assert_class(datetime_created, "POSIXt")
self$datetimeCreated <- getOption("openxlsx2.datetimeCreated") %||%
datetime_created

assert_class(self$creator, "character")
assert_class(title, "character", or_null = TRUE)
assert_class(subject, "character", or_null = TRUE)
assert_class(category, "character", or_null = TRUE)
assert_class(self$datetimeCreated, "POSIXt")

stopifnot(
length(title) <= 1L,
Expand All @@ -308,7 +311,6 @@ wbWorkbook <- R6::R6Class(
self$title <- title
self$subject <- subject
self$category <- category
self$datetimeCreated <- datetime_created
private$generate_base_core()
private$current_sheet <- 0L
invisible(self)
Expand Down Expand Up @@ -3859,11 +3861,13 @@ wbWorkbook <- R6::R6Class(
done <- as_xml_attr(resolve)
if (reply) done <- NULL

ts <- getOption("openxlsx2.datetimeCreated") %||% Sys.time()

tc <- xml_node_create(
"threadedComment",
xml_attributes = c(
ref = dims,
dT = format(as_POSIXct_utc(Sys.time()), "%Y-%m-%dT%H:%M:%SZ"),
dT = format(as_POSIXct_utc(ts), "%Y-%m-%dT%H:%M:%SZ"),
personId = person_id,
id = cmt_id,
parentId = parentId,
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-Workbook_properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test_that("escaping in wbWorkbooks genBaseCore works as expected", {

nms <- xml_node_name(got, "cp:coreProperties")

for (nm in nms[nms != "cp:lastModifiedBy"]) {
for (nm in nms[!nms %in% c("cp:lastModifiedBy", "dcterms:created")]) {
expect_equal(
xml_node(got, "cp:coreProperties", nm),
xml_node(wb$core, "cp:coreProperties", nm)
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-aaa.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
test_that("testsetup", {

options("openxlsx2.datetimeCreated" = as.POSIXct("2023-07-20 23:32:14"))

if (Sys.getenv("openxlsx2_testthat_fullrun") == "") {
skip_on_ci()
}
Expand Down

0 comments on commit 29c2ef5

Please sign in to comment.