Skip to content

Commit

Permalink
Fix range construction
Browse files Browse the repository at this point in the history
When the time difference between 'start' and 'end' is smaller than
'time.period', the 'construct.*.ranges' functions produce wrong results.
This commit fixes that and updates the documentation of those functions.

This addresses #103.

Signed-off-by: Thomas Bock <[email protected]>
  • Loading branch information
bockthom committed Mar 19, 2018
1 parent 877888e commit 975ae4d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions util-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
##
## Copyright 2016-2017 by Claus Hunsen <[email protected]>
## Copyright 2016-2018 by Claus Hunsen <[email protected]>
## Copyright 2017 by Raphael Nömmer <[email protected]>
## Copyright 2017 by Christian Hechtl <[email protected]>
## Copyright 2017 by Felix Prasse <[email protected]>
## Copyright 2017 by Thomas Bock <[email protected]>
## Copyright 2017-2018 by Thomas Bock <[email protected]>
## All Rights Reserved.


Expand Down Expand Up @@ -312,6 +312,9 @@ construct.ranges = function(revs, sliding.window = FALSE, raw = FALSE) {
#' > ..++.
#' > ....+
#'
#' When the time difference between \code{start} and \code{end} is smaller than
#' \code{time.period}, just one range from \code{start} to \code{end} is constructed.
#'
#' Important: As the start of each range is supposed to be inclusive and the end of each range
#' exclusive, 1 second is added to \code{end}. This way, the date \code{end} will be *included*
#' in the last range.
Expand Down Expand Up @@ -347,6 +350,9 @@ construct.consecutive.ranges = function(start, end, time.period, raw = FALSE) {
#' overlapping ranges as in the function \code{construct.ranges} when \code{sliding.window}
#' is set to \code{TRUE}.
#'
#' When the time difference between \code{start} and \code{end} is smaller than
#' \code{time.period}, just one range from \code{start} to \code{end} is constructed.
#'
#' Important: As the start of each range is supposed to be inclusive and the end of each range
#' exclusive, 1 second is added to \code{end}. This way, the date \code{end} will be *included*
#' in the last range.
Expand Down Expand Up @@ -405,7 +411,12 @@ construct.overlapping.ranges = function(start, end, time.period, overlap, raw =
## handle end date properly
if (end.date > seq.end) {
bins.number = bins.number + 1
ranges.approx = c(ranges.approx, end.date)

if (seq.end == seq.start) {
ranges.approx = c(seq.start, end.date)
} else {
ranges.approx = c(ranges.approx, end.date)
}
}

## construct the raw ranges from the approximate ones
Expand Down Expand Up @@ -448,6 +459,9 @@ construct.overlapping.ranges = function(start, end, time.period, overlap, raw =
#' > +++.
#' > ++++
#'
#' When the time difference between \code{start} and \code{end} is smaller than
#' \code{time.period}, just one range from \code{start} to \code{end} is constructed.
#'
#' Important: As the start of each range is supposed to be inclusive and the end of each range
#' exclusive, 1 second is added to \code{end}. This way, the date \code{end} will be *included*
#' in the last range.
Expand Down

0 comments on commit 975ae4d

Please sign in to comment.