SuperNOVAS C++ API v1.6
High-precision C/C++ astrometry library
Loading...
Searching...
No Matches
supernovas::Calendar Class Reference

Type of calendar used for representing dates, such as Gregorian, Roman, or astronomical. More...

#include <supernovas.h>

Inheritance diagram for supernovas::Calendar:

Public Member Functions

CalendarDate date (const struct timespec *ts) const
 Returns a new calendar date instance, in this calendar, for the given astronomical time specification.
CalendarDate date (double jd) const
 Returns a new calendar date instance, in this calendar, for the specified Julian date.
CalendarDate date (int year, int month, int day, const TimeAngle &time=TimeAngle::zero()) const
 Returns a new calendar date instance for the date and time specified in this calendar.
CalendarDate date (time_t t, long nanos=0) const
 Returns a new calendar date instance, in this calendar, for the specified UNIX time.
CalendarDate parse_date (const std::string &str, enum novas_date_format fmt=NOVAS_YMD) const
 Returns a new calendar date instance, in this calendar, for the specified string date / time representation, if possible, or else std::nullopt.
std::string to_string () const
 Returns a string representation of this type of calendar.
enum novas_calendar_type type () const
 Returns the type of this calendar, that is whether it is a Gregorian, Roman / Julian, or astronomical calendar.
Public Member Functions inherited from supernovas::Validating
bool is_valid () const
 Returns the previously set 'valid' stae of the implementing instance.
 operator bool () const
 Objects that implement Validating can be used in conditionals directly, without explicitly calling is_valid().

Static Public Member Functions

static Calendar astronomical ()
 Returns a new astronomical calendar instance.
static Calendar gregorian ()
 Returns a new Gregorian calendar instance.
static Calendar roman ()
 Returns a new Roman / Julian calendar instance.

Additional Inherited Members

Protected Member Functions inherited from supernovas::Validating
 Validating ()
 dummy constructor;
Protected Attributes inherited from supernovas::Validating
bool _valid = false
 the state variable.

Detailed Description

Type of calendar used for representing dates, such as Gregorian, Roman, or astronomical.

Member Function Documentation

◆ astronomical()

Calendar supernovas::Calendar::astronomical ( )
static

Returns a new astronomical calendar instance.

The astronomical calendat is the conventional calendar of date, that is the Roman / Julian calendar prior to the Gregorian calendar reform of 1582; and the Gregorian calendar after the date of the reform.

Returns
an astronomical calendar / conventional calendar of date instance.
See also
Calendar::roman()
Calendar::gregorian()

References NOVAS_ASTRONOMICAL_CALENDAR.

Referenced by supernovas::Time::operator-(), and supernovas::Time::to_calendar_date().

◆ date() [1/4]

CalendarDate supernovas::Calendar::date ( const struct timespec * ts) const

Returns a new calendar date instance, in this calendar, for the given astronomical time specification.

Parameters
tsPointer to the astronomical time specification
Returns
a new calendar date, in this calendar, corresponding to the specified astronomical time.
See also
date(), parse_date()

References date().

◆ date() [2/4]

CalendarDate supernovas::Calendar::date ( double jd) const

Returns a new calendar date instance, in this calendar, for the specified Julian date.

Parameters
jd[day] Julian Day
Returns
a new calendar date, in this calendar, corresponding to the specified Julian date.
See also
CalendarDate::CalendarDate(), date(), parse_date()

References supernovas::Validating::is_valid().

◆ date() [3/4]

CalendarDate supernovas::Calendar::date ( int year,
int month,
int day,
const TimeAngle & time = TimeAngle::zero() ) const

Returns a new calendar date instance for the date and time specified in this calendar.

Parameters
year[yr] calendar year
month[month] calendar month [1:12]
day[day] calendar day-of-month [1:31]
Time of observation and astronomical timescalestime of day
Returns
a date instance for the specified date in this calendar.
See also
CalendarDate::CalendarDate(), date(), parse_date()

References supernovas::Validating::is_valid().

Referenced by date(), parse_date(), and supernovas::Time::to_calendar_date().

◆ date() [4/4]

CalendarDate supernovas::Calendar::date ( time_t t,
long nanos = 0 ) const

Returns a new calendar date instance, in this calendar, for the specified UNIX time.

Parameters
t[s] UNIX time (seconds since the Gregorian date of January 1, 1970).
nanos[ns] sub-second time component
Returns
a new calendar date, in this calendar, corresponding to the specified UNIX time.
See also
date(), date(double)

References supernovas::Unit::day, NOVAS_JD_J2000, supernovas::Unit::ns, and UNIX_UTC_J2000.

◆ gregorian()

Calendar supernovas::Calendar::gregorian ( )
static

Returns a new Gregorian calendar instance.

Returns
a Gregorian calendar instance
See also
roman(), astronomical()

References NOVAS_GREGORIAN_CALENDAR.

◆ parse_date()

CalendarDate supernovas::Calendar::parse_date ( const std::string & str,
enum novas_date_format fmt = NOVAS_YMD ) const

Returns a new calendar date instance, in this calendar, for the specified string date / time representation, if possible, or else std::nullopt.

Parameters
strThe string date / time specification. There is a lot of flexibility on what dates/times may be parsed. See novas_parse_date_format() for details.
fmtThe date representation, such as NOVAS_YMD, NOVAS_DMY, or NOVAS_MDY, specifying the order in which the year (Y), month (M), and day (D) components are expected in the input string representation.
Returns
A new calendar date, in this calendar, or else CalendarDate::undefined() if the string date could not be parsed.
See also
CalendarDate::to_string(), date()
novas_parse_date(), novas_parse_ido_date(), novas_parse_date_format() for more managed parsing from strings.

References date(), novas_parse_date_format(), and supernovas::CalendarDate::undefined().

◆ roman()

Calendar supernovas::Calendar::roman ( )
static

Returns a new Roman / Julian calendar instance.

Returns
a Roman / Julian calendar instance
See also
gregorian(), astronomical()

References NOVAS_ROMAN_CALENDAR.

◆ to_string()

std::string supernovas::Calendar::to_string ( ) const

Returns a string representation of this type of calendar.

Returns
A string representation of the calendar, such as "Gregorian calendar".

References NOVAS_GREGORIAN_CALENDAR, and NOVAS_ROMAN_CALENDAR.

◆ type()

enum novas_calendar_type supernovas::Calendar::type ( ) const

Returns the type of this calendar, that is whether it is a Gregorian, Roman / Julian, or astronomical calendar.

The astronomical calendat is the conventional calendar of date.

Returns
The type of calendar, e.g. NOVAS_GREGORIAN_CALENDAR, NOVAS_ROMAN_CALENDAR, or NOVAS_ASTRONOMICAL calendar.