KDELibs4Support

kcalendarsystemthai.cpp
1 /*
2  Copyright 2009, 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 "kcalendarsystemthai_p.h"
21 #include "kcalendarsystemgregorianprivate_p.h"
22 
23 #include "klocale.h"
24 #include "klocalizedstring.h"
25 
26 #include <QDate>
27 
28 //Reuse the Gregorian private implementation
29 class KCalendarSystemThaiPrivate : public KCalendarSystemGregorianPrivate
30 {
31 public:
32  KDELIBS4SUPPORT_DEPRECATED explicit KCalendarSystemThaiPrivate(KCalendarSystemThai *q);
33  virtual ~KCalendarSystemThaiPrivate();
34 
35  void loadDefaultEraList() override;
36  int daysInMonth(int year, int month) const override;
37  int daysInYear(int year) const override;
38  bool isLeapYear(int year) const override;
39  bool hasYearZero() const override;
40  int earliestValidYear() const override;
41 };
42 
43 //Override only a few of the Gregorian private methods
44 
45 KCalendarSystemThaiPrivate::KCalendarSystemThaiPrivate(KCalendarSystemThai *q)
46  : KCalendarSystemGregorianPrivate(q)
47 {
48 }
49 
50 KCalendarSystemThaiPrivate::~KCalendarSystemThaiPrivate()
51 {
52 }
53 
54 void KCalendarSystemThaiPrivate::loadDefaultEraList()
55 {
56  QString name, shortName, format;
57 
58  name = i18nc("Calendar Era: Thai Buddhist Era, years > 0, LongFormat", "Buddhist Era");
59  shortName = i18nc("Calendar Era: Thai Buddhist Era, years > 0, ShortFormat", "BE");
60  format = i18nc("(kdedt-format) Thai, BE, full era year format used for %EY, e.g. 2000 BE", "%Ey %EC");
61  addEra('+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format);
62 }
63 
64 int KCalendarSystemThaiPrivate::daysInMonth(int year, int month) const
65 {
66  return KCalendarSystemGregorianPrivate::daysInMonth(year - 543, month);
67 }
68 
69 int KCalendarSystemThaiPrivate::daysInYear(int year) const
70 {
71  return KCalendarSystemGregorianPrivate::daysInYear(year - 543);
72 }
73 
74 bool KCalendarSystemThaiPrivate::isLeapYear(int year) const
75 {
76  return KCalendarSystemGregorianPrivate::isLeapYear(year - 543);
77 }
78 
79 bool KCalendarSystemThaiPrivate::hasYearZero() const
80 {
81  return true;
82 }
83 
84 int KCalendarSystemThaiPrivate::earliestValidYear() const
85 {
86  return 0;
87 }
88 
89 KCalendarSystemThai::KCalendarSystemThai(const KSharedConfig::Ptr config, const KLocale *locale)
90  : KCalendarSystemGregorian(*new KCalendarSystemThaiPrivate(this), config, locale)
91 {
92  d_ptr->loadConfig(calendarType());
93 }
94 
95 KCalendarSystemThai::KCalendarSystemThai(KCalendarSystemThaiPrivate &dd,
96  const KSharedConfig::Ptr config, const KLocale *locale)
97  : KCalendarSystemGregorian(dd, config, locale)
98 {
99  d_ptr->loadConfig(calendarType());
100 }
101 
102 KCalendarSystemThai::~KCalendarSystemThai()
103 {
104 }
105 
106 QString KCalendarSystemThai::calendarType() const
107 {
108  return QLatin1String("thai");
109 }
110 
111 KLocale::CalendarSystem KCalendarSystemThai::calendarSystem() const
112 {
113  return KLocale::ThaiCalendar;
114 }
115 
116 QDate KCalendarSystemThai::epoch() const
117 {
118  // 0000-01-01 = 0544-01-01 BC Gregorian = 0544-01-07 BC Julian
119  return QDate::fromJulianDay(1522734);
120 }
121 
122 QDate KCalendarSystemThai::earliestValidDate() const
123 {
124  return epoch();
125 }
126 
127 QDate KCalendarSystemThai::latestValidDate() const
128 {
129  // Set to last day of year 9999 until confirm date formats & widgets support > 9999
130  // 9999-12-31 = 9456-12-31 AD Gregorian
131  return QDate::fromJulianDay(5175158);
132 }
133 
134 bool KCalendarSystemThai::isLunar() const
135 {
136  return KCalendarSystemGregorian::isLunar();
137 }
138 
139 bool KCalendarSystemThai::isLunisolar() const
140 {
141  return KCalendarSystemGregorian::isLunisolar();
142 }
143 
144 bool KCalendarSystemThai::isSolar() const
145 {
146  return KCalendarSystemGregorian::isSolar();
147 }
148 
149 bool KCalendarSystemThai::isProleptic() const
150 {
151  return false;
152 }
153 
154 bool KCalendarSystemThai::julianDayToDate(qint64 jd, int &year, int &month, int &day) const
155 {
156  bool result = KCalendarSystemGregorian::julianDayToDate(jd, year, month, day);
157  year = year + 543;
158  return result;
159 }
160 
161 bool KCalendarSystemThai::dateToJulianDay(int year, int month, int day, qint64 &jd) const
162 {
163  return KCalendarSystemGregorian::dateToJulianDay(year - 543, month, day, jd);
164 }
165 
QString name(const QVariant &location)
virtual int day(const QDate &date) const
Returns the day portion of a given date in the current calendar system.
virtual QDate epoch() const =0
Returns a QDate holding the epoch of the calendar system.
CalendarSystem
Definition: klocale.h:646
QString i18nc(const char *context, const char *text, const TYPE &arg...)
virtual int month(const QDate &date) const
Returns the month portion of a given date in the current calendar system.
const KLocale * locale() const
Returns the locale used for translations and formats for this calendar system instance.
virtual int year(const QDate &date) const
Returns the year portion of a given date in the current calendar system.
KLocale provides support for language and country specific stuff.
Definition: klocale.h:75
QDate fromJulianDay(qint64 jd)
virtual QString calendarType() const =0
Thai Calendar, aka Buddhist or Thai Buddhist.
Definition: klocale.h:668
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:56:37 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.