CARMA C++
Time.h
Go to the documentation of this file.
1 // -*- c++ -*-
18 #ifndef CARMA_UTIL_TIME_H
19 #define CARMA_UTIL_TIME_H
20 
21 #include <iosfwd>
22 #include <string>
23 #include <ctime>
24 #include "carma/util/types.h"
25 
26 struct timeval;
27 
28 namespace carma {
32  namespace util {
33 
74  class Time
75  {
76  public:
80  typedef enum {
81  LOCAL = -1,
82  GMT = 0,
83  UTC = GMT,
84  ADT = 3,
85  AST = 4,
86  EDT = AST,
87  EST = 5,
88  CDT = EST,
89  CST = 6,
90  MDT = CST,
91  MST = 7,
92  PDT = MST,
93  PST = 8,
94  AKDT = PST,
95  AKST = 9,
96  HADT = AKST,
97  HAST = 10
98  } TimeZone;
99 
103  Time();
104 
108  Time(double mjd);
109 
113  virtual ~Time();
114 
118  double getStoredMJD() const;
119 
124  static double MJD() ;
125 
134  static double MJD(frameType frame) ;
135 
141  static frameType computeClosestFrame() ;
142 
148  static frameType computeClosestFrame(double mjd) ;
149 
165  const std::string& date,
166  const std::string& format="%Y %b %d %H:%M:%S",
167  const TimeZone tz=LOCAL
168  );
169 
177  static frameType computeCurrentFrame() ;
178 
189  static frameType computeFrame(double mjd) ;
190 
197  static double computeTimeToNextFrame(double delay=0) ;
198 
205  static double computeTimeToFrame(frameType frame, double delay=0) ;
206 
213  static double computeFrameTimeDiff(frameType frame, double delay=0) ;
214 
220  static double computeMJD (time_t seconds) ;
221 
235  static double computeMJD(
236  const std::string& date,
237  const std::string& format="%Y %b %d %H:%M:%S",
238  const TimeZone tz=LOCAL
239  );
240 
241  // older version
242  static double computeMJD1(
243  const std::string& date,
244  const std::string& format="%Y %b %d %H:%M:%S",
245  const TimeZone tz=LOCAL
246  );
247 
256  static double timespec2MJD (const struct timespec ts);
257 
264  static double timeval2MJD (const struct ::timeval & abstimeval);
265 
269  static time_t gettime_t(const frameType frame);
270 
279  static std::string getTimeString(int precision=0) ;
280 
290  static std::string getTimeString(double mjd, int precision=0) ;
291 
301  static std::string getTimeString(frameType frame, int precision=0) ;
302 
308  static std::string getDateString(
309  const std::string &dateFormat = "%d%b%y") ;
310 
317  static std::string getDateString(double mjd,
318  const std::string &dateFormat = "%d%b%y") ;
319 
326  static std::string getDateString(frameType frame,
327  const std::string &dateFormat = "%d%b%y") ;
328 
335  static std::string getDateString(int imjd,
336  const std::string &dateFormat = "%d%b%y") ;
337 
343  static std::string getFITSdateString() ;
344 
350  static std::string getFITSdateString(int imjd) ;
351 
357  static std::string getFITSdateString(double mjd) ;
358 
364  static std::string getFITSdateString(frameType frame) ;
365 
372  static ::std::string getNonBuggyByDesignDateTimeString(
373  double mjd, const ::std::string &dateFormat );
374 
383  static std::string getDateTimeString(int precision=0,
384  const std::string &dateFormat = "%d%b%y") ;
385 
396  static std::string getDateTimeString(frameType frame,
397  int precision=0,
398  const std::string &dateFormat = "%d%b%y") ;
399 
410  static std::string getDateTimeString(double mjd,
411  int precision=0,
412  const std::string &dateFormat = "%d%b%y") ;
413 
414 
422  static std::string getFITSdateTimeString(int precision=0);
423 
433  static std::string getFITSdateTimeString(double mjd, int precision=0) ;
434 
444  static std::string getFITSdateTimeString(frameType frame,
445  int precision=0) ;
446 
452  static struct tm getGmtFromLmt(const std::string &date,
453  const std::string &format,
454  const Time::TimeZone tz);
455 
468  static int diffHrsFromGmt(const struct tm myTime,
469  const time_t secondsSince1970);
470 
471 
472 
476  static const double MJD1970 = 40587.0;
477 
481  static const double MJD2000 = 51544.0;
482 
487  static const double JD2000 = 2451544.5;
488 
492  static const double SECONDS_PER_DAY = 86400.0;
493 
497  static const double MINUTES_PER_DAY;
498 
502  // value is initialized with the storage declaration in the .cc file
503  static const double MILLISECONDS_PER_DAY;
504 
508  // value is initialized with the storage declaration in the .cc file
509  static const double MICROSECONDS_PER_DAY;
510 
514  // value is initialized with the storage declaration in the .cc file
515  static const double FRAMES_PER_DAY;
516 
517  private:
521  static double get2kd() ;
522  static int computeIntegerMJD(double mjd, int precision=0) ;
523  static double roundMJD(double mjd, int precision=0) ;
524  double mjd_;
525  };
526 
527  } } // End namespace carma::util
528 
529 
554 ::std::ostream& operator<<( ::std::ostream& os,
555  const carma::util::Time& time );
556 
557 
558 #endif // CARMA_UTIL_TIME_H
559 
560 
561 
562 
563 
564 
565 
566 
567 
568 
569 
570 
571 
572 
573 
574 
static int diffHrsFromGmt(const struct tm myTime, const time_t secondsSince1970)
Utility for obtaining GMT from a local time with faster performance.
static const double JD2000
The JD (Julian Data) for 2000.0 as a convenience.
Definition: Time.h:487
virtual ~Time()
Destructor.
static std::string getFITSdateTimeString(int precision=0)
Get FITS style date and time of day string for current time.
TimeZone
enumeration for defining timezones
Definition: Time.h:80
static frameType computeFrame(double mjd)
Get integral half-second frame since 2000 for requested time, rounded down.
static const double MILLISECONDS_PER_DAY
The number of microseconds per day.
Definition: Time.h:503
unsigned int frameType
Half second frames since Jan 1, 2000.
Definition: types.h:29
static double computeTimeToNextFrame(double delay=0)
Get time to next frame (half-second) with a delay after the frame.
static std::string getDateString(const std::string &dateFormat="%d%b%y")
Get date string for current time.
static double timespec2MJD(const struct timespec ts)
Converts absolute time specified as a ::timespec to an MJD.
static const double FRAMES_PER_DAY
The number of half-second frames per day.
Definition: Time.h:515
static time_t gettime_t(const frameType frame)
Converts a frame number to a time_t in UTC.
static const double MJD2000
The MJD for 2000.0.
Definition: Time.h:481
static frameType computeCurrentFrame()
Get integral half-second frame since 2000, rounded down.
static std::string getDateTimeString(int precision=0, const std::string &dateFormat="%d%b%y")
Get date and time of day string for current time.
static const double MJD1970
The MJD for 1970.0.
Definition: Time.h:476
static std::string getTimeString(int precision=0)
Get time of day string for current time.
static const double MINUTES_PER_DAY
The number of minutes per day.
Definition: Time.h:497
This class deals primarily with Frames and Times.
Definition: Time.h:74
Time()
Default constructor.
static frameType computeClosestFrame()
Get integral half-second frame that is closest to current time.
static double computeFrameTimeDiff(frameType frame, double delay=0)
Get time difference of current time to the delayed frame.
::std::string getNonBuggyByDesignDateTimeString(double mjd, const ::std::string &dateFormat)
Get date and time of day string for current time.
static const double SECONDS_PER_DAY
The number of seconds per day.
Definition: Time.h:492
static const double MICROSECONDS_PER_DAY
The number of milliseconds per day.
Definition: Time.h:509
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.
double getStoredMJD() const
Return stored MJD.
static double computeTimeToFrame(frameType frame, double delay=0)
Get time from now to a specific frame with a delay after the frame.
static double MJD()
Get current MJD.
Various type definitions for util classes.
static double timeval2MJD(const struct::timeval &abstimeval)
Converts absolute time specified as a ::timeval to an MJD.
static double computeMJD(time_t seconds)
Compute the MJD of the Unix-style seconds since 1970.
static std::string getFITSdateString()
Get date string for current time in FITS notation.