2012-01-31 12:28:12 +01:00
|
|
|
/*
|
2012-02-01 11:09:15 +01:00
|
|
|
Copyright (C) 2012 Giorgos Tsiapaliwkas <terietor@gmail.com>
|
|
|
|
Copyright (C) 2012 Antonis Tsiapaliokas <kok3rs@gmail.com>
|
2012-01-31 12:28:12 +01:00
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2012-03-24 18:36:59 +01:00
|
|
|
//own
|
2012-02-01 11:24:48 +01:00
|
|
|
#include "calendarsystem.h"
|
2012-01-31 12:28:12 +01:00
|
|
|
|
2012-03-24 18:36:59 +01:00
|
|
|
//KDE
|
2012-02-12 14:51:55 +01:00
|
|
|
#include <KCalendarSystem>
|
2012-02-16 11:22:44 +01:00
|
|
|
#include <KGlobal>
|
2012-03-24 18:36:59 +01:00
|
|
|
|
|
|
|
//Qt
|
2012-02-12 15:14:18 +01:00
|
|
|
#include <QtCore/QDateTime>
|
2012-01-31 12:28:12 +01:00
|
|
|
|
2012-02-14 11:29:21 +01:00
|
|
|
CalendarSystem::CalendarSystem(QObject* parent)
|
|
|
|
: QObject(parent)
|
|
|
|
{
|
2012-02-16 11:22:44 +01:00
|
|
|
m_calendarSystem = KCalendarSystem::create(KGlobal::locale()->calendarSystem());
|
2012-02-14 11:29:21 +01:00
|
|
|
}
|
|
|
|
|
2012-03-23 14:46:46 +01:00
|
|
|
QList<int> CalendarSystem::calendarSystemsList()
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-03-23 14:46:46 +01:00
|
|
|
QList<int> list;
|
2012-01-31 12:28:12 +01:00
|
|
|
|
2012-02-12 14:51:55 +01:00
|
|
|
foreach(KLocale::CalendarSystem calendarSystem, KCalendarSystem::calendarSystemsList()) {
|
2012-03-23 14:46:46 +01:00
|
|
|
list.append((int)calendarSystem);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 13:02:43 +01:00
|
|
|
return list;
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 11:24:48 +01:00
|
|
|
Locale::CalendarSystem CalendarSystem::calendarSystem() const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return (Locale::CalendarSystem)m_calendarSystem->calendarSystem();
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-03-09 12:25:25 +01:00
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QString CalendarSystem::calendarLabel() const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-12 14:51:55 +01:00
|
|
|
return m_calendarSystem->calendarLabel();
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QDate CalendarSystem::epoch() const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->epoch();
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QDate CalendarSystem::earliestValidDate() const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
|
|
|
return epoch();
|
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QDate CalendarSystem::latestValidDate() const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->latestValidDate();
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
bool CalendarSystem::isValidIsoWeekDate(int year, int isoWeekNumber, int dayOfIsoWeek) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->isValidIsoWeekDate(year, isoWeekNumber, dayOfIsoWeek);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
bool CalendarSystem::isValid(const QDate &date) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->isValid(date);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-03-19 15:20:10 +01:00
|
|
|
QVariantHash CalendarSystem::getDate(const QDate date) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-03-19 15:20:10 +01:00
|
|
|
QVariantHash hash;
|
|
|
|
|
|
|
|
int year;
|
|
|
|
int month;
|
|
|
|
int day;
|
|
|
|
|
|
|
|
m_calendarSystem->getDate(date, &year, &month, &day);
|
|
|
|
|
|
|
|
hash["year"] = year;
|
|
|
|
hash["month"] = month;
|
|
|
|
hash["day"] = day;
|
|
|
|
|
|
|
|
return hash;
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::year(const QDate &date) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->year(date);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::month(const QDate &date) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->month(date);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::day(const QDate &date) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->day(date);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QString CalendarSystem::eraName(const QDate &date, StringFormat format) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-12 15:00:18 +01:00
|
|
|
return m_calendarSystem->eraName(date, (KCalendarSystem::StringFormat)format);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QString CalendarSystem::eraYear(const QDate &date, StringFormat format) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-12 15:00:18 +01:00
|
|
|
return m_calendarSystem->eraYear(date, (KCalendarSystem::StringFormat)format);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-03-09 12:25:25 +01:00
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::yearInEra(const QDate &date) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->yearInEra(date);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 13:02:43 +01:00
|
|
|
QDate CalendarSystem::addYears(const QDate &date, int numYears) const
|
|
|
|
{
|
|
|
|
return m_calendarSystem->addYears(date, numYears);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QDate CalendarSystem::addMonths(const QDate &date, int numMonths) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->addMonths(date, numMonths);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QDate CalendarSystem::addDays(const QDate &date, int numDays) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->addDays(date, numDays);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-03-19 15:20:10 +01:00
|
|
|
QVariantHash CalendarSystem::dateDifference(const QDate &fromDate, const QDate &toDate) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-03-19 15:20:10 +01:00
|
|
|
QVariantHash hash;
|
|
|
|
|
|
|
|
int yearsDiff;
|
|
|
|
int monthsDiff;
|
|
|
|
int daysDiff;
|
|
|
|
int direction;
|
|
|
|
|
|
|
|
m_calendarSystem->dateDifference(fromDate, toDate, &yearsDiff, &monthsDiff, &daysDiff, &direction);
|
|
|
|
|
|
|
|
hash["years"] = yearsDiff;
|
|
|
|
hash["months"] = monthsDiff;
|
|
|
|
hash["days"] = daysDiff;
|
|
|
|
hash["direction"] = direction;
|
|
|
|
|
|
|
|
return hash;
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::yearsDifference(const QDate &fromDate, const QDate &toDate) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->yearsDifference(fromDate, toDate);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::monthsDifference(const QDate &fromDate, const QDate &toDate) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->monthsDifference(fromDate, toDate);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::daysDifference(const QDate &fromDate, const QDate &toDate) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->daysDifference(fromDate, toDate);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::monthsInYear(int year) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->monthsInYear(year);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-03-23 14:31:03 +01:00
|
|
|
int CalendarSystem::weeksInYear(int year, WeekNumberSystem weekNumberSystem) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->weeksInYear(year, (KLocale::WeekNumberSystem)weekNumberSystem);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::daysInYear(int year) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->daysInYear(year);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::daysInMonth(int year, int month) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->daysInMonth(year, month);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::daysInWeek(const QDate &date) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-12 15:00:18 +01:00
|
|
|
return m_calendarSystem->daysInWeek(date);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::dayOfYear(const QDate &date) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->dayOfYear(date);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::dayOfWeek(const QDate &date) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->dayOfWeek(date);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-03-23 14:31:03 +01:00
|
|
|
int CalendarSystem::week(const QDate &date, WeekNumberSystem weekNumberSystem) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-03-23 14:31:03 +01:00
|
|
|
return m_calendarSystem->week(date, (KLocale::WeekNumberSystem)weekNumberSystem);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
bool CalendarSystem::isLeapYear(int year) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->isLeapYear(year);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QDate CalendarSystem::firstDayOfYear(int year) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->firstDayOfYear(year);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QDate CalendarSystem::lastDayOfYear(int year) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->lastDayOfYear(year);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QDate CalendarSystem::firstDayOfMonth(int year, int month) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->firstDayOfMonth(year, month);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QDate CalendarSystem::lastDayOfMonth(int year, int month) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->lastDayOfMonth(year, month);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QString CalendarSystem::monthName(int month, int year, CalendarSystem::MonthNameFormat format) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->monthName(month, year, (KCalendarSystem::MonthNameFormat)format);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
QString CalendarSystem::weekDayName(int weekDay, CalendarSystem::WeekDayNameFormat format) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->weekDayName(weekDay, (KCalendarSystem::WeekDayNameFormat)format);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-03-23 14:31:03 +01:00
|
|
|
QString CalendarSystem::formatDate(const QDate &date, DateTimeComponent component,
|
|
|
|
DateTimeComponentFormat format,
|
|
|
|
WeekNumberSystem weekNumberSystem) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->formatDate(date, (KLocale::DateTimeComponent)component,
|
|
|
|
(KLocale::DateTimeComponentFormat)format,
|
|
|
|
(KLocale::WeekNumberSystem)weekNumberSystem);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-03-23 14:31:03 +01:00
|
|
|
QDate CalendarSystem::readDate(const QString &str, ReadDateFlags flags) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-03-23 14:31:03 +01:00
|
|
|
return m_calendarSystem->readDate(str, (KLocale::ReadDateFlags)flags);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::shortYearWindowStartYear() const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->shortYearWindowStartYear();
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::applyShortYearWindow(int inputYear) const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->applyShortYearWindow(inputYear);
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 10:47:40 +01:00
|
|
|
int CalendarSystem::weekStartDay() const
|
2012-01-31 12:28:12 +01:00
|
|
|
{
|
2012-02-01 13:02:43 +01:00
|
|
|
return m_calendarSystem->weekStartDay();
|
2012-01-31 12:28:12 +01:00
|
|
|
}
|
2012-02-16 11:22:44 +01:00
|
|
|
|
|
|
|
bool CalendarSystem::isSolar() const
|
|
|
|
{
|
|
|
|
return m_calendarSystem->isSolar();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CalendarSystem::isLunar() const
|
|
|
|
{
|
|
|
|
return m_calendarSystem->isLunar();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CalendarSystem::isLunisolar() const
|
|
|
|
{
|
|
|
|
return m_calendarSystem->isLunisolar();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CalendarSystem::isProleptic() const
|
|
|
|
{
|
|
|
|
return m_calendarSystem->isProleptic();
|
|
|
|
}
|