CARMA C++
|
This class deals primarily with Frames and Times. More...
#include <carma/util/Time.h>
Public Types | |
enum | TimeZone { LOCAL = -1, GMT = 0, UTC = GMT, ADT = 3, AST = 4, EDT = AST, EST = 5, CDT = EST, CST = 6, MDT = CST, MST = 7, PDT = MST, PST = 8, AKDT = PST, AKST = 9, HADT = AKST, HAST = 10 } |
enumeration for defining timezones More... | |
Public Member Functions | |
double | getStoredMJD () const |
Return stored MJD. More... | |
Time () | |
Default constructor. More... | |
Time (double mjd) | |
Create a Time object with given mjd. More... | |
virtual | ~Time () |
Destructor. More... | |
Static Public Member Functions | |
static frameType | computeClosestFrame () |
Get integral half-second frame that is closest to current time. More... | |
static frameType | computeClosestFrame (double mjd) |
Get closest integral half-second frame since 2000 to requested time. More... | |
static frameType | computeClosestFrame (const std::string &date, const std::string &format="%Y %b %d %H:%M:%S", const TimeZone tz=LOCAL) |
Get the closest integral half-second frame since 2000 to the input date string. More... | |
static frameType | computeCurrentFrame () |
Get integral half-second frame since 2000, rounded down. More... | |
static frameType | computeFrame (double mjd) |
Get integral half-second frame since 2000 for requested time, rounded down. More... | |
static double | computeFrameTimeDiff (frameType frame, double delay=0) |
Get time difference of current time to the delayed frame. More... | |
static double | computeMJD (time_t seconds) |
Compute the MJD of the Unix-style seconds since 1970. More... | |
static double | computeMJD (const std::string &date, const std::string &format="%Y %b %d %H:%M:%S", const TimeZone tz=LOCAL) |
Get the MJD given the input date string. More... | |
static double | computeMJD1 (const std::string &date, const std::string &format="%Y %b %d %H:%M:%S", const TimeZone tz=LOCAL) |
static double | computeTimeToFrame (frameType frame, double delay=0) |
Get time from now to a specific frame with a delay after the frame. More... | |
static double | computeTimeToNextFrame (double delay=0) |
Get time to next frame (half-second) with a delay after the frame. More... | |
static int | diffHrsFromGmt (const struct tm myTime, const time_t secondsSince1970) |
Utility for obtaining GMT from a local time with faster performance. More... | |
static std::string | getDateString (const std::string &dateFormat="%d%b%y") |
Get date string for current time. More... | |
static std::string | getDateString (double mjd, const std::string &dateFormat="%d%b%y") |
Get date string for specified time. More... | |
static std::string | getDateString (frameType frame, const std::string &dateFormat="%d%b%y") |
Get date for given frame as a string. More... | |
static std::string | getDateString (int imjd, const std::string &dateFormat="%d%b%y") |
Get date for given MJD day as a string. More... | |
static std::string | getDateTimeString (int precision=0, const std::string &dateFormat="%d%b%y") |
Get date and time of day string for current time. More... | |
static std::string | getDateTimeString (frameType frame, int precision=0, const std::string &dateFormat="%d%b%y") |
Get date and time of day string for given frame. More... | |
static std::string | getDateTimeString (double mjd, int precision=0, const std::string &dateFormat="%d%b%y") |
Get date and time of day string for specified time. More... | |
static std::string | getFITSdateString () |
Get date string for current time in FITS notation. More... | |
static std::string | getFITSdateString (int imjd) |
Get date string for specified day. More... | |
static std::string | getFITSdateString (double mjd) |
Get date string for specified time. More... | |
static std::string | getFITSdateString (frameType frame) |
Get date for given frame as a string. More... | |
static std::string | getFITSdateTimeString (int precision=0) |
Get FITS style date and time of day string for current time. More... | |
static std::string | getFITSdateTimeString (double mjd, int precision=0) |
Get FITS style date and time of day string for specified time. More... | |
static std::string | getFITSdateTimeString (frameType frame, int precision=0) |
Get FITS style date and time of day string for given frame. More... | |
static struct tm | getGmtFromLmt (const std::string &date, const std::string &format, const Time::TimeZone tz) |
Utility for obtaining GMT from a local time Note:This is expensive. More... | |
::std::string | getNonBuggyByDesignDateTimeString (double mjd, const ::std::string &dateFormat) |
Get date and time of day string for current time. More... | |
static time_t | gettime_t (const frameType frame) |
Converts a frame number to a time_t in UTC. More... | |
static std::string | getTimeString (int precision=0) |
Get time of day string for current time. More... | |
static std::string | getTimeString (double mjd, int precision=0) |
Get time of day string for specified time. More... | |
static std::string | getTimeString (frameType frame, int precision=0) |
Get time of day for given frame as a string. More... | |
static double | MJD () |
Get current MJD. More... | |
static double | MJD (frameType frame) |
Get MJD for a given frame count. More... | |
static double | timespec2MJD (const struct timespec ts) |
Converts absolute time specified as a ::timespec to an MJD. More... | |
static double | timeval2MJD (const struct::timeval &abstimeval) |
Converts absolute time specified as a ::timeval to an MJD. More... | |
Static Public Attributes | |
static const double | FRAMES_PER_DAY |
The number of half-second frames per day. More... | |
static const double | JD2000 = 2451544.5 |
The JD (Julian Data) for 2000.0 as a convenience. More... | |
static const double | MICROSECONDS_PER_DAY |
The number of milliseconds per day. More... | |
static const double | MILLISECONDS_PER_DAY |
The number of microseconds per day. More... | |
static const double | MINUTES_PER_DAY |
The number of minutes per day. More... | |
static const double | MJD1970 = 40587.0 |
The MJD for 1970.0. More... | |
static const double | MJD2000 = 51544.0 |
The MJD for 2000.0. More... | |
static const double | SECONDS_PER_DAY = 86400.0 |
The number of seconds per day. More... | |
Related Functions | |
(Note that these are not member functions.) | |
std::ostream & | operator<< (::std::ostream &os, const carma::util::Time &time) |
Insert (i.e. output) a presentation of the current time from an instance of carma::util::Time into an output stream. More... | |
This class deals primarily with Frames and Times.
Half-second Frames are used for monitor and data collection and are aligned with absolute time. The time of a Frame refers to the start time of the data contained in the frame. Frames are counted as integers starting from 00:00:00 UTC, Jan 1, 2000. Times are expressed as doubles in units of days with a reference system of Modified Julian Daynumber (MJD), which is aligned with UTC. When any of the "get" methods are called without an explicit time or frame argument, the current time is gotten with the accuracy determined by the OS.
Note:
1) Frames are integers and our Time is a double. As with any integer/real conversion, care must be taken when converting. There are methods for converting with rounding and with truncation. The programmer must make an intelligent choice based on the circumstances of the conversion. 2) Frames, along with civil time, have a discontinuity at leap seconds. When these events occur (approx every year and half), the suggested action is to stop observing shortly before the leap second, have a celebratory drink to the God of Time, reset your clock if necessary, and then resume observing.
3) The string output of time is essential for debugging this class but can be used whenever the format is suitable. It does not include the century and is not Y2K compliant, a defect that is accepted in exchange for brevity. The FITS formatted time and date strings are Y2K compliant. The FITS format is also known as ISO 8601. Formatted time output is a broad topic and this class does not attempt to provide a general solution. If you develop a new format you are encouraged to incorporate it into this class.If a number of new formats are developed simultaneously, then a new class (FormattedTime?) might be useful. 4) The abbreviations "MJD" and "FITS" will be used in the code as a commonly accepted term in our field. 5) This class contains no state.
carma::util::Time::Time | ( | ) |
Default constructor.
carma::util::Time::Time | ( | double | mjd | ) |
Create a Time object with given mjd.
|
virtual |
Destructor.
|
static |
Get integral half-second frame that is closest to current time.
|
static |
Get closest integral half-second frame since 2000 to requested time.
mjd | requested date/time as Modified Julian Daynumber |
|
static |
Get the closest integral half-second frame since 2000 to the input date string.
The timezone is defaulted to be the local timezone
date | The date string specified in a format identifiable with a Unix date format string. |
format | The date string in a Unix format. Default is format used by syslog plus the year (Y b %2d H:M:S). |
tz | The time zone, defined by the enum Time::TimeZone, that "date" is in (not the time zone that you're currently in) |
date(1)
, strptime(3)
|
static |
Get integral half-second frame since 2000, rounded down.
BEWARE: this truncation will probably not give what is desired if the MJD is just a smidgen below the frame (which is the case if it originally came from a frame).
|
static |
Get integral half-second frame since 2000 for requested time, rounded down.
BEWARE: this truncation will probably not give what is desired if the MJD is just a smidgen below the frame (which is the case if it originally came from a frame).
mjd | requested date/time as Modified Julian Daynumber |
|
static |
Get time difference of current time to the delayed frame.
frame | number (number of half-seconds since J2000) |
delay | in seconds after next half-second frame; default=0 |
|
static |
Compute the MJD of the Unix-style seconds since 1970.
seconds | the seconds since January 1, 1970, as from ctime(). |
|
static |
Get the MJD given the input date string.
The timezone is assumed to be the local timezone.
date | The date string specified in a format identifiable with a Unix date format string. |
format | The date string in a Unix format. Default is format used by syslog plus the year (Y b %2d H:M:S). |
tz | The time zone, defined by the enum Time::TimeZone, that "date" is in (not the time zone that you're currently in) |
date(1)
, strptime(3)
|
static |
Get time from now to a specific frame with a delay after the frame.
frame | number (number of half-seconds since 2000) |
delay | in seconds after next half-second frame; default=0 |
|
static |
Get time to next frame (half-second) with a delay after the frame.
This uses the current time from the OS.
delay | in seconds after next half-second frame; default=0 |
|
static |
Utility for obtaining GMT from a local time with faster performance.
About a 3x speedup over getGmtFromLmt, which adds up in a loop over thousands calls (e.g. filling a FluxCatalog from FluxSource.cat)
myTime | tm struct giving time in local time zone. |
secondsSince1970 | - return from a call to mktime(&myTime) Note the call is not made from within this method for performance reasons as methods which call this method have to call mktime anyway. |
|
static |
Get date string for current time.
dateFormat | format that the date will be returned (see date(1) ) |
|
static |
Get date string for specified time.
mjd | specified time as a Modified Julian Daynumber |
dateFormat | format that the date will be returned (see date(1) ) |
|
static |
Get date for given frame as a string.
frame | number (number of half-seconds since J2000) |
dateFormat | format that the date will be returned (see date(1) ) |
|
static |
Get date for given MJD day as a string.
imjd | day number |
dateFormat | format that the date will be returned (see date(1) ) |
|
static |
Get date and time of day string for current time.
precision | digits to the right of the decimal for seconds |
dateFormat | format that the date will be returned (see date(1) ) |
|
static |
Get date and time of day string for given frame.
frame | number (number of half-seconds since J2000) |
precision | digits to the right of the decimal for seconds |
dateFormat | format that the date will be returned (see date(1) ) |
ErrorException | if precision < 0 or > 10 |
|
static |
Get date and time of day string for specified time.
mjd | specified time as a Modified Julian Daynumber |
precision | digits to the right of the decimal for seconds |
dateFormat | format that the date will be returned (see date(1) ) |
ErrorException | if precision < 0 or > 10 |
|
static |
Get date string for current time in FITS notation.
|
static |
Get date string for specified day.
imjd | specified time as an integer Modified Julian Daynumber |
|
static |
Get date string for specified time.
mjd | specified time as a Modified Julian Daynumber |
|
static |
Get date for given frame as a string.
frame | number (number of half-seconds since J2000) |
|
static |
Get FITS style date and time of day string for current time.
precision | digits to the right of the decimal for seconds |
|
static |
Get FITS style date and time of day string for specified time.
mjd | specified time as a Modified Julian Daynumber |
precision | digits to the right of the decimal for seconds |
ErrorException | if precision < 0 or > 10 |
|
static |
Get FITS style date and time of day string for given frame.
frame | number (number of half-seconds since J2000) |
precision | digits to the right of the decimal for seconds |
ErrorException | if precision < 0 or > 10 |
|
static |
Utility for obtaining GMT from a local time Note:This is expensive.
Use diffHrsFromGmt if performance is an issue.
|
static |
Get date and time of day string for current time.
dateFormat | format that the date will be returned (see date(1) ) |
double carma::util::Time::getStoredMJD | ( | ) | const |
Return stored MJD.
|
static |
Converts a frame number to a time_t in UTC.
|
static |
Get time of day string for current time.
precision | digits to the right of the decimal for seconds |
ErrorException | if precision < 0 or > 10 |
|
static |
Get time of day string for specified time.
mjd | specified time as a Modified Julian Daynumber |
precision | digits to the right of the decimal for seconds |
ErrorException | if precision < 0 or > 10 |
|
static |
Get time of day for given frame as a string.
frame | number (number of half-seconds since J2000) |
precision | digits to the right of the decimal for seconds |
ErrorException | if precision < 0 or > 10 |
|
static |
Get current MJD.
|
static |
Get MJD for a given frame count.
Note that is a real representation of a linear conversion of an integer. It will be very close, but subject to the limitations of real numbers.
frame | count to convert to MJD |
|
static |
Converts absolute time specified as a ::timespec to an MJD.
NOTE - timespec assumed to contain absolute time, not some difference.
ts | const struct timespec structure with abs time specified in seconds and nanoseconds from the Epoch |
|
static |
Converts absolute time specified as a ::timeval to an MJD.
tv | const struct timeval structure with abs time specified in seconds and nanoseconds from the Epoch. |
|
related |
Insert (i.e. output) a presentation of the current time from an instance of carma::util::Time into an output stream.
The precision with which the seconds field is presented is determined by the precision of the stream. Hence, usage like this:
would produce output that looks like this:
os | The output stream to insert the presentation into. |
time | The carma::util::Time instance to get the current time from. |
os
output stream parameter so that stream insertions can be chained in the usual C++ way (as shown in the example).
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |