[ExecString] combine SplitParameters with identical function of CUtil
[xbmc.git] / xbmc / XBDateTime.h
blob8331593ce85bc479b650b0498ed897919b6923d6
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "utils/IArchivable.h"
12 #include "utils/TimeFormat.h"
13 #include "utils/XTimeUtils.h"
15 #include <string>
17 #include "PlatformDefs.h"
19 class CDateTime;
21 class CDateTimeSpan
23 public:
24 CDateTimeSpan();
25 CDateTimeSpan(const CDateTimeSpan& span);
26 CDateTimeSpan& operator=(const CDateTimeSpan&) = default;
27 CDateTimeSpan(int day, int hour, int minute, int second);
29 bool operator >(const CDateTimeSpan& right) const;
30 bool operator >=(const CDateTimeSpan& right) const;
31 bool operator <(const CDateTimeSpan& right) const;
32 bool operator <=(const CDateTimeSpan& right) const;
33 bool operator ==(const CDateTimeSpan& right) const;
34 bool operator !=(const CDateTimeSpan& right) const;
36 CDateTimeSpan operator +(const CDateTimeSpan& right) const;
37 CDateTimeSpan operator -(const CDateTimeSpan& right) const;
39 const CDateTimeSpan& operator +=(const CDateTimeSpan& right);
40 const CDateTimeSpan& operator -=(const CDateTimeSpan& right);
42 void SetDateTimeSpan(int day, int hour, int minute, int second);
43 void SetFromPeriod(const std::string &period);
44 void SetFromTimeString(const std::string& time);
46 int GetDays() const;
47 int GetHours() const;
48 int GetMinutes() const;
49 int GetSeconds() const;
50 int GetSecondsTotal() const;
52 private:
53 void ToLargeInt(LARGE_INTEGER& time) const;
54 void FromLargeInt(const LARGE_INTEGER& time);
56 private:
57 KODI::TIME::FileTime m_timeSpan;
59 friend class CDateTime;
62 /// \brief DateTime class, which uses FileTime as it's base.
63 class CDateTime final : public IArchivable
65 public:
66 CDateTime();
67 CDateTime(const CDateTime& time);
68 CDateTime& operator=(const CDateTime&) = default;
69 explicit CDateTime(const KODI::TIME::SystemTime& time);
70 explicit CDateTime(const KODI::TIME::FileTime& time);
71 explicit CDateTime(const time_t& time);
72 explicit CDateTime(const tm& time);
73 CDateTime(int year, int month, int day, int hour, int minute, int second);
75 static CDateTime GetCurrentDateTime();
76 static CDateTime GetUTCDateTime();
77 static int MonthStringToMonthNum(const std::string& month);
79 static CDateTime FromDBDateTime(const std::string &dateTime);
80 static CDateTime FromDateString(const std::string &date);
81 static CDateTime FromDBDate(const std::string &date);
82 static CDateTime FromDBTime(const std::string &time);
83 static CDateTime FromW3CDate(const std::string &date);
84 static CDateTime FromW3CDateTime(const std::string &date, bool ignoreTimezone = false);
85 static CDateTime FromUTCDateTime(const CDateTime &dateTime);
86 static CDateTime FromUTCDateTime(const time_t &dateTime);
87 static CDateTime FromRFC1123DateTime(const std::string &dateTime);
89 const CDateTime& operator=(const KODI::TIME::SystemTime& right);
90 const CDateTime& operator=(const KODI::TIME::FileTime& right);
91 const CDateTime& operator =(const time_t& right);
92 const CDateTime& operator =(const tm& right);
94 bool operator >(const CDateTime& right) const;
95 bool operator >=(const CDateTime& right) const;
96 bool operator <(const CDateTime& right) const;
97 bool operator <=(const CDateTime& right) const;
98 bool operator ==(const CDateTime& right) const;
99 bool operator !=(const CDateTime& right) const;
101 bool operator>(const KODI::TIME::FileTime& right) const;
102 bool operator>=(const KODI::TIME::FileTime& right) const;
103 bool operator<(const KODI::TIME::FileTime& right) const;
104 bool operator<=(const KODI::TIME::FileTime& right) const;
105 bool operator==(const KODI::TIME::FileTime& right) const;
106 bool operator!=(const KODI::TIME::FileTime& right) const;
108 bool operator>(const KODI::TIME::SystemTime& right) const;
109 bool operator>=(const KODI::TIME::SystemTime& right) const;
110 bool operator<(const KODI::TIME::SystemTime& right) const;
111 bool operator<=(const KODI::TIME::SystemTime& right) const;
112 bool operator==(const KODI::TIME::SystemTime& right) const;
113 bool operator!=(const KODI::TIME::SystemTime& right) const;
115 bool operator >(const time_t& right) const;
116 bool operator >=(const time_t& right) const;
117 bool operator <(const time_t& right) const;
118 bool operator <=(const time_t& right) const;
119 bool operator ==(const time_t& right) const;
120 bool operator !=(const time_t& right) const;
122 bool operator >(const tm& right) const;
123 bool operator >=(const tm& right) const;
124 bool operator <(const tm& right) const;
125 bool operator <=(const tm& right) const;
126 bool operator ==(const tm& right) const;
127 bool operator !=(const tm& right) const;
129 CDateTime operator +(const CDateTimeSpan& right) const;
130 CDateTime operator -(const CDateTimeSpan& right) const;
132 const CDateTime& operator +=(const CDateTimeSpan& right);
133 const CDateTime& operator -=(const CDateTimeSpan& right);
135 CDateTimeSpan operator -(const CDateTime& right) const;
137 operator KODI::TIME::FileTime() const;
139 void Archive(CArchive& ar) override;
141 void Reset();
143 int GetDay() const;
144 int GetMonth() const;
145 int GetYear() const;
146 int GetHour() const;
147 int GetMinute() const;
148 int GetSecond() const;
149 int GetDayOfWeek() const;
150 int GetMinuteOfDay() const;
152 bool SetDateTime(int year, int month, int day, int hour, int minute, int second);
153 bool SetDate(int year, int month, int day);
154 bool SetTime(int hour, int minute, int second);
156 bool SetFromDateString(const std::string &date);
157 bool SetFromDBDate(const std::string &date);
158 bool SetFromDBTime(const std::string &time);
159 bool SetFromW3CDate(const std::string &date);
160 bool SetFromW3CDateTime(const std::string &date, bool ignoreTimezone = false);
161 bool SetFromUTCDateTime(const CDateTime &dateTime);
162 bool SetFromUTCDateTime(const time_t &dateTime);
163 bool SetFromRFC1123DateTime(const std::string &dateTime);
165 /*! \brief set from a database datetime format YYYY-MM-DD HH:MM:SS
166 \sa GetAsDBDateTime()
168 bool SetFromDBDateTime(const std::string &dateTime);
170 void GetAsSystemTime(KODI::TIME::SystemTime& time) const;
171 void GetAsTime(time_t& time) const;
172 void GetAsTm(tm& time) const;
173 void GetAsTimeStamp(KODI::TIME::FileTime& time) const;
175 enum class ReturnFormat : bool
177 CHOICE_YES = true,
178 CHOICE_NO = false,
181 CDateTime GetAsUTCDateTime() const;
182 std::string GetAsSaveString() const;
183 std::string GetAsDBDateTime() const;
184 std::string GetAsDBDate() const;
185 std::string GetAsDBTime() const;
186 std::string GetAsLocalizedDate(bool longDate=false) const;
187 std::string GetAsLocalizedDate(const std::string &strFormat) const;
188 std::string GetAsLocalizedDate(const std::string& strFormat, ReturnFormat returnFormat) const;
189 std::string GetAsLocalizedTime(const std::string &format, bool withSeconds=true) const;
190 std::string GetAsLocalizedDateTime(bool longDate=false, bool withSeconds=true) const;
191 std::string GetAsLocalizedTime(TIME_FORMAT format, bool withSeconds = false) const;
192 std::string GetAsRFC1123DateTime() const;
193 std::string GetAsW3CDate() const;
194 std::string GetAsW3CDateTime(bool asUtc = false) const;
196 void SetValid(bool yesNo);
197 bool IsValid() const;
199 static void ResetTimezoneBias(void);
200 static CDateTimeSpan GetTimezoneBias(void);
202 private:
203 bool ToFileTime(const KODI::TIME::SystemTime& time, KODI::TIME::FileTime& fileTime) const;
204 bool ToFileTime(const time_t& time, KODI::TIME::FileTime& fileTime) const;
205 bool ToFileTime(const tm& time, KODI::TIME::FileTime& fileTime) const;
207 void ToLargeInt(LARGE_INTEGER& time) const;
208 void FromLargeInt(const LARGE_INTEGER& time);
210 private:
211 KODI::TIME::FileTime m_time;
213 typedef enum _STATE
215 invalid=0,
216 valid
217 } STATE;
219 STATE m_state;