Skip to content
This repository
tree: 91bd4ee969
Fetching contributors…

Cannot retrieve contributors at this time

file 64 lines (44 sloc) 1.918 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#' @include timespans.r
#' @include durations.r
#' @include intervals.r
#' @include periods.r
NULL

modulo_duration_by_duration <- function(dur, dur2)
dur - dur %/% dur2 * dur2



modulo_interval_by_duration <- function(int, dur)
interval(int@start + int@.Data %/% dur@.Data * dur, int_end(int))

modulo_interval_by_period <- function(int, per)
interval(int@start + int %/% per * per, int_end(int))



modulo_period_by_period <- function(per, per2)
per - per %/% per2 * per2



#' @export
setMethod("%%", signature(e1 = "Duration", e2 = "Duration"),
function(e1, e2) modulo_duration_by_duration(e1, e2))

#' @export
setMethod("%%", signature(e1 = "Duration", e2 = "Interval"), function(e1, e2) {
stop("Incompatible timespan classes:\n change class with as.duration() or put interval in numerator.")
})

#' @export
setMethod("%%", signature(e1 = "Duration", e2 = "Period"), function(e1, e2) {
stop("Incompatible timespan classes:\n change class with as.duration() or as.period()")
})



#' @export
setMethod("%%", signature(e1 = "Interval", e2 = "Duration"),
function(e1, e2) modulo_interval_by_duration(e1, e2))
#' @export
setMethod("%%", signature(e1 = "Interval", e2 = "Interval"),
function(e1, e2) stop("%% not defined for Interval class\nConsider setdiff()"))

#' @export
setMethod("%%", signature(e1 = "Interval", e2 = "Period"),
function(e1, e2) modulo_interval_by_period(e1, e2))

#' @export
setMethod("%%", signature(e1 = "Period", e2 = "Duration"), function(e1, e2) {
stop("Incompatible timespan classes:\n change class with as.duration() or as.period()")
})

#' @export
setMethod("%%", signature(e1 = "Period", e2 = "Interval"), function(e1, e2) {
stop("Incompatible timespan classes:\n change class with as.period() or put interval in numerator.")
})

#' @export
setMethod("%%", signature(e1 = "Period", e2 = "Period"),
function(e1, e2) modulo_period_by_period(e1, e2))
Something went wrong with that request. Please try again.