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

KDECore

  • 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
29class KCalendarSystemThaiPrivate : public KCalendarSystemGregorianPrivate
30{
31public:
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
44KCalendarSystemThaiPrivate::KCalendarSystemThaiPrivate(KCalendarSystemThai *q)
45 : KCalendarSystemGregorianPrivate(q)
46{
47}
48
49KCalendarSystemThaiPrivate::~KCalendarSystemThaiPrivate()
50{
51}
52
53KLocale::CalendarSystem KCalendarSystemThaiPrivate::calendarSystem() const
54{
55 return KLocale::ThaiCalendar;
56}
57
58void 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
68bool KCalendarSystemThaiPrivate::isLeapYear(int year) const
69{
70 return KCalendarSystemGregorianPrivate::isLeapYear(year - 543);
71}
72
73bool KCalendarSystemThaiPrivate::hasYearZero() const
74{
75 return true;
76}
77
78int KCalendarSystemThaiPrivate::earliestValidYear() const
79{
80 return 0;
81}
82
83
84KCalendarSystemThai::KCalendarSystemThai(const KLocale *locale)
85 : KCalendarSystemGregorian(*new KCalendarSystemThaiPrivate(this), KSharedConfig::Ptr(), locale)
86{
87 d_ptr->loadConfig(calendarType());
88}
89
90KCalendarSystemThai::KCalendarSystemThai(const KSharedConfig::Ptr config, const KLocale *locale)
91 : KCalendarSystemGregorian(*new KCalendarSystemThaiPrivate(this), config, locale)
92{
93 d_ptr->loadConfig(calendarType());
94}
95
96KCalendarSystemThai::KCalendarSystemThai(KCalendarSystemThaiPrivate &dd,
97 const KSharedConfig::Ptr config, const KLocale *locale)
98 : KCalendarSystemGregorian(dd, config, locale)
99{
100 d_ptr->loadConfig(calendarType());
101}
102
103KCalendarSystemThai::~KCalendarSystemThai()
104{
105}
106
107QString KCalendarSystemThai::calendarType() const
108{
109 return QLatin1String("thai");
110}
111
112QDate 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
118QDate KCalendarSystemThai::earliestValidDate() const
119{
120 return epoch();
121}
122
123QDate 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
130bool KCalendarSystemThai::isValid(int year, int month, int day) const
131{
132 return KCalendarSystemGregorian::isValid(year, month, day);
133}
134
135bool KCalendarSystemThai::isValid(const QDate &date) const
136{
137 return KCalendarSystemGregorian::isValid(date);
138}
139
140bool KCalendarSystemThai::isLeapYear(int year) const
141{
142 return KCalendarSystemGregorian::isLeapYear(year);
143}
144
145bool KCalendarSystemThai::isLeapYear(const QDate &date) const
146{
147 return KCalendarSystemGregorian::isLeapYear(date);
148}
149
150int KCalendarSystemThai::weekDayOfPray() const
151{
152 return 7; // TODO JPL ???
153}
154
155bool KCalendarSystemThai::isLunar() const
156{
157 return KCalendarSystemGregorian::isLunar();
158}
159
160bool KCalendarSystemThai::isLunisolar() const
161{
162 return KCalendarSystemGregorian::isLunisolar();
163}
164
165bool KCalendarSystemThai::isSolar() const
166{
167 return KCalendarSystemGregorian::isSolar();
168}
169
170bool KCalendarSystemThai::isProleptic() const
171{
172 return false;
173}
174
175bool 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
182bool KCalendarSystemThai::dateToJulianDay(int year, int month, int day, int &jd) const
183{
184 return KCalendarSystemGregorian::dateToJulianDay(year - 543, month, day, jd);
185}
186
KCalendarSystemGregorianPrivate
Definition: kcalendarsystemgregorianprivate_p.h:28
KCalendarSystemGregorianPrivate::hasYearZero
virtual bool hasYearZero() const
Definition: kcalendarsystemgregorian.cpp:139
KCalendarSystemGregorianPrivate::calendarSystem
virtual KLocale::CalendarSystem calendarSystem() const
Definition: kcalendarsystemgregorian.cpp:45
KCalendarSystemGregorianPrivate::earliestValidYear
virtual int earliestValidYear() const
Definition: kcalendarsystemgregorian.cpp:154
KCalendarSystemGregorianPrivate::loadDefaultEraList
virtual void loadDefaultEraList()
Definition: kcalendarsystemgregorian.cpp:52
KCalendarSystemGregorianPrivate::isLeapYear
virtual bool isLeapYear(int year) const
Definition: kcalendarsystemgregorian.cpp:117
KCalendarSystemGregorian
Definition: kcalendarsystemgregorian_p.h:43
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
KCalendarSystemGregorian::isLeapYear
virtual bool isLeapYear(int year) const
Returns whether a given year is a leap year.
Definition: kcalendarsystemgregorian.cpp:446
KCalendarSystemGregorian::isSolar
virtual bool isSolar() const
Returns whether the calendar is solar based.
Definition: kcalendarsystemgregorian.cpp:496
KCalendarSystemGregorian::isLunar
virtual bool isLunar() const
Returns whether the calendar is lunar based.
Definition: kcalendarsystemgregorian.cpp:486
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::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
KCalendarSystemGregorian::isLunisolar
virtual bool isLunisolar() const
Returns whether the calendar is lunisolar based.
Definition: kcalendarsystemgregorian.cpp:491
KCalendarSystemPrivate::q
const KCalendarSystem * q
Definition: kcalendarsystemprivate_p.h:104
KCalendarSystemThai
Definition: kcalendarsystemthai_p.h:39
KCalendarSystemThai::isLunisolar
virtual bool isLunisolar() const
Returns whether the calendar is lunisolar based.
Definition: kcalendarsystemthai.cpp:160
KCalendarSystemThai::isLeapYear
virtual bool isLeapYear(int year) const
Returns whether a given year is a leap year.
Definition: kcalendarsystemthai.cpp:140
KCalendarSystemThai::earliestValidDate
virtual QDate earliestValidDate() const
Returns the earliest date valid in this calendar system implementation.
Definition: kcalendarsystemthai.cpp:118
KCalendarSystemThai::~KCalendarSystemThai
virtual ~KCalendarSystemThai()
Definition: kcalendarsystemthai.cpp:103
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
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::epoch
virtual QDate epoch() const
Returns a QDate holding the epoch of the calendar system.
Definition: kcalendarsystemthai.cpp:112
KCalendarSystemThai::latestValidDate
virtual QDate latestValidDate() const
Returns the latest date valid in this calendar system implementation.
Definition: kcalendarsystemthai.cpp:123
KCalendarSystemThai::isProleptic
virtual bool isProleptic() const
Returns whether the calendar system is proleptic, i.e.
Definition: kcalendarsystemthai.cpp:170
KCalendarSystemThai::weekDayOfPray
virtual int weekDayOfPray() const
Definition: kcalendarsystemthai.cpp:150
KCalendarSystemThai::isSolar
virtual bool isSolar() const
Returns whether the calendar is solar based.
Definition: kcalendarsystemthai.cpp:165
KCalendarSystemThai::calendarType
virtual QString calendarType() const
Definition: kcalendarsystemthai.cpp:107
KCalendarSystemThai::isLunar
virtual bool isLunar() const
Returns whether the calendar is lunar based.
Definition: kcalendarsystemthai.cpp:155
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
KCalendarSystem::KCalendarSystemThai
friend class KCalendarSystemThai
Definition: kcalendarsystem.h:1676
KCalendarSystem::day
virtual int day(const QDate &date) const
Returns the day portion of a given date in the current calendar system.
Definition: kcalendarsystem.cpp:1357
KCalendarSystem::year
virtual int year(const QDate &date) const
Returns the year portion of a given date in the current calendar system.
Definition: kcalendarsystem.cpp:1331
KCalendarSystem::month
virtual int month(const QDate &date) const
Returns the month portion of a given date in the current calendar system.
Definition: kcalendarsystem.cpp:1344
KLocale
KLocale provides support for country specific stuff like the national language.
Definition: klocale.h:70
KLocale::CalendarSystem
CalendarSystem
Definition: klocale.h:780
KLocale::ThaiCalendar
@ ThaiCalendar
Thai Calendar, aka Buddhist or Thai Buddhist.
Definition: klocale.h:803
KSharedConfig
KConfig variant using shared memory.
Definition: ksharedconfig.h:41
KSharedPtr< KSharedConfig >
QString
kcalendarsystemgregorianprivate_p.h
kcalendarsystemthai_p.h
kdebug.h
klocale.h
i18nc
QString i18nc(const char *ctxt, const char *text)
Returns a localized version of a string and a context.
Definition: klocalizedstring.h:797
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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