[osx/ios] remove unused function
[vuplus_xbmc] / xbmc / DateTime.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2008 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, write to
19  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20  *  http://www.gnu.org/copyleft/gpl.html
21  *
22  */
23
24 #include "utils/Archive.h"
25
26 /*! \brief TIME_FORMAT enum/bitmask used for formatting time strings
27  Note the use of bitmasking, e.g.
28   TIME_FORMAT_HH_MM_SS = TIME_FORMAT_HH | TIME_FORMAT_MM | TIME_FORMAT_SS
29  \sa StringUtils::SecondsToTimeString
30  */
31 enum TIME_FORMAT { TIME_FORMAT_GUESS     =  0,
32                    TIME_FORMAT_SS        =  1,
33                    TIME_FORMAT_MM        =  2,
34                    TIME_FORMAT_MM_SS     =  3,
35                    TIME_FORMAT_HH        =  4,
36                    TIME_FORMAT_HH_SS     =  5, // not particularly useful
37                    TIME_FORMAT_HH_MM     =  6,
38                    TIME_FORMAT_HH_MM_SS  =  7,
39                    TIME_FORMAT_XX        =  8, // AM/PM
40                    TIME_FORMAT_HH_MM_XX  = 14};
41
42 class CDateTime;
43
44 class CDateTimeSpan
45 {
46 public:
47   CDateTimeSpan();
48   CDateTimeSpan(const CDateTimeSpan& span);
49   CDateTimeSpan(int day, int hour, int minute, int second);
50
51   bool operator >(const CDateTimeSpan& right) const;
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
58   CDateTimeSpan operator +(const CDateTimeSpan& right) const;
59   CDateTimeSpan operator -(const CDateTimeSpan& right) const;
60
61   const CDateTimeSpan& operator +=(const CDateTimeSpan& right);
62   const CDateTimeSpan& operator -=(const CDateTimeSpan& right);
63
64   void SetDateTimeSpan(int day, int hour, int minute, int second);
65   void SetFromPeriod(const CStdString &period);
66   void SetFromTimeString(const CStdString& time);
67
68   int GetDays() const;
69   int GetHours() const;
70   int GetMinutes() const;
71   int GetSeconds() const;
72
73 private:
74   void ToULargeInt(ULARGE_INTEGER& time) const;
75   void FromULargeInt(const ULARGE_INTEGER& time);
76
77 private:
78   FILETIME m_timeSpan;
79
80   friend class CDateTime;
81 };
82
83 /// \brief DateTime class, which uses FILETIME as it's base.
84 class CDateTime : public IArchivable
85 {
86 public:
87   CDateTime();
88   CDateTime(const CDateTime& time);
89   CDateTime(const SYSTEMTIME& time);
90   CDateTime(const FILETIME& time);
91   CDateTime(const time_t& time);
92   CDateTime(const tm& time);
93   CDateTime(int year, int month, int day, int hour, int minute, int second);
94   virtual ~CDateTime() {}
95
96   void SetFromDateString(const CStdString &date);
97
98   static CDateTime GetCurrentDateTime();
99   static CDateTime GetUTCDateTime();
100
101   const CDateTime& operator =(const SYSTEMTIME& right);
102   const CDateTime& operator =(const FILETIME& right);
103   const CDateTime& operator =(const time_t& right);
104   const CDateTime& operator =(const tm& right);
105
106   bool operator >(const CDateTime& right) const;
107   bool operator >=(const CDateTime& right) const;
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
113   bool operator >(const FILETIME& right) const;
114   bool operator >=(const FILETIME& right) const;
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
120   bool operator >(const SYSTEMTIME& right) const;
121   bool operator >=(const SYSTEMTIME& right) const;
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
127   bool operator >(const time_t& right) const;
128   bool operator >=(const time_t& right) const;
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
134   bool operator >(const tm& right) const;
135   bool operator >=(const tm& right) const;
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
141   CDateTime operator +(const CDateTimeSpan& right) const;
142   CDateTime operator -(const CDateTimeSpan& right) const;
143
144   const CDateTime& operator +=(const CDateTimeSpan& right);
145   const CDateTime& operator -=(const CDateTimeSpan& right);
146
147   CDateTimeSpan operator -(const CDateTime& right) const;
148
149   operator FILETIME() const;
150
151   virtual void Archive(CArchive& ar);
152
153   void Reset();
154
155   int GetDay() const;
156   int GetMonth() const;
157   int GetYear() const;
158   int GetHour() const;
159   int GetMinute() const;
160   int GetSecond() const;
161   int GetDayOfWeek() const;
162   int GetMinuteOfDay() const;
163
164   void SetDateTime(int year, int month, int day, int hour, int minute, int second);
165   void SetDate(int year, int month, int day);
166   void SetTime(int hour, int minute, int second);
167   void SetFromDBDate(const CStdString &date);
168   void SetFromDBTime(const CStdString &time);
169   void SetFromW3CDate(const CStdString &date);
170
171   /*! \brief set from a database datetime format YYYY-MM-DD HH:MM:SS
172    \sa GetAsDBDateTime()
173    */
174   void SetFromDBDateTime(const CStdString &dateTime);
175
176   void GetAsSystemTime(SYSTEMTIME& time) const;
177   void GetAsTime(time_t& time) const;
178   void GetAsTm(tm& time) const;
179   void GetAsTimeStamp(FILETIME& time) const;
180
181   CDateTime GetAsUTCDateTime() const;
182   CStdString GetAsDBDateTime() const;
183   CStdString GetAsDBDate() const;
184   CStdString GetAsLocalizedDate(bool longDate=false, bool withShortNames=true) const;
185   CStdString GetAsLocalizedTime(const CStdString &format, bool withSeconds=true) const;
186   CStdString GetAsLocalizedDateTime(bool longDate=false, bool withSeconds=true) const;
187   CStdString GetAsRFC1123DateTime() const;
188
189   void SetValid(bool yesNo);
190   bool IsValid() const;
191
192 private:
193   bool ToFileTime(const SYSTEMTIME& time, FILETIME& fileTime) const;
194   bool ToFileTime(const time_t& time, FILETIME& fileTime) const;
195   bool ToFileTime(const tm& time, FILETIME& fileTime) const;
196
197   void ToULargeInt(ULARGE_INTEGER& time) const;
198   void FromULargeInt(const ULARGE_INTEGER& time);
199
200 private:
201   FILETIME m_time;
202
203   typedef enum _STATE
204   {
205     invalid=0,
206     valid
207   } STATE;
208
209   STATE m_state;
210 };