Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

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 12ae310
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 72 deletions.
5 changes: 3 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export(fixed_to_BP)
export(fixed_to_CE)
export(fixed_to_b2k)
export(fixed_to_julian)
export(is_calendar)
export(is_gregorian)
export(is_julian)
export(year_axis)
exportClasses(RataDie)
exportClasses(TimeIntervals)
Expand Down Expand Up @@ -67,8 +70,6 @@ exportMethods(frequency)
exportMethods(get_calendar)
exportMethods(image)
exportMethods(intervals)
exportMethods(is_gregorian)
exportMethods(is_julian)
exportMethods(overlap)
exportMethods(plot)
exportMethods(pretty)
Expand Down
27 changes: 0 additions & 27 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,33 +174,6 @@ setGeneric(
valueClass = "TimeScale"
)

#' Is an Object a Calendar?
#'
#' Test inheritance relationships between an object and a calendar class.
#' @param object Any \R object.
#' @return
#' A [`logical`] vector.
#' @author N. Frerebeau
#' @docType methods
#' @family calendar tools
#' @name is
#' @rdname is
NULL

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

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

#' Calendar Parameters
#'
#' @param object A [`TimeScale-class`] object.
Expand Down
12 changes: 0 additions & 12 deletions R/calendar-gregorian.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@
#' @include AllGenerics.R
NULL

# Gregorian calendar ===========================================================
#' @export
#' @rdname is
#' @aliases is_gregorian,ANY-method
setMethod(
f = "is_gregorian",
signature = "ANY",
definition = function(object) {
methods::is(object, "GregorianCalendar")
}
)

# Fixed from Gregorian =========================================================
#' @export
#' @rdname fixed
Expand Down
12 changes: 0 additions & 12 deletions R/calendar-julian.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@
#' @include AllGenerics.R
NULL

# Julian calendar ==============================================================
#' @export
#' @rdname is
#' @aliases is_julian,ANY-method
setMethod(
f = "is_julian",
signature = "ANY",
definition = function(object) {
methods::is(object, "JulianCalendar")
}
)

# Fixed from Julian ============================================================
#' @export
#' @rdname fixed
Expand Down
27 changes: 27 additions & 0 deletions R/calendar.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,33 @@ setMethod(
}
)

# Predicates ===================================================================
#' Is an Object a Calendar?
#'
#' Test inheritance relationships between an object and a calendar class.
#' @param object Any \R object.
#' @return
#' A [`logical`] scalar.
#' @author N. Frerebeau
#' @docType methods
#' @family calendar tools
#' @export
is_calendar <- function(object) {
methods::is(object, "TimeScale")
}

#' @export
#' @rdname is_calendar
is_gregorian <- function(object) {
methods::is(object, "GregorianCalendar")
}

#' @export
#' @rdname is_calendar
is_julian <- function(object) {
methods::is(object, "JulianCalendar")
}

# 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.

19 changes: 6 additions & 13 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 12ae310

Please sign in to comment.