ReFRACtor
fp_time.h
Go to the documentation of this file.
1 #ifndef FP_TIME_H
2 #define FP_TIME_H
3 #include "printable.h"
4 #include <boost/operators.hpp>
5 #include <boost/date_time/posix_time/posix_time.hpp>
6 
7 namespace FullPhysics {
8 /****************************************************************/
29 class Time : public Printable<Time>,
30  private boost::less_than_comparable<Time>,
31  private boost::equality_comparable<Time>,
32  private boost::addable<Time, double>,
33  private boost::subtractable<Time, double> {
34 public:
35 
36 //-----------------------------------------------------------------------
38 //-----------------------------------------------------------------------
39 
40  Time() { unix_time_ = 0; }
41 
42  Time(const boost::posix_time::ptime& t);
43  operator boost::posix_time::ptime() const;
44 
45 //-----------------------------------------------------------------------
47 //-----------------------------------------------------------------------
48 
49  static Time time_unix(double unix_time)
50  {Time res; res.unix_time_ = unix_time; return res;}
51 
52 //-----------------------------------------------------------------------
54 //-----------------------------------------------------------------------
55 
56  static Time time_pgs(double pgs)
57  {Time res; res.unix_time_ = pgs + 725846400.0; return res;}
58 
59 //-----------------------------------------------------------------------
61 //-----------------------------------------------------------------------
62 
63  static Time time_iet(double iet)
64  {Time res; res.unix_time_ = iet - 378691200.0; return res;}
65 
66 //-----------------------------------------------------------------------
68 //-----------------------------------------------------------------------
69 
70  Time& operator+=(double T) {unix_time_ += T; return *this;}
71 
72 //-----------------------------------------------------------------------
74 //-----------------------------------------------------------------------
75 
76  Time& operator-=(double T) {unix_time_ -= T; return *this;}
77 
78 //-----------------------------------------------------------------------
80 //-----------------------------------------------------------------------
81 
82  double unix_time() const { return unix_time_;}
83 
84 //-----------------------------------------------------------------------
86 //-----------------------------------------------------------------------
87 
88  double pgs_time() const { return unix_time_ - 725846400.0;}
89 
90 //-----------------------------------------------------------------------
92 //-----------------------------------------------------------------------
93 
94  double iet_time() const { return unix_time_ + 378691200.0;}
95 
96  double frac_day_of_year() const;
97  double frac_year() const;
98 
99  static Time parse_time(const std::string& Time_string);
100  std::string to_string() const;
101 
102 //-----------------------------------------------------------------------
104 //-----------------------------------------------------------------------
105 
106  void print(std::ostream& os) const { os << to_string(); }
107 
108 private:
109  double unix_time_;
110 };
111 
112 //-----------------------------------------------------------------------
116 //-----------------------------------------------------------------------
117 
118 inline double operator-(const Time& T1, const Time& T2)
119 { return T1.unix_time() - T2.unix_time(); }
120 
121 //-----------------------------------------------------------------------
126 //-----------------------------------------------------------------------
127 
128 inline bool operator<(const Time& T1, const Time& T2)
129 { return T1.unix_time() < T2.unix_time(); }
130 
132 //-----------------------------------------------------------------------
133 
134 inline bool operator==(const Time& T1, const Time& T2)
135 { return T1.unix_time() == T2.unix_time(); }
136 
137 }
138 #endif
Time()
Default constructor.
Definition: fp_time.h:40
static Time parse_time(const std::string &Time_string)
Parse CCSDS format time (e.g., "1996-07-03T04:13:57.987654Z")
Definition: fp_time.cc:64
static Time time_iet(double iet)
Return time from given IDPS Epoch Time (IET) (epoch of 1958-01-01).
Definition: fp_time.h:63
double pgs_time() const
Give time in PGS toolkit time, as a double (epoch 1993-01-01)
Definition: fp_time.h:88
double frac_year() const
Calculate the fractional year.
Definition: fp_time.cc:49
double iet_time() const
Give time in IDPS Epoch Time (IET) time, as double (epoch 1958-01-01)
Definition: fp_time.h:94
double operator-(const Time &T1, const Time &T2)
Subtract two Times, giving the interval between them in seconds.
Definition: fp_time.h:118
This is a Mixin for classes that can be printed.
Definition: printable.h:24
Time & operator+=(double T)
Add given number of seconds to Time.
Definition: fp_time.h:70
std::string to_string() const
Convert to CCSDS format.
Definition: fp_time.cc:82
double frac_day_of_year() const
Calculate the fractional day of the year.
Definition: fp_time.cc:37
void print(std::ostream &os) const
Print to stream.
Definition: fp_time.h:106
This is a simple time class.
Definition: fp_time.h:29
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
bool operator<(const FullPhysics::DoubleWithUnit &A, const FullPhysics::DoubleWithUnit &B)
static Time time_pgs(double pgs)
Return time from given PGS toolkit time (epoch of 1993-01-01).
Definition: fp_time.h:56
Time & operator-=(double T)
Subtract given number of seconds to Time.
Definition: fp_time.h:76
static Time time_unix(double unix_time)
Return time from given Unix time (epoch of 1970-01-01).
Definition: fp_time.h:49
bool operator==(const FullPhysics::DoubleWithUnit &A, const FullPhysics::DoubleWithUnit &B)
We define != in terms of this operator.
double unix_time() const
Give time in unix time, as a double (epoch 1970-01-01)
Definition: fp_time.h:82

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:11