KDELibs4Support

kcalendarera.cpp
1 /*
2  Copyright 2010 John Layt <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "kcalendarera_p.h"
21 #include "kcalendarsystem.h"
22 #include "kcalendarsystemprivate_p.h"
23 
24 #include <QDate>
25 
26 KCalendarEra::KCalendarEra()
27 {
28 }
29 
30 KCalendarEra::~KCalendarEra()
31 {
32 }
33 
34 bool KCalendarEra::isValid() const
35 {
36  return m_startDate.isValid() &&
37  m_endDate.isValid() &&
38  !m_longName.isEmpty() &&
39  !m_shortName.isEmpty() &&
40  !m_format.isEmpty();
41 }
42 
43 QDate KCalendarEra::startDate() const
44 {
45  return m_startDate;
46 }
47 
48 QDate KCalendarEra::endDate() const
49 {
50  return m_endDate;
51 }
52 
53 QString KCalendarEra::name(KLocale::DateTimeComponentFormat format) const
54 {
55  if (format == KLocale::LongName) {
56  return m_longName;
57  } else {
58  return m_shortName;
59  }
60 }
61 
62 QString KCalendarEra::format() const
63 {
64  return m_format;
65 }
66 
67 int KCalendarEra::direction() const
68 {
69  return m_direction;
70 }
71 
72 bool KCalendarEra::isInEra(const QDate &date) const
73 {
74  if (m_endDate < m_startDate) {
75  return (date >= m_endDate && date <= m_startDate);
76  } else {
77  return (date >= m_startDate && date <= m_endDate);
78  }
79 }
80 
81 int KCalendarEra::yearInEra(int year) const
82 {
83  return ((year - m_startYear) * m_direction) + m_offset;
84 }
85 
86 int KCalendarEra::year(int yearInEra) const
87 {
88  return ((yearInEra - m_offset) / m_direction) + m_startYear;
89 }
DateTimeComponentFormat
Definition: klocale.h:770
Long text format, e.g.
Definition: klocale.h:777
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 14 2020 22:58:19 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.