File indexing completed on 2024-03-24 15:27:11

0001 /*
0002     Copyright 2010 John Layt <john@layt.net>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License as published by the Free Software Foundation; either
0007     version 2 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Library General Public License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to
0016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017     Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "kcalendarera_p.h"
0021 #include "kcalendarsystem.h"
0022 #include "kcalendarsystemprivate_p.h"
0023 
0024 #include <QDate>
0025 
0026 KCalendarEra::KCalendarEra()
0027 {
0028 }
0029 
0030 KCalendarEra::~KCalendarEra()
0031 {
0032 }
0033 
0034 bool KCalendarEra::isValid() const
0035 {
0036     return m_startDate.isValid() &&
0037            m_endDate.isValid() &&
0038            !m_longName.isEmpty() &&
0039            !m_shortName.isEmpty() &&
0040            !m_format.isEmpty();
0041 }
0042 
0043 QDate KCalendarEra::startDate() const
0044 {
0045     return m_startDate;
0046 }
0047 
0048 QDate KCalendarEra::endDate() const
0049 {
0050     return m_endDate;
0051 }
0052 
0053 QString KCalendarEra::name(KLocale::DateTimeComponentFormat format) const
0054 {
0055     if (format == KLocale::LongName) {
0056         return m_longName;
0057     } else {
0058         return m_shortName;
0059     }
0060 }
0061 
0062 QString KCalendarEra::format() const
0063 {
0064     return m_format;
0065 }
0066 
0067 int KCalendarEra::direction() const
0068 {
0069     return m_direction;
0070 }
0071 
0072 bool KCalendarEra::isInEra(const QDate &date) const
0073 {
0074     if (m_endDate < m_startDate) {
0075         return (date >= m_endDate && date <= m_startDate);
0076     } else {
0077         return (date >= m_startDate && date <= m_endDate);
0078     }
0079 }
0080 
0081 int KCalendarEra::yearInEra(int year) const
0082 {
0083     return ((year - m_startYear) * m_direction) + m_offset;
0084 }
0085 
0086 int KCalendarEra::year(int yearInEra) const
0087 {
0088     return ((yearInEra - m_offset) / m_direction) + m_startYear;
0089 }