[droid] Do not show any ui if pre-checks are OK
[vuplus_xbmc] / xbmc / XBDateTime.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2012 Team XBMC
5  *      http://www.xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #include "utils/Archive.h"
24
25 /*! \brief TIME_FORMAT enum/bitmask used for formatting time strings
26  Note the use of bitmasking, e.g.
27   TIME_FORMAT_HH_MM_SS = TIME_FORMAT_HH | TIME_FORMAT_MM | TIME_FORMAT_SS
28  \sa StringUtils::SecondsToTimeString
29  */
30 enum TIME_FORMAT { TIME_FORMAT_GUESS     =  0,
31                    TIME_FORMAT_SS        =  1,
32                    TIME_FORMAT_MM        =  2,
33                    TIME_FORMAT_MM_SS     =  3,
34                    TIME_FORMAT_HH        =  4,
35                    TIME_FORMAT_HH_SS     =  5, // not particularly useful
36                    TIME_FORMAT_HH_MM     =  6,
37                    TIME_FORMAT_HH_MM_SS  =  7,
38                    TIME_FORMAT_XX        =  8, // AM/PM
39                    TIME_FORMAT_HH_MM_XX  = 14,
40                    TIME_FORMAT_H         = 16,
41                    TIME_FORMAT_H_MM_SS   = 19};
42
43 class CDateTime;
44
45 class CDateTimeSpan
46 {
47 public:
48   CDateTimeSpan();
49   CDateTimeSpan(const CDateTimeSpan& span);
50   CDateTimeSpan(int day, int hour, int minute, int second);
51
52   bool operator >(const CDateTimeSpan& right) const;
53   bool operator >=(const CDateTimeSpan& right) const;
54   bool operator <(const CDateTimeSpan& right) const;
55   bool operator <=(const CDateTimeSpan& right) const;
56   bool operator ==(const CDateTimeSpan& right) const;
57   bool operator !=(const CDateTimeSpan& right) const;
58
59   CDateTimeSpan operator +(const CDateTimeSpan& right) const;
60   CDateTimeSpan operator -(const CDateTimeSpan& right) const;
61
62   const CDateTimeSpan& operator +=(const CDateTimeSpan& right);
63   const CDateTimeSpan& operator -=(const CDateTimeSpan& right);
64
65   void SetDateTimeSpan(int day, int hour, int minute, int second);
66   void SetFromPeriod(const CStdString &period);
67   void SetFromTimeString(const CStdString& time);
68
69   int GetDays() const;
70   int GetHours() const;
71   int GetMinutes() const;
72   int GetSeconds() const;
73
74 private:
75   void ToULargeInt(ULARGE_INTEGER& time) const;
76   void FromULargeInt(const ULARGE_INTEGER& time);
77
78 private:
79   FILETIME m_timeSpan;
80
81   friend class CDateTime;
82 };
83
84 /// \brief DateTime class, which uses FILETIME as it's base.
85 class CDateTime : public IArchivable
86 {
87 public:
88   CDateTime();
89   CDateTime(const CDateTime& time);
90   CDateTime(const SYSTEMTIME& time);
91   CDateTime(const FILETIME& time);
92   CDateTime(const time_t& time);
93   CDateTime(const tm& time);
94   CDateTime(int year, int month, int day, int hour, int minute, int second);
95   virtual ~CDateTime() {}
96
97   void SetFromDateString(const CStdString &date);
98
99   static CDateTime GetCurrentDateTime();
100   static CDateTime GetUTCDateTime();
101   static int MonthStringToMonthNum(const CStdString& month);
102
103   const CDateTime& operator =(const SYSTEMTIME& right);
104   const CDateTime& operator =(const FILETIME& right);
105   const CDateTime& operator =(const time_t& right);
106   const CDateTime& operator =(const tm& right);
107
108   bool operator >(const CDateTime& right) const;
109   bool operator >=(const CDateTime& right) const;
110   bool operator <(const CDateTime& right) const;
111   bool operator <=(const CDateTime& right) const;
112   bool operator ==(const CDateTime& right) const;
113   bool operator !=(const CDateTime& right) const;
114
115   bool operator >(const FILETIME& right) const;
116   bool operator >=(const FILETIME& right) const;
117   bool operator <(const FILETIME& right) const;
118   bool operator <=(const FILETIME& right) const;
119   bool operator ==(const FILETIME& right) const;
120   bool operator !=(const FILETIME& right) const;
121
122   bool operator >(const SYSTEMTIME& right) const;
123   bool operator >=(const SYSTEMTIME& right) const;
124   bool operator <(const SYSTEMTIME& right) const;
125   bool operator <=(const SYSTEMTIME& right) const;
126   bool operator ==(const SYSTEMTIME& right) const;
127   bool operator !=(const SYSTEMTIME& right) const;
128
129   bool operator >(const time_t& right) const;
130   bool operator >=(const time_t& right) const;
131   bool operator <(const time_t& right) const;
132   bool operator <=(const time_t& right) const;
133   bool operator ==(const time_t& right) const;
134   bool operator !=(const time_t& right) const;
135
136   bool operator >(const tm& right) const;
137   bool operator >=(const tm& right) const;
138   bool operator <(const tm& right) const;
139   bool operator <=(const tm& right) const;
140   bool operator ==(const tm& right) const;
141   bool operator !=(const tm& right) const;
142
143   CDateTime operator +(const CDateTimeSpan& right) const;
144   CDateTime operator -(const CDateTimeSpan& right) const;
145
146   const CDateTime& operator +=(const CDateTimeSpan& right);
147   const CDateTime& operator -=(const CDateTimeSpan& right);
148
149   CDateTimeSpan operator -(const CDateTime& right) const;
150
151   operator FILETIME() const;
152
153   virtual void Archive(CArchive& ar);
154
155   void Reset();
156
157   int GetDay() const;
158   int GetMonth() const;
159   int GetYear() const;
160   int GetHour() const;
161   int GetMinute() const;
162   int GetSecond() const;
163   int GetDayOfWeek() const;
164   int GetMinuteOfDay() const;
165
166   void SetDateTime(int year, int month, int day, int hour, int minute, int second);
167   void SetDate(int year, int month, int day);
168   void SetTime(int hour, int minute, int second);
169   void SetFromDBDate(const CStdString &date);
170   void SetFromDBTime(const CStdString &time);
171   void SetFromW3CDate(const CStdString &date);
172   void SetFromUTCDateTime(const CDateTime &dateTime);
173   void SetFromUTCDateTime(const time_t &dateTime);
174   void SetFromRFC1123DateTime(const CStdString &dateTime);
175
176   /*! \brief set from a database datetime format YYYY-MM-DD HH:MM:SS
177    \sa GetAsDBDateTime()
178    */
179   void SetFromDBDateTime(const CStdString &dateTime);
180
181   void GetAsSystemTime(SYSTEMTIME& time) const;
182   void GetAsTime(time_t& time) const;
183   void GetAsTm(tm& time) const;
184   void GetAsTimeStamp(FILETIME& time) const;
185
186   CDateTime GetAsUTCDateTime() const;
187   CStdString GetAsSaveString() const;
188   CStdString GetAsDBDateTime() const;
189   CStdString GetAsDBDate() const;
190   CStdString GetAsLocalizedDate(bool longDate=false, bool withShortNames=true) const;
191   CStdString GetAsLocalizedDate(const CStdString &strFormat, bool withShortNames=true) const;
192   CStdString GetAsLocalizedTime(const CStdString &format, bool withSeconds=true) const;
193   CStdString GetAsLocalizedDateTime(bool longDate=false, bool withSeconds=true) const;
194   CStdString GetAsRFC1123DateTime() const;
195
196   void SetValid(bool yesNo);
197   bool IsValid() const;
198
199   static void ResetTimezoneBias(void);
200   static CDateTimeSpan GetTimezoneBias(void);
201
202 private:
203   bool ToFileTime(const SYSTEMTIME& time, FILETIME& fileTime) const;
204   bool ToFileTime(const time_t& time, FILETIME& fileTime) const;
205   bool ToFileTime(const tm& time, FILETIME& fileTime) const;
206
207   void ToULargeInt(ULARGE_INTEGER& time) const;
208   void FromULargeInt(const ULARGE_INTEGER& time);
209
210 private:
211   FILETIME m_time;
212
213   typedef enum _STATE
214   {
215     invalid=0,
216     valid
217   } STATE;
218
219   STATE m_state;
220 };