22 #include <QtCore/QSharedData>
23 #include <QtCore/QString>
24 #include <QtCore/QTime>
29 KDayPeriodPrivate(
const QString &periodCode,
33 const QTime &periodStart,
34 const QTime &periodEnd,
37 KDayPeriodPrivate(
const KDayPeriodPrivate &other);
40 QString m_periodCode, m_longName, m_shortName, m_narrowName;
41 QTime m_periodStart, m_periodEnd;
42 int m_offsetFromStart, m_offsetIfZero;
45 KDayPeriodPrivate::KDayPeriodPrivate(
const QString &periodCode,
49 const QTime &periodStart,
50 const QTime &periodEnd,
54 m_periodCode(periodCode),
56 m_shortName(shortName),
57 m_narrowName(narrowName),
58 m_periodStart(periodStart),
59 m_periodEnd(periodEnd),
60 m_offsetFromStart(offsetFromStart),
61 m_offsetIfZero(offsetIfZero)
65 KDayPeriodPrivate::KDayPeriodPrivate(
const KDayPeriodPrivate &other)
67 m_periodCode(other.m_periodCode),
68 m_longName(other.m_longName),
69 m_shortName(other.m_shortName),
70 m_narrowName(other.m_narrowName),
71 m_periodStart(other.m_periodStart),
72 m_periodEnd(other.m_periodEnd),
73 m_offsetFromStart(other.m_offsetFromStart),
74 m_offsetIfZero(other.m_offsetIfZero)
78 KDayPeriodPrivate::~KDayPeriodPrivate()
86 const QTime &periodStart,
87 const QTime &periodEnd,
90 : d(new KDayPeriodPrivate(periodCode,
125 return d->m_periodCode;
130 return d->m_periodStart;
135 return d->m_periodEnd;
141 return d->m_longName;
143 return d->m_narrowName;
145 return d->m_shortName;
152 if (time.isValid() &&
isValid(time)) {
153 hourInPeriod = time.hour() -
periodStart().hour() + d->m_offsetFromStart;
154 while (d->m_offsetIfZero > 0 && hourInPeriod <= 0) {
155 hourInPeriod = hourInPeriod + d->m_offsetIfZero;
165 if (hip == d->m_offsetIfZero) {
172 hour = hip +
periodStart().hour() - d->m_offsetFromStart;
176 time = QTime(hour, minute, second, millisecond);
177 if (time.isValid() &&
isValid(time)) {
188 return !d->m_periodCode.isEmpty() &&
189 d->m_periodStart.isValid() &&
190 d->m_periodEnd.isValid();
199 return ((time >=
periodStart() && time <= QTime(23, 59, 59, 999)) ||
200 (time >= QTime(0, 0, 0) && time <=
periodEnd()));
QString periodName(KLocale::DateTimeComponentFormat format=KLocale::ShortName) const
Return translated Period Name in the required format e.g.
Narrow text format, may not be unique, e.g.
KDayPeriod & operator=(const KDayPeriod &rhs)
Assignment operator.
QTime periodStart() const
Return the time the Period starts at.
QTime time(int hourInPeriod, int minute, int second, int millisecond=0) const
Calculate and return the 24hr time for a given hms in the Day Period.
int hourInPeriod(const QTime &time) const
Calculate and return the hour in the Day Period for a given 24h time.
virtual ~KDayPeriod()
Destructor.
KDayPeriod()
Constructs a null KDayPeriod.
QTime periodEnd() const
Return the time the Period ends at.
QString periodCode() const
Return the Period Code.
bool isValid() const
Return if the Day Period is valid.