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

A signed time interval between two instants of time, in the astronomical timescale of choice. More...

#include <supernovas.h>

Inheritance diagram for supernovas::Interval:

Public Member Functions

 Interval (double seconds, enum novas_timescale timescale=NOVAS_TT)
 Instantiates a new time interval with the specified time in seconds and a timescale (TT by default).
double days () const
 Returns this time interval in days.
bool equals (const Interval &interval, double precision=Unit::us) const
 Checks if this time interval is equal to the specified other time interval within the specified precision.
double hours () const
 Returns this time interval in hours.
Interval inv () const
 Returns the inverse of this time interval ie, its negated value.
double julian_centuries () const
 Returns this time interval in Julian centuries.
double julian_years () const
 Returns this time interval in Julian years.
double milliseconds () const
 Returns this time interval in milliseconds.
double minutes () const
 Returns this time interval in minutes.
bool operator!= (const Interval &interval) const
 Checks if this time interval differs from the specified other time interval at the full double-precision.
Coordinate operator* (const ScalarVelocity &v) const
 Returns the distance travelled in this time interval at the specified speed.
Position operator* (const Velocity &v) const
 Returns the spatial vector travelled in this time interval at the specified velocity.
Interval operator+ (const Interval &r) const
 Returns a new time interval that is the sum of this time interval and the specified other time interval.
Interval operator- (const Interval &r) const
 Returns a new time interval that is the signed difference of this time interval and the specified other time interval.
bool operator== (const Interval &interval) const
 Checks if this time interval is equal to the specified other time interval at the full double-precision.
double seconds () const
 Returns this time interval in seconds.
enum novas_timescale timescale () const
 Returns the time scale in which this time interval was defined.
std::string to_string (int decimals=3) const
 Returns a string representation of this interval using the specified number of significant figures and a best matched time unit.
Interval to_timescale (enum novas_timescale scale) const
 Returns a new time interval, which matches this time interval in the specified other timescale.
double weeks () const
 Returns this time interval in weeks.
double years () const
 Returns this time interval in calendar years.
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 const Intervalzero ()
 Returns a reference to the zero time interval.

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

A signed time interval between two instants of time, in the astronomical timescale of choice.

See also
Time, TimeAngle

Constructor & Destructor Documentation

◆ Interval()

supernovas::Interval::Interval ( double seconds,
enum novas_timescale timescale = NOVAS_TT )
explicit

Instantiates a new time interval with the specified time in seconds and a timescale (TT by default).

Parameters
seconds[s] time span in seconds.
timescale(optional) timescale in which the interval was defined (default: novas:NOVAS_TT)
See also
zero()

References supernovas::Validating::_valid, NOVAS_TIMESCALES, seconds(), and timescale().

Referenced by equals(), inv(), operator!=(), operator+(), operator-(), operator==(), to_timescale(), and zero().

Member Function Documentation

◆ days()

double supernovas::Interval::days ( ) const

Returns this time interval in days.

Returns
[day] the time interval
See also
milliseconds(), seconds(), minutes(), hours(), weeks(), years(), julian_years(), julian_centuries()

References supernovas::Unit::day.

Referenced by supernovas::CalendarDate::operator+(), supernovas::CalendarDate::operator-(), and to_string().

◆ equals()

bool supernovas::Interval::equals ( const Interval & interval,
double precision = Unit::us ) const

Checks if this time interval is equal to the specified other time interval within the specified precision.

The comparison is performed in Terrestrial Time (TT).

Parameters
intervalthe reference time interval.
precision[s] the precision used for checking equality.
Returns
true if this time interval is equal to the reference time interval within the specified precision, or else false.
See also
operator==(), operator!=()

References Interval().

Referenced by operator!=(), and operator==().

◆ hours()

double supernovas::Interval::hours ( ) const

Returns this time interval in hours.

Returns
[h] the time interval
See also
milliseconds(), seconds(), minutes(), days(), weeks(), years(), julian_years(), julian_centuries()

References supernovas::Unit::hour.

Referenced by supernovas::TimeAngle::operator+(), supernovas::TimeAngle::operator-(), and to_string().

◆ inv()

Interval supernovas::Interval::inv ( ) const

Returns the inverse of this time interval ie, its negated value.

Returns
a new time interval with the same absolute value, but negated.

References Interval().

◆ julian_centuries()

double supernovas::Interval::julian_centuries ( ) const

Returns this time interval in Julian centuries.

Returns
[cy] the time interval
See also
milliseconds(), seconds(), minutes(), hours(), days(), weeks(), years(), julian_years()

References supernovas::Unit::julian_century.

◆ julian_years()

double supernovas::Interval::julian_years ( ) const

Returns this time interval in Julian years.

Returns
[yr] the time interval
See also
milliseconds(), seconds(), minutes(), hours(), days(), weeks(), years(), julian_centuries()

References supernovas::Unit::julian_year.

◆ milliseconds()

double supernovas::Interval::milliseconds ( ) const

Returns this time interval in milliseconds.

Returns
[ms] the time interval
See also
seconds(), minutes(), hours(), days(), weeks(), years(), julian_years(), julian_centuries()

References supernovas::Unit::ms.

Referenced by to_string().

◆ minutes()

double supernovas::Interval::minutes ( ) const

Returns this time interval in minutes.

Returns
[min] the time interval
See also
milliseconds(), seconds(), hours(), days(), weeks(), years(), julian_years(), julian_centuries()

References supernovas::Unit::min.

◆ operator!=()

bool supernovas::Interval::operator!= ( const Interval & interval) const

Checks if this time interval differs from the specified other time interval at the full double-precision.

The comparison is performed in Terrestrial Time (TT).

Parameters
intervalthe reference time interval.
Returns
true if this time interval differs from the reference time interval, or else false.
See also
equals(), operator==()

References Interval(), and equals().

◆ operator*() [1/2]

Coordinate supernovas::Interval::operator* ( const ScalarVelocity & v) const

Returns the distance travelled in this time interval at the specified speed.

Parameters
vspeed value
Returns
the distance travelled under this time interval at the specified speed.

References supernovas::Validating::is_valid(), and supernovas::ScalarVelocity::travel().

◆ operator*() [2/2]

Position supernovas::Interval::operator* ( const Velocity & v) const

Returns the spatial vector travelled in this time interval at the specified velocity.

Parameters
vspeed value
Returns
the statial vector travelled under this interval at the specified velocity.

References supernovas::Validating::is_valid(), and supernovas::Velocity::travel().

◆ operator+()

Interval supernovas::Interval::operator+ ( const Interval & r) const

Returns a new time interval that is the sum of this time interval and the specified other time interval.

Parameters
rthe other time interval
Returns
the sum of this time interval and the argument time interval.
See also
operator-()

References Interval().

◆ operator-()

Interval supernovas::Interval::operator- ( const Interval & r) const

Returns a new time interval that is the signed difference of this time interval and the specified other time interval.

Parameters
rthe other time interval
Returns
the signed difference of this time interval and the argument time interval.
See also
operator+()

References Interval().

◆ operator==()

bool supernovas::Interval::operator== ( const Interval & interval) const

Checks if this time interval is equal to the specified other time interval at the full double-precision.

The comparison is performed in Terrestrial Time (TT).

Parameters
intervalthe reference time interval.
Returns
true if this time interval is equal to the reference time interval, or else false.
See also
equals(), operator!=()

References Interval(), and equals().

◆ seconds()

◆ timescale()

enum novas_timescale supernovas::Interval::timescale ( ) const

Returns the time scale in which this time interval was defined.

Returns
the time scale for this interval.

Referenced by Interval().

◆ to_string()

std::string supernovas::Interval::to_string ( int decimals = 3) const

Returns a string representation of this interval using the specified number of significant figures and a best matched time unit.

Returns
A human readable string representation of the distance and a unit specifier.

References supernovas::Unit::day, days(), supernovas::Unit::hour, hours(), milliseconds(), supernovas::Unit::s, years(), and supernovas::Unit::yr.

Referenced by supernovas::Orbital::to_string().

◆ to_timescale()

Interval supernovas::Interval::to_timescale ( enum novas_timescale scale) const

Returns a new time interval, which matches this time interval in the specified other timescale.

Parameters
scalethe timescale of the returned equivalent interval.
Returns
the equivalent time interval in the specified timescale

References Interval().

◆ weeks()

double supernovas::Interval::weeks ( ) const

Returns this time interval in weeks.

Returns
[wk] the time interval
See also
milliseconds(), seconds(), minutes(), hours(), days(), years(), julian_years(), julian_centuries()

References supernovas::Unit::week.

◆ years()

double supernovas::Interval::years ( ) const

Returns this time interval in calendar years.

Returns
[yr] the time interval
See also
milliseconds(), seconds(), minutes(), hours(), days(), weeks(), julian_years(), julian_centuries()

References supernovas::Unit::yr.

Referenced by to_string().

◆ zero()

const Interval & supernovas::Interval::zero ( )
static

Returns a reference to the zero time interval.

Returns
a reference to a statically defined zero time interval.

References Interval().