SAGA API v9.10
Loading...
Searching...
No Matches
datetime.h
Go to the documentation of this file.
1
3// //
4// SAGA //
5// //
6// System for Automated Geoscientific Analyses //
7// //
8// Application Programming Interface //
9// //
10// Library: SAGA_API //
11// //
12//-------------------------------------------------------//
13// //
14// datetime.h //
15// //
16// Copyright (C) 2015 by Olaf Conrad //
17// //
18//-------------------------------------------------------//
19// //
20// This file is part of 'SAGA - System for Automated //
21// Geoscientific Analyses'. //
22// //
23// This library is free software; you can redistribute //
24// it and/or modify it under the terms of the GNU Lesser //
25// General Public License as published by the Free //
26// Software Foundation, either version 2.1 of the //
27// License, or (at your option) any later version. //
28// //
29// This library is distributed in the hope that it will //
30// be useful, but WITHOUT ANY WARRANTY; without even the //
31// implied warranty of MERCHANTABILITY or FITNESS FOR A //
32// PARTICULAR PURPOSE. See the GNU Lesser General Public //
33// License for more details. //
34// //
35// You should have received a copy of the GNU Lesser //
36// General Public License along with this program; if //
37// not, see <http://www.gnu.org/licenses/>. //
38// //
39//-------------------------------------------------------//
40// //
41// contact: Olaf Conrad //
42// Institute of Geography //
43// University of Hamburg //
44// Germany //
45// //
46// e-mail: oconrad@saga-gis.org //
47// //
49
50//---------------------------------------------------------
51#ifndef HEADER_INCLUDED__SAGA_API__datetime_H
52#define HEADER_INCLUDED__SAGA_API__datetime_H
53
54
56// //
57// //
58// //
60
61//---------------------------------------------------------
71
72
74// //
75// //
76// //
78
79//---------------------------------------------------------
80#include "api_core.h"
81
82
84// //
85// //
86// //
88
89//---------------------------------------------------------
91{
92 friend class CSG_DateTime;
93
94public:
95
96 CSG_TimeSpan(void) { m_span = 0l ; }
97 CSG_TimeSpan(const CSG_TimeSpan &ts) { m_span = ts.m_span; }
98 CSG_TimeSpan(const sLong &diff) { m_span = diff ; }
99 CSG_TimeSpan(double hours) { m_span = (sLong)(1000.*60.*60. * hours); }
100 CSG_TimeSpan(long hours, long min = 0, sLong sec = 0, sLong msec = 0)
101 {
102 m_span = msec + 1000 * (sec + 60 * ((sLong)min + 60 * (sLong)hours));
103 }
104
105 //-----------------------------------------------------
106 static CSG_TimeSpan Milliseconds (sLong ms ) { return( CSG_TimeSpan(0, 0, 0, ms) ); }
107 static CSG_TimeSpan Seconds (sLong sec ) { return( CSG_TimeSpan(0, 0, sec ) ); }
108 static CSG_TimeSpan Minutes (long min ) { return( CSG_TimeSpan(0, min, 0 ) ); }
109 static CSG_TimeSpan Hours (long hours) { return( CSG_TimeSpan(hours, 0, 0) ); }
110 static CSG_TimeSpan Days (long days ) { return( Hours(24 * days) ); }
111 static CSG_TimeSpan Weeks (long days ) { return( Days ( 7 * days) ); }
112
113 static CSG_TimeSpan Millisecond (void) { return( Milliseconds(1) ); }
114 static CSG_TimeSpan Second (void) { return( Seconds (1) ); }
115 static CSG_TimeSpan Minute (void) { return( Minutes (1) ); }
116 static CSG_TimeSpan Hour (void) { return( Hours (1) ); }
117 static CSG_TimeSpan Day (void) { return( Days (1) ); }
118 static CSG_TimeSpan Week (void) { return( Weeks (1) ); }
119
120 //-----------------------------------------------------
121 CSG_TimeSpan & Add (const CSG_TimeSpan &ts) { m_span += ts.m_span; return( *this ); }
122 CSG_TimeSpan & Subtract (const CSG_TimeSpan &ts) { m_span -= ts.m_span; return( *this ); }
123 CSG_TimeSpan & Multiply (int n) { m_span *= n; return( *this ); }
124
125 CSG_TimeSpan & operator += (const CSG_TimeSpan &ts) { return( Add (ts) ); }
126 CSG_TimeSpan & operator -= (const CSG_TimeSpan &ts) { return( Subtract(ts) ); }
127 CSG_TimeSpan & operator *= (int n) { return( Multiply( n) ); }
128
129 CSG_TimeSpan Add (const CSG_TimeSpan &ts) const { return( CSG_TimeSpan(m_span + ts.m_span) ); }
130 CSG_TimeSpan Subtract (const CSG_TimeSpan &ts) const { return( CSG_TimeSpan(m_span - ts.m_span) ); }
131 CSG_TimeSpan Multiply (int n) const { return( CSG_TimeSpan(m_span * n) ); }
132
133 CSG_TimeSpan operator + (const CSG_TimeSpan &ts) const { return( CSG_TimeSpan(m_span + ts.m_span) ); }
134 CSG_TimeSpan operator - (const CSG_TimeSpan &ts) const { return( CSG_TimeSpan(m_span - ts.m_span) ); }
135 CSG_TimeSpan operator * (int n) const { return( CSG_TimeSpan(m_span * n) ); }
136
137 CSG_TimeSpan Abs (void) const { return( CSG_TimeSpan(m_span >= 0l ? m_span : -m_span) ); }
138 CSG_TimeSpan Negate (void) const { return( CSG_TimeSpan(-m_span) ); }
139 CSG_TimeSpan & Neg (void) { m_span = -m_span; return( *this ); }
140 CSG_TimeSpan & operator - (void) { return( Neg() ); }
141
142 bool is_Null (void) const { return( m_span == 0l ); }
143 bool is_Positive (void) const { return( m_span > 0l ); }
144 bool is_Negative (void) const { return( m_span < 0l ); }
145
146 bool operator ! (void) const { return( !is_Null() ); }
147
148 bool is_EqualTo (const CSG_TimeSpan &ts) const { return( m_span == ts.m_span ); }
149 bool is_LongerThan (const CSG_TimeSpan &ts) const { return( m_span > ts.m_span ); }
150 bool is_ShorterThan (const CSG_TimeSpan &ts) const { return( m_span < ts.m_span ); }
151
152 bool operator < (const CSG_TimeSpan &ts) const { return( m_span < ts.m_span ); }
153 bool operator <= (const CSG_TimeSpan &ts) const { return( m_span <= ts.m_span ); }
154 bool operator == (const CSG_TimeSpan &ts) const { return( m_span == ts.m_span ); }
155 bool operator != (const CSG_TimeSpan &ts) const { return( m_span != ts.m_span ); }
156 bool operator >= (const CSG_TimeSpan &ts) const { return( m_span >= ts.m_span ); }
157 bool operator > (const CSG_TimeSpan &ts) const { return( m_span > ts.m_span ); }
158
159 int Get_Weeks (void) const { return( Get_Days () / 7 ); }
160 int Get_Days (void) const { return( Get_Hours () / 24 ); }
161 int Get_Hours (void) const { return( Get_Minutes() / 60 ); }
162 int Get_Minutes (void) const { return( (int)(Get_Seconds() / 60) ); }
163 sLong Get_Seconds (void) const { return( m_span / 1000l ); }
164 sLong Get_Milliseconds (void) const { return( m_span ); }
165 sLong Get_Value (void) const { return( m_span ); }
166
167 CSG_String Format (const CSG_String &format = "") const;
168
169
170private:
171
172 sLong m_span;
173
174};
175
176
178// //
180
181//---------------------------------------------------------
183{
184public:
185
186 //-----------------------------------------------------
187 // types
188
189 typedef unsigned short TSG_DateTime;
190
191
192 //-----------------------------------------------------
193 // constants
194
195 enum Month // symbolic names for the months
196 {
198 };
199
200 enum WeekDay // symbolic names for the weekdays
201 {
203 };
204
205 enum Year // invalid value for the year
206 {
207 Inv_Year = -32768 // should hold in wxDateTime_t
208 };
209
210 enum NameFlags // flags for GetWeekDayName and GetMonthName
211 {
212 Name_Full = 0x01, // return full name
213 Name_Abbr = 0x02 // return abbreviated name
214 };
215
216
217public:
218
219 //-----------------------------------------------------
220 CSG_DateTime(void);
221 CSG_DateTime(const CSG_DateTime &DateTime);
222 CSG_DateTime(const CSG_String &ISODate);
223 CSG_DateTime(double JDN);
224 CSG_DateTime( TSG_DateTime Hour , TSG_DateTime Minute = 0, TSG_DateTime Second = 0, TSG_DateTime Millisec = 0);
225 CSG_DateTime(TSG_DateTime Day, Month Month, int Year = Inv_Year, TSG_DateTime Hour = 0, TSG_DateTime Minute = 0, TSG_DateTime Second = 0, TSG_DateTime Millisec = 0);
226
227 virtual ~CSG_DateTime(void);
228
229
230 //-----------------------------------------------------
231 CSG_DateTime & Set (const CSG_DateTime &DateTime);
232 CSG_DateTime & Set (const CSG_String &ISODate);
233 CSG_DateTime & Set (double JDN);
234 CSG_DateTime & Set ( TSG_DateTime Hour , TSG_DateTime Minute = 0, TSG_DateTime Second = 0, TSG_DateTime Millisec = 0);
235 CSG_DateTime & Set (TSG_DateTime Day, Month Month, int Year = Inv_Year, TSG_DateTime Hour = 0, TSG_DateTime Minute = 0, TSG_DateTime Second = 0, TSG_DateTime Millisec = 0);
236
237 CSG_DateTime & Set_Millisecond (unsigned short Value);
238 CSG_DateTime & Set_Second (unsigned short Value);
239 CSG_DateTime & Set_Minute (unsigned short Value);
240 CSG_DateTime & Set_Hour (unsigned short Value);
241 CSG_DateTime & Set_Hour (double Value);
242 CSG_DateTime & Set_Day (unsigned short Value);
243 CSG_DateTime & Set_Month (unsigned short Value);
244 CSG_DateTime & Set_Year (int Value);
245
246 CSG_DateTime & Set_DayOfYear (unsigned short Value);
247 CSG_DateTime & Set_To_Current (void);
248
249 CSG_DateTime & Set_Unix_Time (sLong Seconds);
250 CSG_DateTime & Set_Hours_AD (int Hours);
251
252 CSG_DateTime & Reset_Time (void);
253
254
255 //-----------------------------------------------------
256 CSG_DateTime From_UTC (bool noDST = false) const;
257 CSG_DateTime To_UTC (bool noDST = false) const;
258
259 CSG_DateTime & Make_UTC (bool noDST = false);
260
261 bool is_DST (void) const;
262
263
264 //-----------------------------------------------------
265 CSG_DateTime Add (const CSG_TimeSpan &TimeSpan) const;
266 CSG_DateTime & Add (const CSG_TimeSpan &TimeSpan);
267
268 CSG_DateTime Subtract (const CSG_TimeSpan &TimeSpan) const;
269 CSG_DateTime & Subtract (const CSG_TimeSpan &TimeSpan);
270
271 CSG_TimeSpan Subtract (const CSG_DateTime &DateTime) const;
272
273
274 //-----------------------------------------------------
275 bool is_Valid (void) const;
276
277 sLong Get_Value (void) const;
278
279 unsigned short Get_Millisecond (void) const;
280 unsigned short Get_Second (void) const;
281 unsigned short Get_Minute (void) const;
282 unsigned short Get_Hour (void) const;
283
284 unsigned short Get_Day (void) const;
285 Month Get_Month (void) const;
286 int Get_Year (void) const;
287
288 unsigned short Get_DayOfYear (void) const;
289 WeekDay Get_WeekDay (void) const;
290 TSG_DateTime Get_WeekOfMonth (void) const;
291 TSG_DateTime Get_WeekOfYear (void) const;
292
293 double Get_JDN (void) const;
294 double Get_MJD (void) const;
295 sLong Get_Unix_Time (void) const;
296
297
298 //-----------------------------------------------------
299 bool is_EarlierThan (const CSG_DateTime &DateTime) const;
300 bool is_EqualTo (const CSG_DateTime &DateTime) const;
301 bool is_LaterThan (const CSG_DateTime &DateTime) const;
302
303 bool is_SameDate (const CSG_DateTime &DateTime) const;
304 bool is_SameTime (const CSG_DateTime &DateTime) const;
305
306 bool is_Between (const CSG_DateTime &t1, const CSG_DateTime &t2) const;
307 bool is_StrictlyBetween (const CSG_DateTime &t1, const CSG_DateTime &t2) const;
308
309
310 //-----------------------------------------------------
311 CSG_DateTime & operator = (const CSG_DateTime &DateTime) { return( Set (DateTime) ); }
312 CSG_DateTime & operator = (double JDN) { return( Set ( JDN) ); }
313
314 CSG_DateTime & operator += (const CSG_TimeSpan &TimeSpan) { return( Add (TimeSpan) ); }
315 CSG_DateTime & operator -= (const CSG_TimeSpan &TimeSpan) { return( Subtract(TimeSpan) ); }
316
317 CSG_DateTime operator + (const CSG_TimeSpan &TimeSpan) const { return( Add (TimeSpan) ); }
318 CSG_DateTime operator - (const CSG_TimeSpan &TimeSpan) const { return( Subtract(TimeSpan) ); }
319
320 CSG_TimeSpan operator - (const CSG_DateTime &DateTime) const { return( Subtract(DateTime) ); }
321
322 bool operator < (const CSG_DateTime &DateTime) const { return( Get_Value() < DateTime.Get_Value() ); }
323 bool operator <= (const CSG_DateTime &DateTime) const { return( Get_Value() <= DateTime.Get_Value() ); }
324 bool operator == (const CSG_DateTime &DateTime) const { return( Get_Value() == DateTime.Get_Value() ); }
325 bool operator >= (const CSG_DateTime &DateTime) const { return( Get_Value() >= DateTime.Get_Value() ); }
326 bool operator > (const CSG_DateTime &DateTime) const { return( Get_Value() > DateTime.Get_Value() ); }
327
328
329 //-----------------------------------------------------
330 CSG_String Format (const CSG_String &Format = "") const;
331 CSG_String Format_Date (void) const;
332 CSG_String Format_Time (void) const;
333 CSG_String Format_ISODate (void) const;
334 CSG_String Format_ISOTime (void) const;
335 CSG_String Format_ISOCombined (char sep = 'T') const;
336
337 bool Parse_Date (const CSG_String &date);
338 bool Parse_DateTime (const CSG_String &datetime);
339 bool Parse_Format (const CSG_String &date, const CSG_String &format, const CSG_DateTime &dateDef);
340 bool Parse_Format (const CSG_String &date, const CSG_String &format);
341 bool Parse_Format (const CSG_String &date);
342 bool Parse_ISOCombined (const CSG_String &date, char sep= 'T');
343 bool Parse_ISODate (const CSG_String &date);
344 bool Parse_ISOTime (const CSG_String &date);
345
346
347 //-----------------------------------------------------
348 static TSG_DateTime Get_Current_Day (void);
349 static Month Get_Current_Month (void);
350 static int Get_Current_Year (void);
351
352 static CSG_String Get_MonthName (Month month, NameFlags flags = Name_Full);
353 static CSG_String Get_EnglishMonthName (Month month, NameFlags flags = Name_Full);
354 static CSG_String Get_WeekDayName (WeekDay weekday, NameFlags flags = Name_Full);
355 static CSG_String Get_EnglishWeekDayName (WeekDay weekday, NameFlags flags = Name_Full);
356
357 static TSG_DateTime Get_NumberOfDays ( int year);
358 static TSG_DateTime Get_NumberOfDays (Month month, int year = Inv_Year);
359
360 static bool is_LeapYear (int year = Inv_Year);
361
362 static CSG_DateTime Now (void);
363
364 static CSG_String Get_Month_Choices (void);
365
366
367private:
368
369 class wxDateTime *m_pDateTime;
370
371};
372
373
375// //
376// //
377// //
379
380//---------------------------------------------------------
381SAGA_API_DLL_EXPORT bool SG_JulianDayNumber_To_Date (double JDN, int &y, int &m, int &d);
384
385SAGA_API_DLL_EXPORT double SG_Date_To_JulianDayNumber (int y, int m, int d);
387
388SAGA_API_DLL_EXPORT int SG_Get_Day_MidOfMonth (int Month, bool bLeapYear = false);
389
390
392// //
393// //
394// //
396
397//---------------------------------------------------------
398SAGA_API_DLL_EXPORT bool SG_Get_Sun_Position (double JulianDayNumber, double &RA, double &Dec);
399SAGA_API_DLL_EXPORT bool SG_Get_Sun_Position (const CSG_DateTime &Time, double &RA, double &Dec);
400
401SAGA_API_DLL_EXPORT bool SG_Get_Sun_Position (double JulianDayNumber, double Longitude, double Latitude, double &Height, double &Azimuth, bool bRefraction = false);
402SAGA_API_DLL_EXPORT bool SG_Get_Sun_Position (const CSG_DateTime &Time, double Longitude, double Latitude, double &Height, double &Azimuth, bool bRefraction = false);
403SAGA_API_DLL_EXPORT bool SG_Get_Sun_Position (double JulianDayNumber, double Longitude, double Latitude, class CSG_Vector &Position , bool bRefraction = false);
404SAGA_API_DLL_EXPORT bool SG_Get_Sun_Position (const CSG_DateTime &Time, double Longitude, double Latitude, class CSG_Vector &Position , bool bRefraction = false);
405
406SAGA_API_DLL_EXPORT double SG_Get_Sun_Refraction (double Height, bool bRadians);
407
408SAGA_API_DLL_EXPORT double SG_Get_Day_Length (int DayOfYear, double Latitude);
409SAGA_API_DLL_EXPORT double SG_Get_Day_Length (const CSG_DateTime &Date, double Latitude);
410
411
413// //
414// //
415// //
417
418//---------------------------------------------------------
419#endif // #ifndef HEADER_INCLUDED__SAGA_API__datetime_H
signed long long sLong
Definition api_core.h:158
#define SAGA_API_DLL_EXPORT
Definition api_core.h:94
SAGA_API_DLL_EXPORT CSG_String operator+(const char *A, const CSG_String &B)
CSG_DateTime Add(const CSG_TimeSpan &TimeSpan) const
Definition datetime.cpp:324
sLong Get_Value(void) const
Definition datetime.cpp:313
unsigned short TSG_DateTime
Definition datetime.h:189
CSG_DateTime(void)
Definition datetime.cpp:82
CSG_DateTime Subtract(const CSG_TimeSpan &TimeSpan) const
Definition datetime.cpp:339
CSG_DateTime & Set(const CSG_DateTime &DateTime)
Definition datetime.cpp:131
static CSG_TimeSpan Second(void)
Definition datetime.h:114
static CSG_TimeSpan Days(long days)
Definition datetime.h:110
CSG_TimeSpan(double hours)
Definition datetime.h:99
CSG_TimeSpan(const CSG_TimeSpan &ts)
Definition datetime.h:97
CSG_TimeSpan(void)
Definition datetime.h:96
int Get_Minutes(void) const
Definition datetime.h:162
bool is_ShorterThan(const CSG_TimeSpan &ts) const
Definition datetime.h:150
CSG_TimeSpan & Subtract(const CSG_TimeSpan &ts)
Definition datetime.h:122
CSG_TimeSpan(long hours, long min=0, sLong sec=0, sLong msec=0)
Definition datetime.h:100
CSG_TimeSpan & Add(const CSG_TimeSpan &ts)
Definition datetime.h:121
static CSG_TimeSpan Minute(void)
Definition datetime.h:115
CSG_TimeSpan & Multiply(int n)
Definition datetime.h:123
bool is_Null(void) const
Definition datetime.h:142
static CSG_TimeSpan Hours(long hours)
Definition datetime.h:109
CSG_TimeSpan Negate(void) const
Definition datetime.h:138
static CSG_TimeSpan Hour(void)
Definition datetime.h:116
int Get_Weeks(void) const
Definition datetime.h:159
bool is_Positive(void) const
Definition datetime.h:143
bool is_EqualTo(const CSG_TimeSpan &ts) const
Definition datetime.h:148
CSG_TimeSpan Add(const CSG_TimeSpan &ts) const
Definition datetime.h:129
CSG_TimeSpan Subtract(const CSG_TimeSpan &ts) const
Definition datetime.h:130
CSG_TimeSpan(const sLong &diff)
Definition datetime.h:98
static CSG_TimeSpan Millisecond(void)
Definition datetime.h:113
sLong Get_Value(void) const
Definition datetime.h:165
static CSG_TimeSpan Day(void)
Definition datetime.h:117
static CSG_TimeSpan Seconds(sLong sec)
Definition datetime.h:107
sLong Get_Milliseconds(void) const
Definition datetime.h:164
sLong Get_Seconds(void) const
Definition datetime.h:163
int Get_Hours(void) const
Definition datetime.h:161
bool is_LongerThan(const CSG_TimeSpan &ts) const
Definition datetime.h:149
CSG_TimeSpan & Neg(void)
Definition datetime.h:139
int Get_Days(void) const
Definition datetime.h:160
friend class CSG_DateTime
Definition datetime.h:92
static CSG_TimeSpan Minutes(long min)
Definition datetime.h:108
static CSG_TimeSpan Milliseconds(sLong ms)
Definition datetime.h:106
bool is_Negative(void) const
Definition datetime.h:144
static CSG_TimeSpan Weeks(long days)
Definition datetime.h:111
static CSG_TimeSpan Week(void)
Definition datetime.h:118
CSG_TimeSpan Multiply(int n) const
Definition datetime.h:131
CSG_TimeSpan Abs(void) const
Definition datetime.h:137
SAGA_API_DLL_EXPORT double SG_Get_Sun_Refraction(double Height, bool bRadians)
Definition datetime.cpp:947
SAGA_API_DLL_EXPORT double SG_Get_Day_Length(int DayOfYear, double Latitude)
Definition datetime.cpp:976
SAGA_API_DLL_EXPORT bool SG_Get_Sun_Position(double JulianDayNumber, double &RA, double &Dec)
Definition datetime.cpp:841
SAGA_API_DLL_EXPORT bool SG_JulianDayNumber_To_Date(double JDN, int &y, int &m, int &d)
Definition datetime.cpp:682
SAGA_API_DLL_EXPORT double SG_Date_To_JulianDayNumber(int y, int m, int d)
Definition datetime.cpp:742
SAGA_API_DLL_EXPORT int SG_Get_Day_MidOfMonth(int Month, bool bLeapYear=false)
Definition datetime.cpp:790
CSG_Vector operator*(double Scalar, const CSG_Vector &Vector)