diff --git a/NEWS.md b/NEWS.md index ca184d6df..fb827382e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,9 @@ - Improved logging of what guider was used when using NotWorn and optional backup guider, #1156 - Skip night in part 4 csv report if guider was NotWorn, #1156 + +- Part 5: Fixed bug in g.part5.wakesleepwindows causing the first SPT window in a recording incorrectly to be defined from the first timestamp in the recording. For details see: #1192 + # CHANGES IN GGIR VERSION 3.1-3 diff --git a/R/g.part5.wakesleepwindows.R b/R/g.part5.wakesleepwindows.R index 07862e73c..45f4295dc 100644 --- a/R/g.part5.wakesleepwindows.R +++ b/R/g.part5.wakesleepwindows.R @@ -22,11 +22,10 @@ g.part5.wakesleepwindows = function(ts, part4_output, desiredtz, nightsi, w0 = w1 = rep(0,length(part4_output$calendar_date)) # Round seconds to integer number of epoch lengths (needed if cleaningcode = 5). round_seconds_to_epochSize = function(x, epochSize) { - temp = as.numeric(unlist(strsplit(x,":"))) - if (length(temp) == 3) { - if (temp[3] / epochSize != round(temp[3] / epochSize)) { - x = paste0(temp[1],":",temp[2],":",round(temp[3] / epochSize)*epochSize) - } + if (length(as.numeric(unlist(strsplit(x,":")))) == 3) { + xPOSIX = as.POSIXct(x, format = "%H:%M:%S") + xPOSIX_rounded = as.POSIXct(round(as.numeric(xPOSIX) / epochSize) * epochSize) + x = format(xPOSIX_rounded, format = "%H:%M:%S") } else { x = "" }