Ilwis-Objects  1.0
GIS and Remote Sensing framework for data access and processing
All Classes Functions Enumerations Pages
juliantime.h
1 #ifndef TIME_H
2 #define TIME_H
3 
4 #include "Kernel_global.h"
5 
6 namespace Ilwis {
7 
8 class Duration;
18 class KERNELSHARED_EXPORT Time {
19 public:
23  enum TimePart{tpYEAR, tpMONTH, tpDAYOFMONTH, tpJULIANDAY, tpDAYOFTHEWEEK, tpDAYOFTHEYEAR, tpWEEKNUMBER, tpHOUR, tpMINUTE, tpSECOND, tpDATE, tpDAYTIME};
24 
25  Time();
38  Time(int year, int month, int day, int hour, int minute, double seconds=0);
48  Time(int hour, int minute, double seconds=0);
58  Time(int year, int month=1, int day=1);
59 
64  Time(const time_t time);
65 
72  //TODO link to isostring docu?
73  Time(const QString& isostring);
74  Time(const char * isostring);
75 
81  Time(double jd, IlwisTypes m =itDATETIME);
82 
89  Time(const QDateTime &time);
90  Time(const QDate& date);
91  Time(const QTime& tm);
92  Time(const Time& time);
93 
97  virtual ~Time();
98 
102  operator double() const;
103 
107  operator QDateTime() const;
108 
115  Time& operator=(double t);
116 
121  time_t toTime_t() const;
122 
129  bool isLeapYear(int year = iUNDEF) const;
130 
149  virtual double get(TimePart part) const;
150 
160  Duration operator-(const Time& time) const;
161 
171  Time operator+(const Duration& duration) const;
172 
182  bool operator <(const Time& time) const;
183 
193  bool operator >(const Time& time) const;
194 
204  bool operator ==(const Time& time) const;
205 
215  bool operator !=(const Time& time) const;
216 
227  void setValue(const QString& isostring);
228 
236  void setYear(int year);
237 
245  void setMonth(int Mnt);
246 
254  void setDay(int dy);
255 
263  void setHour(int hr);
264 
272  void setMinute(int min);
273 
281  void setSecond(double sec);
282 
295  virtual QString toString(bool local= false, IlwisTypes tp=itUNKNOWN) const;
296 
303  virtual bool isValid() const;
304 
310  static Time now();
311 
312  //@override
313  IlwisTypes valueType() const;
314 
315  //@override
316  void valueType(IlwisTypes tp);
317 
318 protected:
319  void checkDate(int year, int month, int day); // alters _valid
320  void checkTime(int hour, int minute, double seconds); //alters _valid
321 
322  double gregorianToJulian(int year, int month, int day, int hour, int minutes, double seconds) const;
323  void julianToGregorian(int& year, int& month, int& day, int& hour, int& minutes, double& seconds) const;
324  int julianyearday(int year, int month, int day) const;
325  int tolong(double val) const;
326  void parseOrdinalDate(int ordinal, int year, int& month, int& day);
327  void parseYearPart(const QString& yearpart, int& year, int& month, int& day) ;
328  void parseDayPart(const QString& dayPart, int& hours, int& minutes, double& seconds);
329  void parseIsoString(const QString& isostring, int& year, int& month, int& day, int& hours, int& minutes, double& seconds);
330 
331  double _julianday;
332  bool _valid;
333  IlwisTypes _valuetype;
334 };
335 
336 class KERNELSHARED_EXPORT Duration : public Time {
337 public:
338  Duration(const QString& step="",IlwisTypes tp=itTIME);
339  Duration(double r,IlwisTypes tp=itTIME);
340  QString toString(bool local, IlwisTypes tp=itTIME) const;
341  bool isValid() const;
342  double get(TimePart part) const;
343 };
344 
345 class KERNELSHARED_EXPORT TimeInterval : public NumericRange {
346 public:
347  TimeInterval(IlwisTypes tp=itUNKNOWN);
348  TimeInterval(const Time& begin, const Time& end, const Duration& stp=Duration(""), IlwisTypes tp=itUNKNOWN);
349 // TimeInterval operator+(const TimeInterval& interval);
350 // TimeInterval operator-(const TimeInterval& interval);
351  TimeInterval& operator=(const TimeInterval& tiv);
352  Time begin() const { return Time(min());}
353  Time end() const { return Time(max());}
354  void begin(const Time& t) ;
355  void end(const Time& t);
356  Duration getStep() const { return _step;}
357  QString toString(bool local, IlwisTypes) const;
358  bool contains(const QString& value, bool inclusive = true) const;
359  bool contains(const Time& value, bool inclusive = true) const;
360  bool contains(const QVariant& value, bool inclusive = true) const;
361  QVariant impliedValue(const QVariant& v) const;
362 
363  Range *clone() const ;
364  bool isValid() const;
365 
366 private:
367  Duration _step;
368 };
369 
370 #define tUNDEF Time()
371 
372 }
373 
374 Q_DECLARE_METATYPE(Ilwis::Time)
375 Q_DECLARE_METATYPE(Ilwis::Duration)
376 Q_DECLARE_METATYPE(Ilwis::TimeInterval)
377 
378 #endif // TIME_H