11# Group generics ----------------------------------------------------------
22
3+ # ' Maxima and Minima for date_xx
4+ # '
5+ # ' @param ... date_xx vectors. It is up to the user to ensure that they are
6+ # ' of the same subclass.
7+ # ' @param na.rm
8+ # '
9+ # ' @return
10+ # ' @export
11+ # '
12+ # ' @examples
313Summary.date_xx <- function (
414 ... ,
515 na.rm
@@ -8,14 +18,44 @@ Summary.date_xx <- function (
818 .Generic %in% c(" min" , " max" , " range" ),
919 .Generic , " not defined for 'date_xx' Objects"
1020 )
21+ dots <- list (... )
22+ class <- vapply(dots , which_date_xx , character (1 ))
23+ assert(
24+ all_are_identical(class ),
25+ " All inputs must have the same <date_xx> subclass"
26+ )
27+
1128 res <- NextMethod(.Generic )
12- class(res ) <- class(..1 )
13- res
29+
30+ switch (
31+ class [[1 ]],
32+ date_yq = as_date_yq(res ),
33+ date_ym = as_date_ym(res ),
34+ date_yw = as_date_yw(res ),
35+ date_y = as_date_y(res )
36+ )
1437}
1538
1639
1740
1841
42+ # ' Comparison Operators for date_xx
43+ # '
44+ # ' @param e1,e2 Objects with the same `date_xx` subclass (one of them can also
45+ # ' be integer)
46+ # '
47+ # ' @return a `logical` scalar
48+ # ' @export
49+ # '
50+ # ' @examples
51+ # ' date_yq(2015, 1) < date_yq(2015, 2)
52+ # '
53+ # ' # comparison with integers is ok
54+ # ' date_yq(2015, 1) < 20152
55+ # '
56+ # ' # but two different date_xx cannot be compared#'
57+ # ' try(date_yq(2015, 1) < date_ym(2015, 2))
58+ # '
1959Ops.date_xx <- function (
2060 e1 ,
2161 e2
0 commit comments