TTKMusicPlayer  4.3.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 - 2026 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 {
30 public:
34  TTKTime() noexcept;
35  TTKTime(qint64 value) noexcept;
36  TTKTime(int day, int hour, int min, int sec, int msec) noexcept;
37  TTKTime(const TTKTime &other) noexcept;
38  TTKTime(TTKTime &&other) noexcept;
39 
43  bool isNull() const noexcept;
47  bool isValid() const noexcept;
48 
52  inline void setDay(int day) noexcept { m_day = day; }
56  inline void setHour(int hour) noexcept { m_hour = hour; }
60  inline void setMinute(int min) noexcept { m_minute = min; }
64  inline void setSecond(int sec) noexcept { m_second = sec; }
68  inline void setMillionSecond(int msec) noexcept { m_msecond = msec; }
69 
73  inline int day() const noexcept { return m_day; }
77  inline int hour() const noexcept { return m_hour; }
81  inline int minute() const noexcept { return m_minute; }
85  inline int second() const noexcept { return m_second; }
89  inline int millionSecond() const noexcept { return m_msecond; }
90 
94  static TTKTime fromString(const QString &time, const QString &format) noexcept;
98  static QString toString(qint64 time, const QString &format) noexcept;
99 
103  QString toString(const QString &format) const noexcept;
104 // h the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
105 // hh the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
106 // H the hour without a leading zero (0 to 23, even with AM/PM display)
107 // HH the hour with a leading zero (00 to 23, even with AM/PM display)
108 // m the minute without a leading zero (0 to 59)
109 // mm the minute with a leading zero (00 to 59)
110 // s the second without a leading zero (0 to 59)
111 // ss the second with a leading zero (00 to 59)
112 // z the milliseconds without leading zeroes (0 to 999)
113 // zzz the milliseconds with leading zeroes (000 to 999)
114 // AP or A use AM/PM display. A/AP will be replaced by either "AM" or "PM".
115 // ap or a use am/pm display. a/ap will be replaced by either "am" or "pm".
116 // t the timezone (for example "CEST")
117 
121  void fromValue(int day, int hour, int min, int sec, int msec = 0) noexcept;
125  void fromValue(qint64 value) noexcept;
129  qint64 toValue() const noexcept;
130 
134  static qint64 formatDuration(const QString &time) noexcept;
138  static QString formatDuration(qint64 time) noexcept;
139 
140  TTKTime& operator = (const TTKTime &other) noexcept;
141  TTKTime& operator = (TTKTime &&other) noexcept;
142  TTKTime& operator+= (const TTKTime &other) noexcept;
143  TTKTime& operator+= (const int other) noexcept;
144  TTKTime& operator-= (const TTKTime &other) noexcept;
145  TTKTime& operator-= (const int other) noexcept;
146  TTKTime& operator*= (const int other) noexcept;
147  TTKTime& operator/= (const int other) noexcept;
148 
149  TTKTime operator+ (const TTKTime &other) noexcept;
150  TTKTime operator+ (const int other) noexcept;
151  TTKTime operator- (const TTKTime &other) noexcept;
152  TTKTime operator- (const int other) noexcept;
153  TTKTime operator* (const int other) noexcept;
154  TTKTime operator/ (const int other) noexcept;
155 
156  bool operator== (const TTKTime &other) const noexcept;
157  bool operator!= (const TTKTime &other) const noexcept;
158 
159  inline friend QDataStream& operator<<(QDataStream &stream, const TTKTime &other) noexcept
160  {
161  stream << other.day() << TTK_SPACE << other.hour() << TTK_SPACE << other.minute() << TTK_SPACE
162  << other.second() << TTK_SPACE << other.millionSecond();
163  return stream;
164  }
165 
166  inline friend QDataStream& operator>>(QDataStream &stream, TTKTime &other) noexcept
167  {
168  int x[5];
169  stream >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
170  other.fromValue(x[0], x[1], x[2], x[3], x[4]);
171  return stream;
172  }
173 
174 private:
178  void initialize() noexcept;
182  void makeCopy(const TTKTime &other) noexcept;
183 
184  int m_day, m_hour;
185  int m_minute, m_second, m_msecond;
186 
187 };
188 
189 
194 {
195 public:
199  static qint64 currentTimestamp() noexcept;
203  static QString format(const QString &time, const QString &format);
207  static QString format(qint64 time, const QString &format);
208 
209 };
210 
211 
215 namespace TTK
216 {
224  TTK_MODULE_EXPORT int random(int value = RAND_MAX);
225 
226 }
227 
228 #endif // TTKTIME_H
#define TTK_MODULE_EXPORT
int minute() const noexcept
Definition: ttktime.h:81
constexpr const _Tp & min(const _Tp &a, const _Tp &b) noexcept
Definition: ttkcompat.h:27
void setHour(int hour) noexcept
Definition: ttktime.h:56
bool isValid(const QString &data)
Definition: qdlna.cpp:76
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:52
void setSecond(int sec) noexcept
Definition: ttktime.h:64
TTK_MODULE_EXPORT void initRandom()
Definition: ttktime.cpp:7
std::shared_ptr< T > makeCopy(const T *&source)
Definition: ttksmartptr.h:221
int millionSecond() const noexcept
Definition: ttktime.h:89
TTK_MODULE_EXPORT int random(int value=RAND_MAX)
Definition: ttktime.cpp:14
int day() const noexcept
Definition: ttktime.h:73
The class of the ttk date time object.
Definition: ttktime.h:193
int hour() const noexcept
Definition: ttktime.h:77
The namespace of the application object.
Definition: ttkcompat.h:24
int second() const noexcept
Definition: ttktime.h:85
TTK_MODULE_EXPORT void initialize(TTK::Attribute attr)
void setMinute(int min) noexcept
Definition: ttktime.h:60
TTK_MODULE_EXPORT QString toString(Record type) noexcept
voidpf stream
Definition: ioapi.h:136
The class of the ttk time object.
Definition: ttktime.h:28
void setMillionSecond(int msec) noexcept
Definition: ttktime.h:68
#define const
Definition: zconf.h:233
friend QDataStream & operator>>(QDataStream &stream, TTKTime &other) noexcept
Definition: ttktime.h:166
#define TTK_SPACE
Definition: ttkglobal.h:268