Debian Codegraph @

src/DateTime.h

raw
1 /*
2 * Copyright (C) 2005-2021 Team Kodi (https://kodi.tv)
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 * See LICENSE.md for more information.
6 */
7
8 #pragma once
9
10 #include <ctime>
11 #include <string>
12
13 namespace MPTV
14 {
15
16 const time_t cUndefinedDate = 946681200; ///> 01-01-2000 00:00:00 in time_t
17
18 class CDateTime
19 {
20 public:
21 CDateTime();
22 CDateTime(const struct tm& time);
23 CDateTime(const time_t& time);
24 virtual ~CDateTime();
25
26 int GetDay() const;
27 int GetMonth() const;
28 int GetYear() const;
29 int GetHour() const;
30 int GetMinute() const;
31 int GetSecond() const;
32 int GetDayOfWeek() const;
33 int GetMinuteOfDay() const;
34
35 time_t GetAsTime(void) const;
36
37 /**
38 * @brief Converts the stored datetime value to a string with the date representation for current locale
39 * @param strDate the date string (return value)
40 */
41 void GetAsLocalizedDate(std::string& strDate) const;
42
43 /**
44 * @brief Converts the stored datetime value to a string with the time representation for current locale
45 * @param strDate the date string (return value)
46 */
47 void GetAsLocalizedTime(std::string& strTime) const;
48
49 /**
50 * @brief Sets the date and time from a C# DateTime string
51 * Assumes the usage of somedatetimeval.ToString("u") in C#
52 */
53 bool SetFromDateTime(const std::string& dateTime);
54
55 /**
56 * @brief Sets the date and time from a time_t value
57 */
58 void SetFromTime(const time_t& time);
59 void SetFromTM(const struct tm& time);
60
61 int operator -(const CDateTime& right) const;
62 const CDateTime& operator =(const time_t& right);
63 const CDateTime& operator =(const tm& right);
64 bool operator ==(const time_t& right) const;
65 const CDateTime& operator +=(const int seconds);
66
67 static time_t Now();
68 private:
69 void InitLocale(void);
70
71 struct tm m_time;
72 };
73
74 } // namespace MPTV