diff --git a/R/NcDataReader.R b/R/NcDataReader.R index 82131288a7e8b53d1edb9fc6467fd8a594e3b631..cba05fac8a5f721eb41c209437d5900722acb297 100644 --- a/R/NcDataReader.R +++ b/R/NcDataReader.R @@ -162,7 +162,7 @@ NcDataReader <- function(file_path = NULL, file_object = NULL, units <- 'days' } - new_array <- rep(as.POSIXct(parts[2]), length(result)) + + new_array <- rep(as.POSIXct(parts[2], tz = 'UTC'), length(result)) + as.difftime(result[], units = units) #new_array <- seq(as.POSIXct(parts[2]), # length = max(result, na.rm = TRUE) + 1, diff --git a/R/Start.R b/R/Start.R index c04894aa7aeb29ff89e939e4788cacd49d757c11..b23e0ebb82987abbaa6d968c33878198f68ff88f 100644 --- a/R/Start.R +++ b/R/Start.R @@ -1330,11 +1330,19 @@ Start <- function(..., # dim = indices/selectors, c(list(x = picked_common_vars[[var_to_read]]), var_store_indices, list(value = var_values))) + # Turn time zone back to UTC if this var_to_read is 'time' + if (all(class(picked_common_vars[[var_to_read]]) == c('POSIXct', 'POSIXt'))) { + attr(picked_common_vars[[var_to_read]], "tzone") <- 'UTC' + } } else { picked_vars[[i]][[var_to_read]] <- do.call('[<-', c(list(x = picked_vars[[i]][[var_to_read]]), var_store_indices, list(value = var_values))) + # Turn time zone back to UTC if this var_to_read is 'time' + if (all(class(picked_vars[[i]][[var_to_read]]) == c('POSIXct', 'POSIXt'))) { + attr(picked_vars[[i]][[var_to_read]], "tzone") <- 'UTC' + } } if (var_to_read %in% names(first_found_file)) { first_found_file[var_to_read] <- TRUE diff --git a/inst/doc/usecase/ex1_2_exp_obs_attr.R b/inst/doc/usecase/ex1_2_exp_obs_attr.R index 5a906f3ac2f4eecfb71eab374537290ee184c228..acff7c9167d19b7bee40e96913859c0982c310b3 100644 --- a/inst/doc/usecase/ex1_2_exp_obs_attr.R +++ b/inst/doc/usecase/ex1_2_exp_obs_attr.R @@ -97,12 +97,12 @@ print(attr(exp, 'Variables')$common$time) #[11] "2007-03-16 13:14:44 CET" "2008-03-16 13:14:44 CET" print(attr(obs, 'Variables')$common$time) -# [1] "2005-01-31 18:00:00 CET" "2006-01-31 18:00:00 CET" -# [3] "2007-01-31 18:00:00 CET" "2008-01-31 18:00:00 CET" -# [5] "2005-02-28 18:00:00 CET" "2006-02-28 18:00:00 CET" -# [7] "2007-02-28 18:00:00 CET" "2008-02-29 18:00:00 CET" -# [9] "2005-03-31 19:00:00 CEST" "2006-03-31 19:00:00 CEST" -#[11] "2007-03-31 19:00:00 CEST" "2008-03-31 19:00:00 CEST" +# [1] "2005-01-31 18:00:00 UTC" "2006-01-31 18:00:00 UTC" +# [3] "2007-01-31 18:00:00 UTC" "2008-01-31 18:00:00 UTC" +# [5] "2005-02-28 18:00:00 UTC" "2006-02-28 18:00:00 UTC" +# [7] "2007-02-28 18:00:00 UTC" "2008-02-29 18:00:00 UTC" +# [9] "2005-03-31 18:00:00 UTC" "2006-03-31 18:00:00 UTC" +#[11] "2007-03-31 18:00:00 UTC" "2008-03-31 18:00:00 UTC" ##-----lat----- print(attr(exp, 'Variables')$common$lat[1:3]) diff --git a/inst/doc/usecase/ex1_3_attr_loadin.R b/inst/doc/usecase/ex1_3_attr_loadin.R index 3dca648fa83851059679bb8356b28d7355e70c84..a918e167c6f23092d8d27690613061e98e7affd5 100644 --- a/inst/doc/usecase/ex1_3_attr_loadin.R +++ b/inst/doc/usecase/ex1_3_attr_loadin.R @@ -113,7 +113,7 @@ erai[1, 1, 2, 31, 1, 1] # 1st March also, since June only has 30 days dates <- attr(system4, 'Variables')$common$time dates[2, 31] -#[1] "1994-07-01 CEST" +#[1] "1994-07-01 UTC" dates[2, 31] <- NA # Jun dates[5, 31] <- NA # Sep dates[7, 31] <- NA # Nov @@ -141,4 +141,9 @@ erai[1, 1, 2, , 1, 1] # June # [9] 270.5395 272.0379 272.5489 271.1494 270.7764 270.5678 272.0331 273.7856 #[17] 273.9849 274.5904 273.4369 273.8404 274.4068 274.2292 274.7375 275.5104 #[25] 275.4324 274.9408 274.8679 276.5602 275.0995 274.6409 NA +erai[1, 1, 5, , 1, 1] # Sep +# [1] 270.0656 270.7113 268.4678 271.6489 271.2354 269.7831 269.8045 268.7994 +# [9] 266.3092 262.2734 265.0124 261.8378 265.3950 257.1690 255.8402 264.8826 +#[17] 267.8663 266.6875 262.5502 258.5476 258.9617 263.6396 257.1111 264.8644 +#[25] 261.0085 256.7690 256.5811 256.4331 256.1260 256.4716 NA #------------------------------