• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • date
kcalendarsystemthai.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2009, 2010 John Layt <john@layt.net>
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 "kdebug.h"
24 #include "klocale.h"
25 
26 #include <QtCore/QDate>
27 
28 //Reuse the Gregorian private implementation
29 class KCalendarSystemThaiPrivate : public KCalendarSystemGregorianPrivate
30 {
31 public:
32  explicit KCalendarSystemThaiPrivate(KCalendarSystemThai *q);
33  virtual ~KCalendarSystemThaiPrivate();
34 
35  virtual KLocale::CalendarSystem calendarSystem() const;
36  virtual void loadDefaultEraList();
37  virtual bool isLeapYear(int year) const;
38  virtual bool hasYearZero() const;
39  virtual int earliestValidYear() const;
40 };
41 
42 //Override only a few of the Gregorian private methods
43 
44 KCalendarSystemThaiPrivate::KCalendarSystemThaiPrivate(KCalendarSystemThai *q)
45  : KCalendarSystemGregorianPrivate(q)
46 {
47 }
48 
49 KCalendarSystemThaiPrivate::~KCalendarSystemThaiPrivate()
50 {
51 }
52 
53 KLocale::CalendarSystem KCalendarSystemThaiPrivate::calendarSystem() const
54 {
55  return KLocale::ThaiCalendar;
56 }
57 
58 void KCalendarSystemThaiPrivate::loadDefaultEraList()
59 {
60  QString name, shortName, format;
61 
62  name = i18nc("Calendar Era: Thai Buddhist Era, years > 0, LongFormat", "Buddhist Era");
63  shortName = i18nc("Calendar Era: Thai Buddhist Era, years > 0, ShortFormat", "BE");
64  format = i18nc("(kdedt-format) Thai, BE, full era year format used for %EY, e.g. 2000 BE", "%Ey %EC");
65  addEra('+', 1, q->epoch(), 1, q->latestValidDate(), name, shortName, format);
66 }
67 
68 bool KCalendarSystemThaiPrivate::isLeapYear(int year) const
69 {
70  return KCalendarSystemGregorianPrivate::isLeapYear(year - 543);
71 }
72 
73 bool KCalendarSystemThaiPrivate::hasYearZero() const
74 {
75  return true;
76 }
77 
78 int KCalendarSystemThaiPrivate::earliestValidYear() const
79 {
80  return 0;
81 }
82 
83 
84 KCalendarSystemThai::KCalendarSystemThai(const KLocale *locale)
85  : KCalendarSystemGregorian(*new KCalendarSystemThaiPrivate(this), KSharedConfig::Ptr(), locale)
86 {
87  d_ptr->loadConfig(calendarType());
88 }
89 
90 KCalendarSystemThai::KCalendarSystemThai(const KSharedConfig::Ptr config, const KLocale *locale)
91  : KCalendarSystemGregorian(*new KCalendarSystemThaiPrivate(this), config, locale)
92 {
93  d_ptr->loadConfig(calendarType());
94 }
95 
96 KCalendarSystemThai::KCalendarSystemThai(KCalendarSystemThaiPrivate &dd,
97  const KSharedConfig::Ptr config, const KLocale *locale)
98  : KCalendarSystemGregorian(dd, config, locale)
99 {
100  d_ptr->loadConfig(calendarType());
101 }
102 
103 KCalendarSystemThai::~KCalendarSystemThai()
104 {
105 }
106 
107 QString KCalendarSystemThai::calendarType() const
108 {
109  return QLatin1String("thai");
110 }
111 
112 QDate KCalendarSystemThai::epoch() const
113 {
114  // 0000-01-01 = 0544-01-01 BC Gregorian = 0544-01-07 BC Julian
115  return QDate::fromJulianDay(1522734);
116 }
117 
118 QDate KCalendarSystemThai::earliestValidDate() const
119 {
120  return epoch();
121 }
122 
123 QDate KCalendarSystemThai::latestValidDate() const
124 {
125  // Set to last day of year 9999 until confirm date formats & widgets support > 9999
126  // 9999-12-31 = 9456-12-31 AD Gregorian
127  return QDate::fromJulianDay(5175158);
128 }
129 
130 bool KCalendarSystemThai::isValid(int year, int month, int day) const
131 {
132  return KCalendarSystemGregorian::isValid(year, month, day);
133 }
134 
135 bool KCalendarSystemThai::isValid(const QDate &date) const
136 {
137  return KCalendarSystemGregorian::isValid(date);
138 }
139 
140 bool KCalendarSystemThai::isLeapYear(int year) const
141 {
142  return KCalendarSystemGregorian::isLeapYear(year);
143 }
144 
145 bool KCalendarSystemThai::isLeapYear(const QDate &date) const
146 {
147  return KCalendarSystemGregorian::isLeapYear(date);
148 }
149 
150 int KCalendarSystemThai::weekDayOfPray() const
151 {
152  return 7; // TODO JPL ???
153 }
154 
155 bool KCalendarSystemThai::isLunar() const
156 {
157  return KCalendarSystemGregorian::isLunar();
158 }
159 
160 bool KCalendarSystemThai::isLunisolar() const
161 {
162  return KCalendarSystemGregorian::isLunisolar();
163 }
164 
165 bool KCalendarSystemThai::isSolar() const
166 {
167  return KCalendarSystemGregorian::isSolar();
168 }
169 
170 bool KCalendarSystemThai::isProleptic() const
171 {
172  return false;
173 }
174 
175 bool KCalendarSystemThai::julianDayToDate(int jd, int &year, int &month, int &day) const
176 {
177  bool result = KCalendarSystemGregorian::julianDayToDate(jd, year, month, day);
178  year = year + 543;
179  return result;
180 }
181 
182 bool KCalendarSystemThai::dateToJulianDay(int year, int month, int day, int &jd) const
183 {
184  return KCalendarSystemGregorian::dateToJulianDay(year - 543, month, day, jd);
185 }
186 
KSharedPtr< KSharedConfig >
KCalendarSystemThai::isValid
virtual bool isValid(int year, int month, int day) const
Returns whether a given date is valid in this calendar system.
Definition: kcalendarsystemthai.cpp:130
KCalendarSystemThai::latestValidDate
virtual QDate latestValidDate() const
Returns the latest date valid in this calendar system implementation.
Definition: kcalendarsystemthai.cpp:123
KSharedConfig
KConfig variant using shared memory.
Definition: ksharedconfig.h:40
kdebug.h
KCalendarSystemThai
Definition: kcalendarsystemthai_p.h:38
KCalendarSystemGregorianPrivate::isLeapYear
virtual bool isLeapYear(int year) const
Definition: kcalendarsystemgregorian.cpp:117
KCalendarSystemThai::dateToJulianDay
virtual bool dateToJulianDay(int year, int month, int day, int &jd) const
Internal method to convert YMD values for this calendar system into a Julian Day number.
Definition: kcalendarsystemthai.cpp:182
KCalendarSystemThai::weekDayOfPray
virtual int weekDayOfPray() const
Definition: kcalendarsystemthai.cpp:150
KCalendarSystemGregorian::isLunar
virtual bool isLunar() const
Returns whether the calendar is lunar based.
Definition: kcalendarsystemgregorian.cpp:486
klocale.h
KCalendarSystemGregorian::julianDayToDate
virtual bool julianDayToDate(int jd, int &year, int &month, int &day) const
Internal method to convert a Julian Day number into the YMD values for this calendar system...
Definition: kcalendarsystemgregorian.cpp:506
KCalendarSystemGregorian::isLeapYear
virtual bool isLeapYear(int year) const
Returns whether a given year is a leap year.
Definition: kcalendarsystemgregorian.cpp:446
i18nc
QString i18nc(const char *ctxt, const char *text)
Returns a localized version of a string and a context.
Definition: klocalizedstring.h:797
KCalendarSystemGregorianPrivate::loadDefaultEraList
virtual void loadDefaultEraList()
Definition: kcalendarsystemgregorian.cpp:52
KGlobal::config
KSharedConfigPtr config()
Returns the general config object.
Definition: kglobal.cpp:139
KCalendarSystemThai::isLeapYear
virtual bool isLeapYear(int year) const
Returns whether a given year is a leap year.
Definition: kcalendarsystemthai.cpp:140
KCalendarSystemGregorianPrivate::calendarSystem
virtual KLocale::CalendarSystem calendarSystem() const
Definition: kcalendarsystemgregorian.cpp:45
KCalendarSystemThai::earliestValidDate
virtual QDate earliestValidDate() const
Returns the earliest date valid in this calendar system implementation.
Definition: kcalendarsystemthai.cpp:118
KLocale::CalendarSystem
CalendarSystem
Definition: klocale.h:780
KCalendarSystemThai::calendarType
virtual QString calendarType() const
Definition: kcalendarsystemthai.cpp:107
KCalendarSystemThai::KCalendarSystemThai
KCalendarSystemThai(const KLocale *locale=0)
Definition: kcalendarsystemthai.cpp:84
KCalendarSystemThai::epoch
virtual QDate epoch() const
Returns a QDate holding the epoch of the calendar system.
Definition: kcalendarsystemthai.cpp:112
KCalendarSystemThai::isProleptic
virtual bool isProleptic() const
Returns whether the calendar system is proleptic, i.e.
Definition: kcalendarsystemthai.cpp:170
QDate
KCalendarSystemGregorianPrivate::hasYearZero
virtual bool hasYearZero() const
Definition: kcalendarsystemgregorian.cpp:139
QString
KCalendarSystemGregorianPrivate::earliestValidYear
virtual int earliestValidYear() const
Definition: kcalendarsystemgregorian.cpp:154
KCalendarSystemGregorian
Definition: kcalendarsystemgregorian_p.h:42
kcalendarsystemgregorianprivate_p.h
KGlobal::locale
KLocale * locale()
Returns the global locale object.
Definition: kglobal.cpp:170
KCalendarSystemThai::isSolar
virtual bool isSolar() const
Returns whether the calendar is solar based.
Definition: kcalendarsystemthai.cpp:165
KCalendarSystemGregorianPrivate
Definition: kcalendarsystemgregorianprivate_p.h:27
KLocale
KLocale provides support for country specific stuff like the national language.
Definition: klocale.h:69
QLatin1String
KCalendarSystemGregorian::dateToJulianDay
virtual bool dateToJulianDay(int year, int month, int day, int &jd) const
Internal method to convert YMD values for this calendar system into a Julian Day number.
Definition: kcalendarsystemgregorian.cpp:534
kcalendarsystemthai_p.h
KCalendarSystemGregorian::isLunisolar
virtual bool isLunisolar() const
Returns whether the calendar is lunisolar based.
Definition: kcalendarsystemgregorian.cpp:491
KCalendarSystemThai::~KCalendarSystemThai
virtual ~KCalendarSystemThai()
Definition: kcalendarsystemthai.cpp:103
KCalendarSystemGregorian::isSolar
virtual bool isSolar() const
Returns whether the calendar is solar based.
Definition: kcalendarsystemgregorian.cpp:496
KCalendarSystemThai::isLunar
virtual bool isLunar() const
Returns whether the calendar is lunar based.
Definition: kcalendarsystemthai.cpp:155
KCalendarSystemThai::julianDayToDate
virtual bool julianDayToDate(int jd, int &year, int &month, int &day) const
Internal method to convert a Julian Day number into the YMD values for this calendar system...
Definition: kcalendarsystemthai.cpp:175
QDate::fromJulianDay
QDate fromJulianDay(int jd)
KCalendarSystemThai::isLunisolar
virtual bool isLunisolar() const
Returns whether the calendar is lunisolar based.
Definition: kcalendarsystemthai.cpp:160
KLocale::ThaiCalendar
Thai Calendar, aka Buddhist or Thai Buddhist.
Definition: klocale.h:803
KCalendarSystemGregorian::isValid
virtual bool isValid(int year, int month, int day) const
Returns whether a given date is valid in this calendar system.
Definition: kcalendarsystemgregorian.cpp:436
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal