OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
TimePoint.hpp
Go to the documentation of this file.
1 #ifndef FOCS_TIMEPOINT
2 #define FOCS_TIMEPOINT
3 
4 #include <cmath>
5 #include <string>
6 
8 
9 #include <boost/date_time/gregorian_calendar.hpp>
10 #include <boost/date_time/posix_time/posix_time.hpp>
11 
12 namespace focs {
29  class TimePoint {
30  public:
35  enum class ClockType {
36  local,
37  utc,
38  tai,
39  tai93,
40  gps,
41  tt
42  };
43 
47  explicit TimePoint() : ptime_{boost::posix_time::microsec_clock::universal_time()} {};
48 
66  TimePoint(const double seconds_since_epoch, const TimePoint::ClockType clock_type=ClockType::utc);
67 
74  TimePoint(const boost::gregorian::date& date, const boost::posix_time::time_duration& time) : ptime_{date, time} {}
75 
83  TimePoint(const boost::gregorian::date date, const boost::posix_time::time_duration& time, const int milli) : ptime_{date, time + boost::posix_time::milliseconds{milli}} {}
84 
90  explicit TimePoint(const boost::posix_time::ptime& ptime) : ptime_{ptime} {}
91 
97  explicit TimePoint(const std::string& datetime);
98 
99  // TimePoint(const TimePoint& other){ptime_ = other.ptime_; clock_type_ = other.clock_type_;}
100 
112  const std::string to_string(const std::string &format="%Y-%m-%dT%H:%M:%S%F") const;
113 
122  const boost::posix_time::ptime& native() const {return ptime_;} // shouldn't be relied on, but I won't wrap everything
123 
132  inline friend std::ostream& operator<<(std::ostream &out, const TimePoint& t){return out << t.to_string();}
133 
141  // boost::posix_time::time_duration duration_since(const boost::posix_time::ptime& time) const;
142 
143  // /*! \brief Return duration since 1970-01-01 00:00:00.
144  // \return duration since 1970-01-01 00:00:00. */
145  // boost::posix_time::time_duration duration_since_1970() const {return duration_since(boost::posix_time::ptime{{1970,1,1}});}
146  // /*! \brief Return seconds since 1970-01-01 00:00:00.
147  // \return seconds since 1970-01-01 00:00:00. */
148  // double seconds_since_1970() const {return (double)duration_since_1970().total_microseconds() / 1'000'000.0;}
149  // /*! \brief Return duration since 1993-01-01 00:00:00.
150  // \return duration since 1993-01-01 00:00:00. */
151  // boost::posix_time::time_duration duration_since_1993() const {return duration_since(boost::posix_time::ptime{{1993,1,1}});}
152  // /*! \brief Return seconds since 1993-01-01 00:00:00.
153  // \return seconds since 1993-01-01 00:00:00. */
154  // double seconds_since_1993() const {return (double)duration_since_1993().total_microseconds() / 1'000'000.0;}
155  // /*! \brief Return duration since 1958-01-01 00:00:00.
156  // \return duration since 1958-01-01 00:00:00. */
157  // boost::posix_time::time_duration duration_since_1958() const {return duration_since(boost::posix_time::ptime{{1958,1,1}});}
158  // /*! \brief Return seconds since 1958-01-01 00:00:00.
159  // \return seconds since 1958-01-01 00:00:00. */
160  // double seconds_since_1958() const {return (double)duration_since_1958().total_microseconds() / 1'000'000.0;}
161 
177  double seconds_since(const TimePoint::ClockType clock_type) const;
178 
181  double utc() const { return seconds_since(ClockType::utc); }
182 
185  double tai() const { return seconds_since(ClockType::tai); }
186 
189  double tai93() const { return seconds_since(ClockType::tai93); }
190 
193  double gps() const { return seconds_since(ClockType::gps); }
194 
197  double tt() const { return seconds_since(ClockType::tt); }
198 
199 
200  // Developer note for the following Julian functions: This is
201  // re-implementing ptime's julian_date(), which returns a long,
202  // losing fractional seconds.
203 
206  double julian_date() const {return (utc() / 86400.0) + 2440587.5;}
209  double modified_julian_date() const {return julian_date() - 2400000.5;}
212  double reduced_julian_date() const {return julian_date() - 2400000.0;}
215  double truncated_julian_date() const {return std::floor(julian_date() - 2440000.5);}
216 
225  friend inline bool operator==(const TimePoint& lhs, const TimePoint& rhs){
226  return lhs.ptime_ == rhs.ptime_;
227  }
236  friend inline bool operator!=(const TimePoint& lhs, const TimePoint& rhs){ return !(lhs == rhs); }
237 
246  friend inline bool operator<(const TimePoint& lhs, const TimePoint& rhs){
247  return lhs.ptime_ < rhs.ptime_;
248  }
249 
258  friend inline bool operator> (const TimePoint& lhs, const TimePoint& rhs){ return rhs < lhs; }
259 
268  friend inline bool operator<=(const TimePoint& lhs, const TimePoint& rhs){ return !(lhs > rhs); }
269 
278  friend inline bool operator>=(const TimePoint& lhs, const TimePoint& rhs){ return !(lhs < rhs); }
279 
280 
281  // ************************************************************************************
282  // Start simple boost::posix_time wrappers
283 
286  int16_t year() const {return static_cast<int16_t>(ptime_.date().year());}
287 
290  uint8_t month() const {return static_cast<uint8_t>(ptime_.date().month());}
291 
294  uint8_t day() const {return static_cast<uint8_t>(ptime_.date().day());}
295 
298  uint16_t day_of_year() const {return static_cast<uint8_t>(ptime_.date().day_of_year());}
299 
302  uint8_t hour() const {return static_cast<uint8_t>(ptime_.time_of_day().hours());}
303 
306  uint8_t minute() const {return static_cast<uint8_t>(ptime_.time_of_day().minutes());}
307 
310  uint8_t second() const {return static_cast<uint8_t>(ptime_.time_of_day().seconds());}
311 
312  // End simple boost::posix_time wrappers
313  // ************************************************************************************
314  private:
315  boost::posix_time::ptime ptime_;
316  };
317 } // namespace focs
318 
319 #endif // FOCS_TIMEPOINT
320 
TimePoint(const boost::gregorian::date &date, const boost::posix_time::time_duration &time)
Construct a new TimePoint given date, time, and optional input clock_type.
Definition: TimePoint.hpp:74
data_t t[NROOTS+1]
Definition: decode_rs.h:77
uint8_t minute() const
Get minute part of the time.
Definition: TimePoint.hpp:306
friend bool operator!=(const TimePoint &lhs, const TimePoint &rhs)
Check if two time points are not equal (clock type or time differ)
Definition: TimePoint.hpp:236
double julian_date() const
Get Julian date.
Definition: TimePoint.hpp:206
double reduced_julian_date() const
Get reduced Julian date.
Definition: TimePoint.hpp:212
friend bool operator>=(const TimePoint &lhs, const TimePoint &rhs)
Return true if the left TimePoint is greater than or equal to the right.
Definition: TimePoint.hpp:278
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude resolving resolving GSFcd00179 Corrected handling of fill values for[Sensor|Solar][Zenith|Azimuth] resolving MODxl01751 Changed to validate LUT version against a value retrieved from the resolving MODxl02056 Changed to calculate Solar Diffuser angles without adjustment for estimated post launch changes in the MODIS orientation relative to incidentally resolving defects MODxl01766 Also resolves MODxl01947 Changed to ignore fill values in SCI_ABNORM and SCI_STATE rather than treating them as resolving MODxl01780 Changed to use spacecraft ancillary data to recognise when the mirror encoder data is being set by side A or side B and to change calculations accordingly This removes the need for seperate LUTs for Side A and Side B data it makes the new LUTs incompatible with older versions of the and vice versa Also resolves MODxl01685 A more robust GRing algorithm is being which will create a non default GRing anytime there s even a single geolocated pixel in a granule Removed obsolete messages from seed as required for compatibility with version of the SDP toolkit Corrected test output file names to end in out
Definition: HISTORY.txt:422
uint8_t day() const
Get month-based day part of the date (one-based, first of the month = 1)
Definition: TimePoint.hpp:294
friend bool operator>(const TimePoint &lhs, const TimePoint &rhs)
Return true if the left TimePoint is greater than the right.
Definition: TimePoint.hpp:258
Representation of a single point in time, with clock conversions.
Definition: TimePoint.hpp:29
double tai() const
Get TAI time in seconds since Jan 1, 1958 including leap seconds.
Definition: TimePoint.hpp:185
@ tai93
TAI clock 1993.
friend std::ostream & operator<<(std::ostream &out, const TimePoint &t)
Output time point using the to_string() function with default parameters.
Definition: TimePoint.hpp:132
double utc() const
Get UTC time (unix) in seconds since Jan 1, 1970.
Definition: TimePoint.hpp:181
int16_t year() const
Get year part of the date.
Definition: TimePoint.hpp:286
@ string
friend bool operator==(const TimePoint &lhs, const TimePoint &rhs)
Check if two time points are equal.
Definition: TimePoint.hpp:225
friend bool operator<=(const TimePoint &lhs, const TimePoint &rhs)
Return true if the left TimePoint is less than or equal to the right.
Definition: TimePoint.hpp:268
TimePoint(const boost::posix_time::ptime &ptime)
Construct a new TimePoint given a boost ptime.
Definition: TimePoint.hpp:90
const std::string to_string(const std::string &format="%Y-%m-%dT%H:%M:%S%F") const
Return time point as string, with the given format.
@ tt
Terrestrial Time clock 1977.
TimePoint(const boost::gregorian::date date, const boost::posix_time::time_duration &time, const int milli)
Construct a new TimePoint given date, time plus miliseconds.
Definition: TimePoint.hpp:83
double truncated_julian_date() const
Get truncated Julian date.
Definition: TimePoint.hpp:215
uint8_t hour() const
Get hour part of the time.
Definition: TimePoint.hpp:302
double tai93() const
Get TAI93 time in seconds since Jan 1, 1993 including leap seconds.
Definition: TimePoint.hpp:189
@ gps
GPS clock 1980, Jan 6.
uint8_t second() const
Get second part of the time.
Definition: TimePoint.hpp:310
double modified_julian_date() const
Get modified Julian date.
Definition: TimePoint.hpp:209
double tt() const
Get terrestrial time in seconds since Jan 1, 1977.
Definition: TimePoint.hpp:197
double seconds_since(const TimePoint::ClockType clock_type) const
Return duration since given time.
friend bool operator<(const TimePoint &lhs, const TimePoint &rhs)
Return true if the left TimePoint is less than the right.
Definition: TimePoint.hpp:246
@ local
Local UTC clock with time zone offset.
this program makes no use of any feature of the SDP Toolkit that could generate such a then geolocation is calculated at that and then aggregated up to Resolved feature request Bug by adding three new int8 SDSs for each high resolution offsets between the high resolution geolocation and a bi linear interpolation extrapolation of the positions This can be used to reconstruct the high resolution geolocation Resolved Bug by delaying cumulation of gflags until after validation of derived products Resolved Bug by setting Latitude and Longitude to the correct fill resolving to support Near Real Time because they may be unnecessary if use of entrained ephemeris and attitude data is turned resolving bug report Corrected to filter out Aqua attitude records with missing status helping resolve bug MOD_PR03 will still correctly write scan and pixel data that does not depend upon the start time
Definition: HISTORY.txt:248
TimePoint()
Construct a TimePoint with the current time.
Definition: TimePoint.hpp:47
uint16_t day_of_year() const
Get day of year part of the date (one-based, Jan 1 = 1)
Definition: TimePoint.hpp:298
const boost::posix_time::ptime & native() const
Get the native representation of this date time.
Definition: TimePoint.hpp:122
uint8_t month() const
Get month part of the date (one-based, Jan = 1)
Definition: TimePoint.hpp:290
double gps() const
Get GPS time in seconds since Jan 6, 1980 including leap seconds.
Definition: TimePoint.hpp:193