jul is used to create jul (julian date)
objects, which are useful for date calculations. as.jul and is.jul coerce an object to a julian date and
test whether an object is a jul.
jul(x, ...)
## S3 method for class 'Date':
jul(x, ...)
## S3 method for class 'ti':
jul(x, offset = 1, ...)
## S3 method for class 'default':
jul(x, ...)
as.jul(x)
is.jul(x)is.jul) or converted into a jul
object. As described in the details below, the constructor function
jul can deal with several different kinds of x.jul.default may pass these args to as.Date.jul.ti, a number in the range [0,1] telling where in the
period represented by x to find the day. 0 returns the first
day of the period, while the default value 1 returns the last day of
the period. For example, if is.jul returns TRUE or FALSE.
as.jul coerces its argument to have class jul, without
making any attempt to discern whether or not this is a sensible thing
to do.
jul constructs a jul object like x.
jul with no arguments returns the jul for the current day.jul's for any pair of valid dates differ by the number of
days between them. R's Date class defines a Date as a number
of days elapsed since January 1, 1970, but jul uses the
encoding from the Numerical Recipes book, which has Jan 1, 1970
= 2440588, and the code for converting between ymd and jul
representations is a straightforward port of the code from that tome.
This also matches the MRA Splus and csh (shell script) julian date
routines. Adding an integer to, or subtracting an integer from a jul
results in another jul, and one jul can be subtracted
from another. Two jul's can also be compared with the
operators (==, !=, <.>, <=,>==,>).
The jul class implements methods for a number of generic
functions, including "[", as.Date, as.POSIXct,
as.POSIXlt, c, format, max,
min, print, rep, seq, ti,
time, ymd.
jul is a generic function with specialized methods to handle
Date and ti objects.
The default method (jul.default) deals with character x by
calling as.Date on it. Otherwise, it proceeds as follows:
If x is numeric, isYmd is used to see if it could be
yyyymmdd date, then isTime is called to see if x could
be a decimal time (a number between 1799 and 2200). If all else fails,
as.Date(x) is called to attempt to create a Date object
that can then be used to construct a jul.
jul, ymd, ti, as.Datedec31 <- jul(20041231)
jan30 <- jul("2005-1-30")
jan30 - dec31 ## 30
feb28 <- jan30 + 29
jul() ## current dateRun the code above in your browser using DataLab