TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
ttktime.h
Go to the documentation of this file.
1 #ifndef TTKTIME_H
2 #define TTKTIME_H
3 
4 /***************************************************************************
5  * This file is part of the TTK Library Module project
6  * Copyright (C) 2015 - 2024 Greedysky Studio
7 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17 
18  * You should have received a copy of the GNU Lesser General Public License along
19  * with this program; If not, see <http://www.gnu.org/licenses/>.
20  ***************************************************************************/
21 
22 #include <QDataStream>
23 #include "ttkmoduleexport.h"
24 
29 {
31 public:
35  TTKTime() noexcept;
36  TTKTime(qint64 value) noexcept;
37  TTKTime(int day, int hour, int min, int sec, int msec) noexcept;
38  TTKTime(const TTKTime &other) noexcept;
39  TTKTime(TTKTime &&other) noexcept;
40 
44  bool isNull() const noexcept;
48  bool isValid() const noexcept;
49 
53  inline void setDay(int day) noexcept { m_day = day; }
57  inline void setHour(int hour) noexcept { m_hour = hour; }
61  inline void setMinute(int min) noexcept { m_minute = min; }
65  inline void setSecond(int sec) noexcept { m_second = sec; }
69  inline void setMillionSecond(int msec) noexcept { m_msecond = msec; }
70 
74  inline int day() const noexcept { return m_day; }
78  inline int hour() const noexcept { return m_hour; }
82  inline int minute() const noexcept { return m_minute; }
86  inline int second() const noexcept { return m_second; }
90  inline int millionSecond() const noexcept { return m_msecond; }
91 
95  static TTKTime fromString(const QString &time, const QString &format) noexcept;
99  static QString toString(qint64 time, const QString &format) noexcept;
100 
104  QString toString(const QString &format) const noexcept;
105 // h the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
106 // hh the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
107 // H the hour without a leading zero (0 to 23, even with AM/PM display)
108 // HH the hour with a leading zero (00 to 23, even with AM/PM display)
109 // m the minute without a leading zero (0 to 59)
110 // mm the minute with a leading zero (00 to 59)
111 // s the second without a leading zero (0 to 59)
112 // ss the second with a leading zero (00 to 59)
113 // z the milliseconds without leading zeroes (0 to 999)
114 // zzz the milliseconds with leading zeroes (000 to 999)
115 // AP or A use AM/PM display. A/AP will be replaced by either "AM" or "PM".
116 // ap or a use am/pm display. a/ap will be replaced by either "am" or "pm".
117 // t the timezone (for example "CEST")
118 
122  void fromValue(int day, int hour, int min, int sec, int msec = 0) noexcept;
126  void fromValue(qint64 value) noexcept;
130  qint64 toValue() const noexcept;
131 
135  static qint64 formatDuration(const QString &time) noexcept;
139  static QString formatDuration(qint64 time/*, bool greedy = true*/) noexcept;
140 
141  TTKTime& operator = (const TTKTime &other) noexcept;
142  TTKTime& operator = (TTKTime &&other) noexcept;
143  TTKTime& operator+= (const TTKTime &other) noexcept;
144  TTKTime& operator+= (const int other) noexcept;
145  TTKTime& operator-= (const TTKTime &other) noexcept;
146  TTKTime& operator-= (const int other) noexcept;
147  TTKTime& operator*= (const int other) noexcept;
148  TTKTime& operator/= (const int other) noexcept;
149 
150  TTKTime operator+ (const TTKTime &other) noexcept;
151  TTKTime operator+ (const int other) noexcept;
152  TTKTime operator- (const TTKTime &other) noexcept;
153  TTKTime operator- (const int other) noexcept;
154  TTKTime operator* (const int other) noexcept;
155  TTKTime operator/ (const int other) noexcept;
156 
157  bool operator== (const TTKTime &other) const noexcept;
158  bool operator!= (const TTKTime &other) const noexcept;
159 
160  inline friend QDataStream& operator<<(QDataStream &stream, const TTKTime &other) noexcept
161  {
162  stream << other.day() << " " << other.hour() << " " << other.minute() << " "
163  << other.second() << " " << other.millionSecond();
164  return stream;
165  }
166 
167  inline friend QDataStream& operator>>(QDataStream &stream, TTKTime &other) noexcept
168  {
169  int x[5];
170  stream >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
171  other.fromValue(x[0], x[1], x[2], x[3], x[4]);
172  return stream;
173  }
174 
175 private:
179  void initialize() noexcept;
183  void copyToThis(const TTKTime &other) noexcept;
184 
185  int m_day, m_hour;
186  int m_minute, m_second, m_msecond;
187 
188 };
189 
190 
195 {
196 public:
200  static qint64 currentTimestamp();
204  static QString format(const QString &time, const QString &format);
208  static QString format(qint64 time, const QString &format);
209 
210 };
211 
212 
216 namespace TTK
217 {
225  TTK_MODULE_EXPORT int random(int value = RAND_MAX);
226 
227 }
228 
229 #endif // TTKTIME_H
#define TTK_MODULE_EXPORT
int minute() const noexcept
Definition: ttktime.h:82
void setHour(int hour) noexcept
Definition: ttktime.h:57
void fromValue(int day, int hour, int min, int sec, int msec=0) noexcept
Definition: ttktime.cpp:82
void setDay(int day) noexcept
Definition: ttktime.h:53
void setSecond(int sec) noexcept
Definition: ttktime.h:65
TTK_MODULE_EXPORT void initRandom()
Definition: ttktime.cpp:7
int millionSecond() const noexcept
Definition: ttktime.h:90
TTK_MODULE_EXPORT int random(int value=RAND_MAX)
Definition: ttktime.cpp:14
int day() const noexcept
Definition: ttktime.h:74
The class of the ttk date time object.
Definition: ttktime.h:194
int hour() const noexcept
Definition: ttktime.h:78
The namespace of the process utils.
Definition: ttkcompat.h:24
int second() const noexcept
Definition: ttktime.h:86
#define TTK_DECLARE_MODULE(Class)
Definition: ttkqtglobal.h:152
void setMinute(int min) noexcept
Definition: ttktime.h:61
voidpf stream
Definition: ioapi.h:136
The class of the ttk time object.
Definition: ttktime.h:28
TTK_MODULE_EXPORT QString toString(Record type)
void setMillionSecond(int msec) noexcept
Definition: ttktime.h:69
#define const
Definition: zconf.h:233
constexpr const _Tp & min(const _Tp &a, const _Tp &b)
Definition: ttkcompat.h:27
friend QDataStream & operator>>(QDataStream &stream, TTKTime &other) noexcept
Definition: ttktime.h:167