From ae64a954e727ab6f6a87aa52ab68f7feb49c5fb7 Mon Sep 17 00:00:00 2001 From: Ethan Bass Date: Tue, 17 Sep 2024 16:04:24 -0400 Subject: [PATCH] fix: wrong time zones returned by `strptime` --- R/grabMzmlFunctions.R | 3 ++- tests/testthat/test_chroms.R | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/R/grabMzmlFunctions.R b/R/grabMzmlFunctions.R index c59ff10..21eb5f6 100644 --- a/R/grabMzmlFunctions.R +++ b/R/grabMzmlFunctions.R @@ -283,7 +283,8 @@ grabMzmlMetadata <- function(xml_data){ time_node <- xml2::xml_find_first(xml_data, xpath = "//d1:run") time_val <- xml2::xml_attr(time_node, "startTimeStamp") if(!is.na(time_val)){ - time_stamp <- as.POSIXct(strptime(time_val, "%Y-%m-%dT%H:%M:%SZ")) + time_val <- sub("Z$", "+0000", time_val) + time_stamp <- as.POSIXct(strptime(time_val, "%Y-%m-%dT%H:%M:%S%z", tz="UTC")) } else { time_stamp <- as.POSIXct(NA) } diff --git a/tests/testthat/test_chroms.R b/tests/testthat/test_chroms.R index 1d79005..9ab4669 100644 --- a/tests/testthat/test_chroms.R +++ b/tests/testthat/test_chroms.R @@ -21,3 +21,8 @@ test_that("warning thrown when requesting chroms from mzXML", { expect_warning(grabMSdata(mzXML_filenames[2], grab_what = "chroms"), regexp = "grab_what = 'chroms' not available for mzXML documents") }) + +test_that("time stamp is correct", { + expect_identical(msdata_MRM_everything$metadata$timestamp, + as.POSIXct("2022-08-11 12:34:56",tz="UTC")) +})