Skip to content

Commit

Permalink
Add is_calendar()
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Jan 3, 2025
1 parent e18f952 commit 7f7f5db
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 18 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ exportMethods(frequency)
exportMethods(get_calendar)
exportMethods(image)
exportMethods(intervals)
exportMethods(is_calendar)
exportMethods(is_gregorian)
exportMethods(is_julian)
exportMethods(overlap)
Expand Down
14 changes: 8 additions & 6 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,24 @@ setGeneric(
#' Test inheritance relationships between an object and a calendar class.
#' @param object Any \R object.
#' @return
#' A [`logical`] vector.
#' A [`logical`] scalar.
#' @author N. Frerebeau
#' @docType methods
#' @family calendar tools
#' @name is
#' @rdname is
NULL
#' @aliases is_calendar-method
setGeneric(
name = "is_calendar",
def = function(object) standardGeneric("is_calendar")
)

#' @rdname is
#' @rdname is_calendar
#' @aliases is_gregorian-method
setGeneric(
name = "is_gregorian",
def = function(object) standardGeneric("is_gregorian")
)

#' @rdname is
#' @rdname is_calendar
#' @aliases is_julian-method
setGeneric(
name = "is_julian",
Expand Down
2 changes: 1 addition & 1 deletion R/calendar-gregorian.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ NULL

# Gregorian calendar ===========================================================
#' @export
#' @rdname is
#' @rdname is_calendar
#' @aliases is_gregorian,ANY-method
setMethod(
f = "is_gregorian",
Expand Down
2 changes: 1 addition & 1 deletion R/calendar-julian.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ NULL

# Julian calendar ==============================================================
#' @export
#' @rdname is
#' @rdname is_calendar
#' @aliases is_julian,ANY-method
setMethod(
f = "is_julian",
Expand Down
12 changes: 12 additions & 0 deletions R/calendar.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ setMethod(
}
)

# Predicates ===================================================================
#' @export
#' @rdname is_calendar
#' @aliases is_calendar,ANY-method
setMethod(
f = "is_calendar",
signature = "ANY",
definition = function(object) {
methods::is(object, "TimeScale")
}
)

# Mutators =====================================================================
## Getters ---------------------------------------------------------------------
#' @export
Expand Down
2 changes: 2 additions & 0 deletions inst/tinytest/test_calendar.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ expect_error(calendar("XXX"), "Unknown calendar")
# Gregorian calendar ===========================================================
G <- calendar("BP")

expect_true(is_calendar(G))
expect_true(is_gregorian(G))
expect_false(is_julian(G))

Expand All @@ -30,6 +31,7 @@ expect_identical(calendar_year(G), 365.2425)
# Julian calendar ==============================================================
J <- calendar("julian")

expect_true(is_calendar(J))
expect_true(is_julian(J))
expect_false(is_gregorian(J))

Expand Down
2 changes: 1 addition & 1 deletion man/calendar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/calendar_get.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/convert.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/get_calendar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/gregorian.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions man/is.Rd → man/is_calendar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/julian.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7f7f5db

Please sign in to comment.