isce3  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
DateTime.h
1 //-*- C++ -*-
2 //-*- coding: utf-8 -*-
3 //
4 //
5 // Author: Piyush Agram
6 // Copyright 2017-2018
7 
8 #pragma once
9 
10 #include "forward.h"
11 
12 #include <cassert>
13 #include <cmath>
14 #include <iostream>
15 #include <string>
16 
19 public:
20 
21  int year;
22  int months;
23  int days;
24  int hours;
25  int minutes;
26  int seconds;
27  double frac;
28 
32  DateTime() : DateTime(1970, 1, 1) {};
33 
35  DateTime(double ord);
36 
38  DateTime(int yy, int mm, int dd);
39 
41  DateTime(int yy, int mm, int dd, int hh, int mn, int ss);
42 
44  DateTime(int yy, int mm, int dd, int hh, int mn, double ss);
45 
47  DateTime(int yy, int mm, int dd, int hh, int mn, int ss, double ff);
48 
50  DateTime(const DateTime& ts);
51 
53  DateTime(const std::string &);
54 
56  void _init(int yy, int mm, int dd, int hh, int mn, int ss, double ff);
57  void _normalize_time();
58  void _normalize_date();
59  void _normalize();
61 
62  explicit operator std::string() const { return isoformat(); }
63 
64  // Comparison operators
65  bool operator<(const DateTime &ts) const;
66  bool operator>(const DateTime &ts) const;
67  bool operator<=(const DateTime &ts) const;
68  bool operator>=(const DateTime &ts) const;
69  bool operator==(const DateTime &ts) const;
70  bool operator!=(const DateTime &ts) const;
71 
72  // Math operators
73  DateTime& operator=(const DateTime& ts);
74  DateTime& operator=(const std::string &);
75  DateTime& operator+=(const TimeDelta& ts);
76  DateTime& operator+=(const double& s);
77  DateTime& operator-=(const TimeDelta& ts);
78  DateTime& operator-=(const double& s);
79 
80  DateTime operator+(const TimeDelta& ts) const;
81  DateTime operator+(const double& s) const;
82  DateTime operator-(const TimeDelta& ts) const;
83  DateTime operator-(const double& s) const;
84 
85  TimeDelta operator-(const DateTime& ts) const;
86 
88  bool isClose(const DateTime& ts) const;
89 
94  bool isClose(const DateTime& ts, const TimeDelta& errtol) const;
95 
97  int dayOfYear() const;
98 
100  double secondsOfDay() const;
101 
103  int dayOfWeek() const;
104 
106  double ordinal() const;
107 
109  double secondsSinceEpoch() const;
110 
112  double secondsSinceEpoch(const DateTime &) const;
113 
115  void secondsSinceEpoch(double);
116 
118  std::string isoformat() const;
119 
121  void strptime(const std::string &, const std::string & sep = "T");
122 };
123 
124 // Some constants
125 namespace isce3 {
126  namespace core {
127 
128  std::ostream & operator<<(std::ostream &, const DateTime &);
129 
130  // Constants for default constructors
131  const DateTime MIN_DATE_TIME = DateTime(1970, 1, 1);
132  const std::string UNINITIALIZED_STRING = "uninitialized";
133 
134  static const int DaysInMonths[] = {31,28,31,
135  30,31,30,
136  31,31,30,
137  31,30,31};
138 
139  static const int DaysBeforeMonths[] = {0,31,59,
140  90,120,151,
141  181,212,243,
142  273,304,334};
143  static const int DAY_TO_YEAR = 365;
144  static const int DAYSPER100 = 36524;
145  static const int DAYSPER400 = 146097;
146  static const int DAYSPER4 = 1461;
147  static const int MAXORDINAL = 3652059;
148 
149  static const double TOL_SECONDS = 1e-10;
150 
151  // Handful of utility functions
152  bool _is_leap(int);
153  int _days_in_month(int, int);
154  int _days_before_year(int);
155  int _days_before_month(int, int);
156  int _ymd_to_ord(int, int, int);
157  void _ord_to_ymd(int, int &, int &, int &);
158  }
159 }
double secondsOfDay() const
Return seconds of day.
Definition: DateTime.cpp:418
Data structure to store date time to nano-sec precision.
Definition: DateTime.h:18
std::string isoformat() const
Return date formatted as ISO-8601 string.
Definition: DateTime.cpp:452
bool isClose(const DateTime &ts) const
Check whether two DateTimes are equivalent to within TOL_SECONDS.
Definition: DateTime.cpp:403
DateTime()
Default constructor.
Definition: DateTime.h:32
double ordinal() const
Return ordinal - time since GPS time origin.
int dayOfWeek() const
Return day of week.
void strptime(const std::string &, const std::string &sep="T")
Parse a given string in ISO-8601 format.
Definition: DateTime.cpp:467
double secondsSinceEpoch() const
Return ordinal - time since GPS time origin.
Definition: DateTime.cpp:438
int dayOfYear() const
Return day of year.

Generated for ISCE3.0 by doxygen 1.8.5.