summaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
authorPraveen Arimbrathodiyil <pravi.a@gmail.com>2008-12-28 00:21:13 -0800
committerPraveen Arimbrathodiyil <pravi.a@gmail.com>2008-12-28 00:21:13 -0800
commite8021bc59b06e8924205530cef77a7c7d13f4fdc (patch)
treebfb8b7495144afe14dba2708ae1c182aeb31692a /calendar
parent6aae3f22ce4e7ed3e901cf350cf4663b03ed2824 (diff)
downloadRachana.git-e8021bc59b06e8924205530cef77a7c7d13f4fdc.tar.gz
Rachana.git-e8021bc59b06e8924205530cef77a7c7d13f4fdc.tar.xz
Rachana.git-e8021bc59b06e8924205530cef77a7c7d13f4fdc.zip
added all files needed to build saka kalendar in kde trunk
Diffstat (limited to 'calendar')
-rw-r--r--calendar/kde/kdelibs/kdecore/CMakeLists.txt467
-rw-r--r--calendar/kde/kdelibs/kdecore/date/kcalendarsystem.cpp693
-rw-r--r--calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp606
-rw-r--r--calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.h117
-rw-r--r--calendar/kde/kdelibs/kdecore/tests/kcalendartest.cpp756
5 files changed, 2639 insertions, 0 deletions
diff --git a/calendar/kde/kdelibs/kdecore/CMakeLists.txt b/calendar/kde/kdelibs/kdecore/CMakeLists.txt
new file mode 100644
index 0000000..2e2bdf9
--- /dev/null
+++ b/calendar/kde/kdelibs/kdecore/CMakeLists.txt
@@ -0,0 +1,467 @@
+project(kdecore)
+# Generate config-kstandarddirs.h
+configure_file(config-kstandarddirs.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kstandarddirs.h )
+
+# Generate kdefakes.h
+configure_file(kdefakes.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/kdefakes.h )
+
+# Generate kdeversion.h
+configure_file(util/kdeversion.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/kdeversion.h )
+
+# Configure checks for network/ but also for netsupp.*
+include(network/ConfigureChecks.cmake)
+configure_file(network/config-network.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/network/config-network.h )
+include_directories( ${CMAKE_CURRENT_BINARY_DIR}/network )
+include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/sonnet/ )
+
+include_directories( ${KDE4_KDECORE_INCLUDES} )
+include_directories( ${ZLIB_INCLUDE_DIR} )
+include_directories( ${QT_INCLUDES} )
+
+# kdecore_OPTIONAL_SRCS is used to collect source files
+# which are not always compiled into kdecore
+# if it's used, *always* append to it
+set(kdecore_OPTIONAL_SRCS)
+# same for optional libs
+set(kdecore_OPTIONAL_LIBS)
+
+if(WIN32)
+ set(kdecore_OPTIONAL_LIBS ${kdecore_OPTIONAL_LIBS} ${KDEWIN32_LIBRARIES})
+endif(WIN32)
+
+# Needed for the kdatetime test in release mode
+if(KDE4_BUILD_TESTS)
+ add_definitions(-DCOMPILING_TESTS)
+endif(KDE4_BUILD_TESTS)
+
+# compile bzip2 support if available
+if(BZIP2_FOUND)
+ include_directories(${BZIP2_INCLUDE_DIR})
+ set(kdecore_OPTIONAL_SRCS ${kdecore_OPTIONAL_SRCS} compression/kbzip2filter.cpp )
+ set(kdecore_OPTIONAL_LIBS ${kdecore_OPTIONAL_LIBS} ${BZIP2_LIBRARIES})
+endif(BZIP2_FOUND)
+
+# compile Gettext support if available
+if(LIBINTL_FOUND)
+ include_directories(${LIBINTL_INCLUDE_DIR})
+ set(kdecore_OPTIONAL_LIBS ${kdecore_OPTIONAL_LIBS} ${LIBINTL_LIBRARIES})
+endif(LIBINTL_FOUND)
+
+if (HAVE_RESOLV_LIBRARY)
+ set(kdecore_OPTIONAL_LIBS ${kdecore_OPTIONAL_LIBS} resolv)
+endif (HAVE_RESOLV_LIBRARY)
+
+if (APPLE)
+ set(kdecore_OPTIONAL_SRCS ${kdecore_OPTIONAL_SRCS}
+ kernel/kkernel_mac.cpp
+ )
+ set(kdecore_OPTIONAL_LIBS ${kdecore_OPTIONAL_LIBS} ${CARBON_LIBRARY})
+endif (APPLE)
+
+if (WIN32)
+ set(kdecore_OPTIONAL_SRCS ${kdecore_OPTIONAL_SRCS}
+ kernel/kkernel_win.cpp
+ kernel/ktoolinvocation_win.cpp
+ kernel/kstandarddirs_win.cpp
+ network/klocalsocket_win.cpp
+ io/klockfile_win.cpp
+ util/kshell_win.cpp
+ util/kmacroexpander_win.cpp
+ util/kuser_win.cpp
+ )
+ if(NOT MSVC)
+ set(kdecore_OPTIONAL_SRCS ${kdecore_OPTIONAL_SRCS}
+ network/netsupp.cpp
+ )
+ endif(NOT MSVC)
+endif (WIN32)
+
+
+if (UNIX)
+ set(kdecore_OPTIONAL_SRCS ${kdecore_OPTIONAL_SRCS}
+ kernel/ktoolinvocation_x11.cpp
+ kernel/kstandarddirs_unix.cpp
+ network/k3httpproxysocketdevice.cpp
+ network/k3socks.cpp
+ network/k3sockssocketdevice.cpp
+ network/klocalsocket_unix.cpp
+ network/netsupp.cpp
+ io/klockfile_unix.cpp
+ util/kshell_unix.cpp
+ util/kuser_unix.cpp
+ util/kmacroexpander_unix.cpp
+ fakes.c
+ )
+endif (UNIX)
+
+
+add_subdirectory( kconfig_compiler )
+add_subdirectory( tests )
+add_subdirectory( sonnet/tests )
+
+########### next target ###############
+
+if (UNIX)
+
+ kde4_add_library(kdefakes SHARED fakes.c)
+ set_target_properties(kdefakes PROPERTIES VERSION ${KDE_NON_GENERIC_LIB_VERSION} SOVERSION ${KDE_NON_GENERIC_LIB_SOVERSION})
+ if (NOT HAVE_TRUNC)
+ target_link_libraries(kdefakes m )
+ endif (NOT HAVE_TRUNC)
+ install(TARGETS kdefakes EXPORT kdelibsLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS} )
+
+endif (UNIX)
+
+
+
+########### next target ###############
+
+set(kdecore_LIB_SRCS
+ compression/kgzipfilter.cpp
+ compression/kfilterbase.cpp
+ compression/kfilterdev.cpp
+ config/kconfig.cpp
+ config/kconfigbase.cpp
+ config/kconfiggroup.cpp
+ config/kconfigbackend.cpp
+ config/kconfigini.cpp
+ config/kdesktopfile.cpp
+ config/ksharedconfig.cpp
+ config/kcoreconfigskeleton.cpp
+ date/kcalendarsystem.cpp
+ date/kcalendarsystemgregorian.cpp
+ date/kcalendarsystemhijri.cpp
+ date/kcalendarsystemhebrew.cpp
+ date/kcalendarsystemjalali.cpp
+ date/kcalendarsystemindic.cpp
+ date/kdatetime.cpp
+ date/ktimezone.cpp
+ date/ksystemtimezone.cpp
+ date/ktzfiletimezone.cpp
+ io/kautosavefile.cpp
+ io/kdebug.cpp
+ io/kdebugdbusiface.cpp
+ io/kmessage.cpp
+ io/kprocess.cpp
+ io/ksavefile.cpp
+ io/ktempdir.cpp
+ io/ktemporaryfile.cpp
+ io/kurl.cpp
+ jobs/kcompositejob.cpp
+ jobs/kjob.cpp
+ jobs/kjobuidelegate.cpp
+ jobs/kjobtrackerinterface.cpp
+ kernel/kauthorized.cpp
+ kernel/kautostart.cpp
+ kernel/kaboutdata.cpp
+ kernel/kcmdlineargs.cpp
+ kernel/kglobal.cpp
+ kernel/kcomponentdata.cpp
+ kernel/kstandarddirs.cpp
+ kernel/ktoolinvocation.cpp
+ services/kfoldermimetype.cpp
+ services/kmimetypefactory.cpp
+ services/kmimemagicrule.cpp
+ services/kmimetypetrader.cpp
+ services/kmimetype.cpp
+ services/kservice.cpp
+ services/kserviceaction.cpp
+ services/kservicefactory.cpp
+ services/kservicegroup.cpp
+ services/kservicegroupfactory.cpp
+ services/kserviceoffer.cpp
+ services/kservicetype.cpp
+ services/kservicetypefactory.cpp
+ services/kservicetypeprofile.cpp
+ services/kservicetypetrader.cpp
+ services/ktraderparse.cpp
+ services/ktraderparsetree.cpp
+ services/yacc.c
+ services/lex.c
+ services/kplugininfo.cpp
+ sonnet/loader.cpp
+ sonnet/client.cpp
+ sonnet/spellerplugin.cpp
+ sonnet/speller.cpp
+ sonnet/filter.cpp
+ sonnet/settings.cpp
+ sonnet/backgroundchecker.cpp
+ sonnet/backgroundengine.cpp
+ sonnet/globals.cpp
+ network/k3socketdevice.cpp # must be before the rest of network/, for enable-final
+ network/k3bufferedsocket.cpp
+ network/k3clientsocketbase.cpp
+ network/k3datagramsocket.cpp
+ network/k3resolver.cpp
+ network/k3resolvermanager.cpp
+ network/k3resolverworkerbase.cpp
+ network/k3resolverstandardworkers.cpp
+ network/k3reverseresolver.cpp
+ network/k3serversocket.cpp
+ network/k3socketaddress.cpp
+ network/k3socketbase.cpp
+ network/k3streamsocket.cpp
+ network/k3socketbuffer.cpp
+ network/klocalsocket.cpp
+ network/ksocketfactory.cpp
+ network/ktcpsocket.cpp
+ localization/kcatalog.cpp
+ localization/kcharsets.cpp
+ localization/kencodingdetector.cpp
+ localization/guess_ja.cpp
+ localization/kencodingprober.cpp
+ localization/probers/CharDistribution.cpp
+ localization/probers/ChineseGroupProber.cpp
+ localization/probers/JapaneseGroupProber.cpp
+ localization/probers/JpCntx.cpp
+ localization/probers/LangBulgarianModel.cpp
+ localization/probers/LangCyrillicModel.cpp
+ localization/probers/LangGreekModel.cpp
+ localization/probers/LangHebrewModel.cpp
+ localization/probers/LangHungarianModel.cpp
+ localization/probers/LangThaiModel.cpp
+ localization/probers/UnicodeGroupProber.cpp
+ localization/probers/nsBig5Prober.cpp
+ localization/probers/nsCharSetProber.cpp
+ localization/probers/nsEUCJPProber.cpp
+ localization/probers/nsEUCKRProber.cpp
+ localization/probers/nsEUCTWProber.cpp
+ localization/probers/nsEscCharsetProber.cpp
+ localization/probers/nsEscSM.cpp
+ localization/probers/nsGB2312Prober.cpp
+ localization/probers/nsHebrewProber.cpp
+ localization/probers/nsLatin1Prober.cpp
+ localization/probers/nsMBCSGroupProber.cpp
+ localization/probers/nsMBCSSM.cpp
+ localization/probers/nsSBCSGroupProber.cpp
+ localization/probers/nsSBCharSetProber.cpp
+ localization/probers/nsSJISProber.cpp
+ localization/probers/nsUniversalDetector.cpp
+ localization/klocale.cpp
+ localization/klocalizedstring.cpp
+ localization/ktranslit.cpp
+ localization/kuitsemantics.cpp
+ localization/kuitformats.cpp
+ localization/common_helpers.cpp
+ sycoca/ksycoca.cpp
+ sycoca/ksycocadict.cpp
+ sycoca/ksycocaentry.cpp
+ sycoca/ksycocafactory.cpp
+ sycoca/kprotocolinfo.cpp
+ sycoca/kprotocolinfofactory.cpp
+ sycoca/kmemfile.cpp
+ text/kascii.cpp
+ text/kcodecs.cpp
+ text/kstringhandler.cpp
+ util/kallocator.cpp
+ util/kdedmodule.cpp
+ util/kdeversion.cpp
+ util/klauncher_iface.cpp
+ util/klibloader.cpp
+ util/klibrary.cpp
+ util/kmacroexpander.cpp
+ util/kpluginfactory.cpp
+ util/kpluginloader.cpp
+ util/kshell.cpp
+ util/krandom.cpp
+ util/krandomsequence.cpp
+ util/qtest_kde.cpp
+ ${kdecore_OPTIONAL_SRCS}
+)
+
+
+if (NOT Q_WS_X11 AND NOT Q_WS_QWS)
+ add_definitions(-DNO_DISPLAY)
+endif (NOT Q_WS_X11 AND NOT Q_WS_QWS)
+
+kde4_add_library(kdecore SHARED ${kdecore_LIB_SRCS})
+
+target_link_libraries(kdecore ${QT_QTCORE_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTDBUS_LIBRARY} ${QT_QTXML_LIBRARY} ${ZLIB_LIBRARY} ${kdecore_OPTIONAL_LIBS})
+
+if(WIN32)
+ set(kdecore_LINK_INTERFACE_LIBRARIES ${QT_QTDBUS_LIBRARY} ${QT_QTCORE_LIBRARY} ${KDEWIN32_LIBRARIES})
+else(WIN32)
+ if(APPLE)
+ set(kdecore_LINK_INTERFACE_LIBRARIES ${QT_QTDBUS_LIBRARY} ${QT_QTCORE_LIBRARY} ${CARBON_LIBRARY})
+ else(APPLE)
+ set(kdecore_LINK_INTERFACE_LIBRARIES ${QT_QTDBUS_LIBRARY} ${QT_QTCORE_LIBRARY} )
+ endif(APPLE)
+endif(WIN32)
+
+target_link_libraries(kdecore LINK_INTERFACE_LIBRARIES ${kdecore_LINK_INTERFACE_LIBRARIES} )
+
+set_target_properties(kdecore PROPERTIES
+ VERSION ${KDE_NON_GENERIC_LIB_VERSION}
+ SOVERSION ${KDE_NON_GENERIC_LIB_SOVERSION}
+ )
+
+
+install(TARGETS kdecore EXPORT kdelibsLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS})
+
+########### next target ###############
+
+configure_file(all_languages.desktop ${CMAKE_CURRENT_BINARY_DIR}/all_languages @ONLY)
+
+kde4_add_executable(kde4-config NOGUI kde-config.cpp )
+
+target_link_libraries(kde4-config ${KDE4_KDECORE_LIBS} )
+
+install(TARGETS kde4-config ${INSTALL_TARGETS_DEFAULT_ARGS} )
+
+
+########### next target ###############
+
+if (WIN32)
+ kde4_add_executable(kcmdwrapper NOGUI io/kcmdwrapper.cpp )
+
+ target_link_libraries(kcmdwrapper kernel32 shell32 )
+
+ install(TARGETS kcmdwrapper DESTINATION ${LIBEXEC_INSTALL_DIR} )
+endif (WIN32)
+
+########### next target ###############
+
+# kjs hash stuff for transcript plugin
+set( CREATE_HASH_TABLE ${CMAKE_SOURCE_DIR}/kjs/create_hash_table )
+
+add_custom_command(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ktranscript.lut.h
+ COMMAND ${PERL_EXECUTABLE} ${CREATE_HASH_TABLE}
+ ${CMAKE_CURRENT_SOURCE_DIR}/localization/ktranscript.cpp
+ > ${CMAKE_CURRENT_BINARY_DIR}/ktranscript.lut.h
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/localization/ktranscript.cpp
+)
+
+# the transcript plugin
+set( ktranscript_LIB_SRCS
+ localization/ktranscript.cpp
+ localization/common_helpers.cpp
+)
+
+kde4_add_plugin( ktranscript ${ktranscript_LIB_SRCS} )
+
+target_link_libraries( ktranscript kjs ${QT_QTCORE_LIBRARY} )
+
+
+if(KDE4_ENABLE_FINAL)
+ macro_add_file_dependencies(${CMAKE_CURRENT_BINARY_DIR}/ktranscript_final_cpp.cpp ${CMAKE_CURRENT_BINARY_DIR}/ktranscript.lut.h)
+else(KDE4_ENABLE_FINAL)
+ macro_add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/localization/ktranscript.cpp ${CMAKE_CURRENT_BINARY_DIR}/ktranscript.lut.h)
+endif(KDE4_ENABLE_FINAL)
+
+install( TARGETS ktranscript DESTINATION ${PLUGIN_INSTALL_DIR} )
+
+########### install files ###############
+install( FILES ${CMAKE_CURRENT_BINARY_DIR}/all_languages DESTINATION ${LOCALE_INSTALL_DIR} )
+install( FILES kdebug.areas kdebugrc DESTINATION ${CONFIG_INSTALL_DIR} )
+install( FILES
+ kdecore_export.h
+ compression/kfilterbase.h
+ compression/kfilterdev.h
+ config/conversion_check.h
+ config/kconfig.h
+ #config/kconfigbackend.h re-enable post-API review and implementation (4.2?)
+ config/kconfigbase.h
+ config/kconfiggroup.h
+ config/kdesktopfile.h
+ config/ksharedconfig.h
+ config/kcoreconfigskeleton.h
+ date/kcalendarsystem.h
+ date/kdatetime.h
+ date/ksystemtimezone.h
+ date/ktimezone.h
+ date/ktzfiletimezone.h
+ io/kautosavefile.h
+ io/kdebug.h
+ io/kmessage.h
+ io/kprocess.h
+ io/klockfile.h
+ io/ksavefile.h
+ io/ktempdir.h
+ io/ktemporaryfile.h
+ io/kurl.h
+ jobs/kcompositejob.h
+ jobs/kjob.h
+ jobs/kjobuidelegate.h
+ jobs/kjobtrackerinterface.h
+ kernel/kaboutdata.h
+ kernel/kauthorized.h
+ kernel/kautostart.h
+ kernel/kcmdlineargs.h
+ kernel/kglobal.h
+ kernel/kcomponentdata.h
+ kernel/kstandarddirs.h
+ kernel/ktoolinvocation.h
+ network/k3bufferedsocket.h
+ network/k3clientsocketbase.h
+ network/k3datagramsocket.h
+ network/k3httpproxysocketdevice.h
+ network/k3resolver.h
+ network/k3reverseresolver.h
+ network/k3serversocket.h
+ network/k3socketaddress.h
+ network/k3socketbase.h
+ network/k3socketdevice.h
+ network/k3socks.h
+ network/k3sockssocketdevice.h
+ network/k3streamsocket.h
+ network/klocalsocket.h
+ network/ksocketfactory.h
+ services/kmimetype.h
+ services/kmimetypetrader.h
+ services/kservice.h
+ services/kserviceaction.h
+ services/kservicegroup.h
+ #services/kservicefactory.h: do not install, internal API
+ services/kservicetype.h
+ #services/kservicetypefactory.h: do not install, internal API
+ services/kservicetypeprofile.h
+ services/kservicetypetrader.h
+ #services/kserviceoffer.h: do not install, internal API
+ services/kplugininfo.h
+ localization/kcharsets.h
+ localization/kencodingdetector.h
+ localization/kencodingprober.h
+ localization/klocale.h
+ localization/klocalizedstring.h
+ sycoca/kprotocolinfo.h
+ sycoca/ksycoca.h
+ sycoca/ksycocaentry.h
+ sycoca/ksycocatype.h
+ text/kascii.h
+ text/kcodecs.h
+ text/kstringhandler.h
+ util/kallocator.h
+ util/kde_file.h
+ util/kdedmodule.h
+ util/kgenericfactory.h
+ util/kgenericfactory.tcc
+ util/klauncher_iface.h
+ util/klibloader.h
+ util/klibrary.h
+ util/kmacroexpander.h
+ util/kexportplugin.h
+ util/kpluginfactory.h
+ util/kpluginloader.h
+ util/kshell.h
+ util/krandom.h
+ util/krandomsequence.h
+ util/ksharedptr.h
+ util/ksortablelist.h
+ util/ktypelist.h
+ util/kuser.h
+ util/qtest_kde.h
+ ${CMAKE_CURRENT_BINARY_DIR}/kdefakes.h
+ ${CMAKE_CURRENT_BINARY_DIR}/kdeversion.h
+ DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel
+)
+
+install( FILES sonnet/backgroundchecker.h sonnet/speller.h sonnet/globals.h
+ DESTINATION ${INCLUDE_INSTALL_DIR}/sonnet COMPONENT Devel)
+
+install( FILES
+ config/kconfigbackend.desktop
+ services/kplugininfo.desktop
+ sonnet/sonnetspeller.desktop
+ DESTINATION ${SERVICETYPES_INSTALL_DIR}
+)
diff --git a/calendar/kde/kdelibs/kdecore/date/kcalendarsystem.cpp b/calendar/kde/kdelibs/kdecore/date/kcalendarsystem.cpp
new file mode 100644
index 0000000..4f8bc3f
--- /dev/null
+++ b/calendar/kde/kdelibs/kdecore/date/kcalendarsystem.cpp
@@ -0,0 +1,693 @@
+/*
+ Copyright (c) 2002 Carlos Moro <cfmoro@correo.uniovi.es>
+ Copyright (c) 2002 Hans Petter Bieker <bieker@kde.org>
+ Copyright (c) 2007 John Layt <john@layt.net>
+
+ 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.
+*/
+
+#include "kcalendarsystem.h"
+
+#include "kglobal.h"
+
+#include <QtCore/QDateTime>
+
+#include "kcalendarsystemgregorian.h"
+#include "kcalendarsystemhebrew.h"
+#include "kcalendarsystemhijri.h"
+#include "kcalendarsystemjalali.h"
+#include "kcalendarsystemindic.h"
+
+KCalendarSystem *KCalendarSystem::create( const QString &calendarType, const KLocale *locale )
+{
+ if ( calendarType == "hebrew" ) {
+ return new KCalendarSystemHebrew( locale );
+ }
+
+ if ( calendarType == "hijri" ) {
+ return new KCalendarSystemHijri( locale );
+ }
+
+ if ( calendarType == "gregorian" ) {
+ return new KCalendarSystemGregorian( locale );
+ }
+
+ if ( calendarType == "jalali" ) {
+ return new KCalendarSystemJalali( locale );
+ }
+ if ( calendarType == "indic" ) {
+ return new KCalendarSystemIndic( locale );
+ }
+
+ // ### HPB: Should it really be a default here?
+ return new KCalendarSystemGregorian( locale );
+}
+
+QStringList KCalendarSystem::calendarSystems()
+{
+ QStringList lst;
+
+ lst.append( "hebrew" );
+ lst.append( "hijri" );
+ lst.append( "gregorian" );
+ lst.append( "jalali" );
+ lst.append( "indic" );
+
+ return lst;
+}
+
+QString KCalendarSystem::calendarLabel( const QString &calendarType )
+{
+ if ( calendarType == "gregorian" ) {
+ return ki18nc( "@item Calendar system", "Gregorian" ).toString( KGlobal::locale() );
+ }
+
+ if ( calendarType == "hebrew" ) {
+ return ki18nc( "@item Calendar system", "Hebrew" ).toString( KGlobal::locale() );
+ }
+
+ if ( calendarType == "hijri" ) {
+ return ki18nc("@item Calendar system", "Hijri").toString( KGlobal::locale());
+ }
+
+ if ( calendarType == "jalali" ) {
+ return ki18nc( "@item Calendar system", "Jalali" ).toString( KGlobal::locale() );
+ }
+ if ( calendarType == "indic" ) {
+ return ki18nc( "@item Calendar system", "Indic" ).toString( KGlobal::locale() );
+ }
+ return ki18nc( "@item Calendar system", "Invalid Calendar Type" ).toString( KGlobal::locale() );
+}
+
+
+class KCalendarSystemPrivate
+{
+public:
+ KCalendarSystemPrivate( KCalendarSystem *q ): q( q )
+ {
+ }
+
+ ~KCalendarSystemPrivate()
+ {
+ }
+
+ KCalendarSystem *q;
+
+ bool setAnyDate( QDate &date, int year, int month, int day ) const;
+
+ int stringToInteger( const QString &sNum, int &iLength );
+
+ const KLocale *locale;
+};
+
+// Allows us to set dates outside publically valid range, USE WITH CARE!!!!
+bool KCalendarSystemPrivate::setAnyDate( QDate &date, int year, int month, int day ) const
+{
+ int jd;
+ q->dateToJulianDay( year, month, day, jd );
+ date = QDate::fromJulianDay( jd );
+ return true;
+}
+
+int KCalendarSystemPrivate::stringToInteger( const QString &sNum, int &iLength )
+{
+ int iPos = 0;
+ int result = 0;
+
+ for ( ; sNum.length() > iPos && sNum.at( iPos ).isDigit(); iPos++ ) {
+ result *= 10;
+ result += sNum.at( iPos ).digitValue();
+ }
+ iLength = iPos;
+
+ return result;
+}
+
+KCalendarSystem::KCalendarSystem( const KLocale *locale ) : d( new KCalendarSystemPrivate( this ) )
+{
+ d->locale = locale;
+}
+
+KCalendarSystem::~KCalendarSystem()
+{
+ delete d;
+}
+
+// This method MUST be re-implemented in any new Calendar System
+QDate KCalendarSystem::epoch() const
+{
+ // Earliest valid QDate
+ return QDate::fromJulianDay( 1 );
+}
+
+QDate KCalendarSystem::earliestValidDate() const
+{
+ return epoch();
+}
+
+// This method MUST be re-implemented in any new Calendar System
+QDate KCalendarSystem::latestValidDate() const
+{
+ // Default to Gregorian 9999-12-31
+ return QDate::fromJulianDay( 5373484 );
+}
+
+// This method MUST be re-implemented in any new Calendar System
+bool KCalendarSystem::isValid( int y, int month, int day ) const
+{
+ // Default to true Gregorian
+
+ if ( y < year( earliestValidDate() ) || y > year( latestValidDate() ) ) {
+ return false;
+ }
+
+ if ( month < 1 || month > 12 ) {
+ return false;
+ }
+
+ if ( month == 2 ) {
+ if ( isLeapYear( y ) ) {
+ return ( day >= 1 && day <= 29 );
+ } else {
+ return ( day >= 1 && day <= 28 );
+ }
+ }
+
+ if ( month == 4 || month == 6 || month == 9 || month == 11 ) {
+ return ( day >= 1 && day <= 30 );
+ }
+
+ return ( day >= 1 && day <= 31 );
+}
+
+bool KCalendarSystem::isValid( const QDate &date ) const
+{
+ if ( date.isNull() || date < earliestValidDate() || date > latestValidDate() ) {
+ return false;
+ }
+ return true;
+}
+
+bool KCalendarSystem::setDate( QDate &date, int year, int month, int day ) const
+{
+ if ( isValid( year, month, day ) ) {
+ int jd;
+ dateToJulianDay( year, month, day, jd );
+ date = QDate::fromJulianDay( jd );
+ return true;
+ }
+
+ return false;
+}
+
+// Deprecated
+bool KCalendarSystem::setYMD( QDate &date, int year, int month, int day ) const
+{
+ return setDate( date, year, month, day );
+}
+
+int KCalendarSystem::year( const QDate &date ) const
+{
+ if ( isValid( date ) ) {
+ int year, month, day;
+
+ julianDayToDate( date.toJulianDay(), year, month, day );
+
+ return year;
+ }
+
+ return 0; // How do you denote invalid year when we support -ve years?
+}
+
+int KCalendarSystem::month( const QDate &date ) const
+{
+ if ( isValid( date ) ) {
+ int year, month, day;
+
+ julianDayToDate( date.toJulianDay(), year, month, day );
+
+ return month;
+ }
+
+ return 0;
+}
+
+int KCalendarSystem::day( const QDate &date ) const
+{
+ if ( isValid( date ) ) {
+ int year, month, day;
+
+ julianDayToDate( date.toJulianDay(), year, month, day );
+
+ return day;
+ }
+
+ return 0;
+}
+
+QDate KCalendarSystem::addYears( const QDate &date, int numYears ) const
+{
+ if ( isValid( date ) ) {
+
+ int originalYear, originalMonth, originalDay;
+ int newYear, newMonth, newDay;
+ QDate firstOfNewMonth, newDate;
+
+ julianDayToDate( date.toJulianDay(), originalYear, originalMonth, originalDay );
+
+ newYear = originalYear + numYears;
+ newMonth = originalMonth;
+
+ //Adjust day number if new month has fewer days than old month
+ if ( setDate( firstOfNewMonth, newYear, newMonth, 1 ) ) {
+ int daysInNewMonth = daysInMonth( firstOfNewMonth );
+ newDay = ( daysInNewMonth < originalDay ) ? daysInNewMonth : originalDay;
+
+ if ( setDate( newDate, newYear, newMonth, newDay ) ) {
+ return newDate;
+ }
+ }
+
+ }
+
+ //Is QDate's way of saying is invalid
+ return QDate::fromJulianDay( 0 );
+}
+
+QDate KCalendarSystem::addMonths( const QDate &date, int numMonths ) const
+{
+ if ( isValid( date ) ) {
+
+ int originalYear, originalMonth, originalDay;
+ int newYear, newMonth, newDay;
+ int monthsInOriginalYear, daysInNewMonth;
+ QDate firstOfNewMonth, newDate;
+
+ julianDayToDate( date.toJulianDay(), originalYear, originalMonth, originalDay );
+
+ monthsInOriginalYear = monthsInYear( date );
+
+ newYear = originalYear + ( ( originalMonth + numMonths ) / monthsInOriginalYear );
+ newMonth = ( originalMonth + numMonths ) % monthsInOriginalYear;
+
+ if ( newMonth == 0 ) {
+ newYear = newYear - 1;
+ newMonth = monthsInOriginalYear;
+ }
+ if ( newMonth < 0 ) {
+ newYear = newYear - 1;
+ newMonth = newMonth + monthsInOriginalYear;
+ }
+
+ //Adjust day number if new month has fewer days than old month
+ if ( setDate( firstOfNewMonth, newYear, newMonth, 1 ) ) {
+ daysInNewMonth = daysInMonth( firstOfNewMonth );
+ newDay = ( daysInNewMonth < originalDay ) ? daysInNewMonth : originalDay;
+
+ if ( setDate( newDate, newYear, newMonth, newDay ) ) {
+ return newDate;
+ }
+ }
+
+ }
+
+ //Is QDate's way of saying is invalid
+ return QDate::fromJulianDay( 0 );
+}
+
+QDate KCalendarSystem::addDays( const QDate &date, int numDays ) const
+{
+ // QDate only holds a uint and has no boundary checking in addDays(), so we need to check
+ if ( isValid( date ) && (long) date.toJulianDay() + (long) numDays > 0 ) {
+ // QDate adds straight to jd
+ QDate temp = date.addDays( numDays );
+ if ( isValid( temp ) ) {
+ return temp;
+ }
+ }
+
+ //Is QDate's way of saying is invalid
+ return QDate::fromJulianDay( 0 );
+}
+
+int KCalendarSystem::monthsInYear( const QDate &date ) const
+{
+ // Last day of this year = first day of next year minus 1 day
+ // Use setAnyDate() to allow correct calculation in last valid year
+
+ if ( isValid( date ) ) {
+ QDate firstDayOfNextYear;
+ d->setAnyDate( firstDayOfNextYear, year( date ) + 1, 1, 1 );
+ QDate lastDayOfThisYear = addDays( firstDayOfNextYear, -1 );
+ return month( lastDayOfThisYear );
+ }
+
+ return -1;
+}
+
+int KCalendarSystem::weeksInYear( const QDate &date ) const
+{
+ if ( isValid( date ) ) {
+ return weeksInYear( year( date ) );
+ }
+ return -1;
+}
+
+// ISO compliant week numbering, not traditional number, rename in KDE5 to isoWeeksInYear()
+int KCalendarSystem::weeksInYear( int year ) const
+{
+ // Last day of this year = first day of next year minus 1 day
+ // Use setAnyDate() to allow correct calculation in last valid year
+
+ if ( isValid( year, 1, 1 ) ) {
+ QDate firstDayOfNextYear;
+ d->setAnyDate( firstDayOfNextYear, year + 1, 1, 1 );
+ QDate lastDayOfThisYear = addDays( firstDayOfNextYear, -1 );
+
+ int lastWeekInThisYear = weekNumber( lastDayOfThisYear );
+
+ // If the last day of the year is in the first week of next year use the week before
+ if ( lastWeekInThisYear == 1 ) {
+ lastDayOfThisYear = lastDayOfThisYear.addDays( -7 );
+ lastWeekInThisYear = weekNumber( lastDayOfThisYear );
+ }
+
+ return lastWeekInThisYear;
+ }
+
+ return -1;
+}
+
+int KCalendarSystem::daysInYear( const QDate &date ) const
+{
+ // Days in year = jd of first day of next year minus jd of first day of this year
+ // Use setAnyDate() to allow correct calculation in last valid year
+
+ if ( isValid( date ) ) {
+ QDate firstDayOfThisYear, firstDayOfNextYear;
+
+ setDate( firstDayOfThisYear, year( date ), 1, 1 );
+ d->setAnyDate( firstDayOfNextYear, year( date ) + 1, 1, 1 );
+
+ return ( firstDayOfNextYear.toJulianDay() - firstDayOfThisYear.toJulianDay() );
+ }
+
+ return -1;
+}
+
+int KCalendarSystem::daysInMonth( const QDate &date ) const
+{
+ // Days In Month = jd of first day of next month minus jd of first day of this month
+ // Use setAnyDate() to allow correct calculation in last valid year
+
+ if ( isValid( date ) ) {
+ QDate firstDayOfThisMonth, firstDayOfNextMonth;
+
+ int thisYear = year( date );
+ int thisMonth = month( date );
+
+ setDate( firstDayOfThisMonth, thisYear, thisMonth, 1 );
+
+ //check if next month falls in next year
+ if ( thisMonth < monthsInYear( date ) ) {
+ setDate( firstDayOfNextMonth, thisYear, thisMonth + 1, 1 );
+ } else {
+ d->setAnyDate( firstDayOfNextMonth, thisYear + 1, 1, 1 );
+ }
+
+ return ( firstDayOfNextMonth.toJulianDay() - firstDayOfThisMonth.toJulianDay() );
+ }
+
+ return -1;
+}
+
+int KCalendarSystem::daysInWeek( const QDate &date ) const
+{
+ Q_UNUSED( date );
+ return 7;
+}
+
+int KCalendarSystem::dayOfYear( const QDate &date ) const
+{
+ //Take the jd of the given date, and subtract the jd of the first day of that year
+
+ if ( isValid( date ) ) {
+ QDate firstDayOfYear;
+
+ if ( setDate( firstDayOfYear, year( date ), 1, 1 ) ) {
+ return ( date.toJulianDay() - firstDayOfYear.toJulianDay() + 1 );
+ }
+ }
+
+ return -1;
+}
+
+int KCalendarSystem::dayOfWeek( const QDate &date ) const
+{
+ // Makes assumption that Julian Day 0 was day 1 of week
+ // This is true for Julian/Gregorian calendar with jd 0 being Monday
+ // We add 1 for ISO compliant numbering for 7 day week
+ // Assumes we've never skipped weekdays
+ if ( isValid( date ) ) {
+ return ( ( date.toJulianDay() % daysInWeek( date ) ) + 1 );
+ }
+
+ return -1;
+}
+
+// ISO compliant week numbering, not traditional number, rename in KDE5 to isoWeekNumber()
+// JPL still need to fully clean up here
+int KCalendarSystem::weekNumber( const QDate &date, int *yearNum ) const
+{
+ if ( isValid( date ) ) {
+ QDate firstDayWeek1, lastDayOfYear;
+ int y = year( date );
+ int week;
+ int weekDay1, dayOfWeek1InYear;
+
+ // let's guess 1st day of 1st week
+ setDate( firstDayWeek1, y, 1, 1 );
+ weekDay1 = dayOfWeek( firstDayWeek1 );
+
+ // iso 8601: week 1 is the first containing thursday and week starts on monday
+ if ( weekDay1 > 4 /*Thursday*/ ) {
+ firstDayWeek1 = addDays( firstDayWeek1 , daysInWeek( date ) - weekDay1 + 1 ); // next monday
+ }
+
+ dayOfWeek1InYear = dayOfYear( firstDayWeek1 );
+
+ // our date in prev year's week
+ if ( dayOfYear( date ) < dayOfWeek1InYear ) {
+ if ( yearNum ) {
+ *yearNum = y - 1;
+ }
+ return weeksInYear( y - 1 );
+ }
+
+ // let's check if its last week belongs to next year
+ d->setAnyDate( lastDayOfYear, y + 1, 1, 1 );
+ lastDayOfYear = addDays( lastDayOfYear, -1 );
+ // if our date is in last week && 1st week in next year has thursday
+ if ( ( dayOfYear( date ) >= daysInYear( date ) - dayOfWeek( lastDayOfYear ) + 1 )
+ && dayOfWeek( lastDayOfYear ) < 4 ) {
+ if ( yearNum ) {
+ * yearNum = y + 1;
+ }
+ week = 1;
+ } else {
+ // To calculate properly the number of weeks from day a to x let's make a day 1 of week
+ if( weekDay1 < 5 ) {
+ firstDayWeek1 = addDays( firstDayWeek1, -( weekDay1 - 1 ) );
+ }
+
+ week = firstDayWeek1.daysTo( date ) / daysInWeek( date ) + 1;
+ }
+
+ return week;
+ }
+
+ return -1;
+}
+
+// This method MUST be reimplemented in any derived Calendar Systems
+bool KCalendarSystem::isLeapYear( int year ) const
+{
+ // Default to pure Gregorian
+
+ if ( year % 4 == 0 ) {
+ if ( year % 100 != 0 ) {
+ return true;
+ } else if ( year % 400 == 0 ) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool KCalendarSystem::isLeapYear( const QDate &date ) const
+{
+ return isLeapYear( year( date ) );
+}
+
+QString KCalendarSystem::monthName( const QDate &date, MonthNameFormat format ) const
+{
+ if ( isValid( date ) ) {
+ return monthName( month( date ), year( date ), format );
+ }
+
+ return QString();
+}
+
+QString KCalendarSystem::weekDayName( const QDate &date, WeekDayNameFormat format ) const
+{
+ if ( isValid( date ) ) {
+ return weekDayName( dayOfWeek( date ), format );
+ }
+
+ return QString();
+}
+
+QString KCalendarSystem::yearString( const QDate &date, StringFormat format ) const
+{
+ if ( isValid( date ) ) {
+ QString result;
+
+ result.setNum( year( date ) );
+ if ( format == ShortFormat && result.length() == 4 ) {
+ result = result.right( 2 );
+ }
+
+ return result;
+ }
+
+ return QString();
+}
+
+QString KCalendarSystem::monthString( const QDate &date, StringFormat format ) const
+{
+ if ( isValid( date ) ) {
+ QString result;
+
+ result.setNum( month( date ) );
+ if ( format == LongFormat && result.length() == 1 ) {
+ result.prepend( QLatin1Char( '0' ) );
+ }
+
+ return result;
+ }
+
+ return QString();
+}
+
+QString KCalendarSystem::dayString( const QDate &date, StringFormat format ) const
+{
+ if ( isValid( date ) ) {
+ QString result;
+
+ result.setNum( day( date ) );
+ if ( format == LongFormat && result.length() == 1 ) {
+ result.prepend( QLatin1Char( '0' ) );
+ }
+
+ return result;
+ }
+
+ return QString();
+}
+
+int KCalendarSystem::yearStringToInteger( const QString &yearString, int &iLength ) const
+{
+ return d->stringToInteger( yearString, iLength );
+}
+
+int KCalendarSystem::monthStringToInteger( const QString &monthString, int &iLength ) const
+{
+ return d->stringToInteger( monthString, iLength );
+}
+
+int KCalendarSystem::dayStringToInteger( const QString &dayString, int &iLength ) const
+{
+ return d->stringToInteger( dayString, iLength );
+}
+
+QString KCalendarSystem::formatDate( const QDate &date, KLocale::DateFormat format ) const
+{
+ return locale()->formatDate( date, format );
+}
+
+QDate KCalendarSystem::readDate( const QString &str, bool *ok ) const
+{
+ return locale()->readDate( str, ok );
+}
+
+QDate KCalendarSystem::readDate( const QString &intstr, const QString &fmt, bool *ok ) const
+{
+ return locale()->readDate( intstr, fmt, ok );
+}
+
+QDate KCalendarSystem::readDate( const QString &str, KLocale::ReadDateFlags flags, bool *ok ) const
+{
+ return locale()->readDate( str, flags, ok );
+}
+
+int KCalendarSystem::weekStartDay() const
+{
+ return locale()->weekStartDay();
+}
+
+// Fake version using QDate, each Calendar System MUST implement the correct version for themselves
+// The implementation MUST NOT do validity checking on date ranges, all calls to this function MUST
+// instead be wrapped in validity checks, as sometimes we want this to work outside the public valid
+// range, i.e. to allow us to internally set dates of 1/1/10000 which are not publically valid but
+// are required for internal maths
+bool KCalendarSystem::julianDayToDate( int jd, int &year, int &month, int &day ) const
+{
+ QDate date = QDate::fromJulianDay( jd );
+
+ if ( date.isValid() ) {
+ year = date.year();
+ month = date.month();
+ day = date.day();
+ }
+
+ return date.isValid();
+}
+
+// Fake version using QDate, each Calendar System MUST implement the correct version for themselves
+// The implementation MUST NOT do validity checking on date ranges, all calls to this function MUST
+// instead be wrapped in validity checks, as sometimes we want this to work outside the public valid
+// range, i.e. to allow us to internally set dates of 1/1/10000 which are not publically valid but
+// are required for internal maths
+bool KCalendarSystem::dateToJulianDay( int year, int month, int day, int &jd ) const
+{
+ QDate date;
+
+ if ( date.setDate( year, month, day ) ) {
+ jd = date.toJulianDay();
+ return true;
+ }
+
+ return false;
+}
+
+const KLocale * KCalendarSystem::locale() const
+{
+ if ( d->locale ) {
+ return d->locale;
+ }
+
+ return KGlobal::locale();
+}
diff --git a/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp b/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp
new file mode 100644
index 0000000..45ec459
--- /dev/null
+++ b/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.cpp
@@ -0,0 +1,606 @@
+/*
+ Copyright (c) 2008 Santhosh Thottingal <santhosh.thottingal@gmail.com>
+
+ 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.
+*/
+
+// Derived indic kde calendar class
+
+#include "kcalendarsystemindic.h"
+
+#include "kdebug.h"
+#include "klocale.h"
+#include <math.h>
+#include <QtCore/QDate>
+#include <QtCore/QCharRef>
+class KCalendarSystemSaka{
+//-------------------------------------------------------------------------
+// The only practical difference from a Gregorian calendar is that years
+// are numbered since the Saka Era. A couple of overrides will
+// take care of that....
+//-------------------------------------------------------------------------
+
+// Starts in 78 AD,
+private:
+ static const int SAKA_ERA_START = 78;
+ // The Saka year starts 80 days later than the Gregorian year.
+ static const int SAKA_YEAR_START = 80;
+public:
+ static int get_era_start(void) { return SAKA_ERA_START; }
+ static int get_year_start(void) { return SAKA_YEAR_START; }
+ static double gregorianToJD(int year, int month, int date);
+ static int getMonthLength(int greg_year, int month);
+ static double SakaToJD(int year, int month, int date);
+
+};
+int KCalendarSystemSaka::getMonthLength(int greg_year, int month)
+{
+ if (month < 0 || month > 11) {
+ greg_year += month/12;
+ month = month%12;
+ }
+
+ if( QDate::isLeapYear( greg_year + get_era_start()) && month == 0) {
+ return 31;
+ }
+
+ if(month >= 1 && month <=5) {
+ return 31;
+ }
+
+ return 30;
+}
+/*
+ * This routine converts an Indian date to the corresponding Julian date"
+ * year The year in Saka Era according to Indian calendar.
+ * month The month according to Indian calendar (between 1 to 12)
+ * date The date in month
+ */
+ double KCalendarSystemSaka::gregorianToJD(int year, int month, int date) {
+ QDate qdate(year,month,date);
+ return qdate.toJulianDay();
+ }
+ double KCalendarSystemSaka::SakaToJD(int year, int month, int date) {
+ int leapMonth, gyear, m;
+ double start, jd;
+
+ gyear = year + get_era_start();
+
+
+ if(QDate::isLeapYear(gyear)) {
+ leapMonth = 31;
+ start = gregorianToJD(gyear, 3, 21);
+ } else {
+ leapMonth = 30;
+ start = gregorianToJD(gyear, 3, 22);
+ }
+
+ if (month == 1) {
+ jd = start + (date - 1);
+ } else {
+ jd = start + leapMonth;
+ m = month - 2;
+ m= (m<5) ? m : 5;
+ jd += m * 31;
+ if (month >= 8) {
+ m = month - 7;
+ jd += m * 30;
+ }
+ jd += date - 1;
+ }
+
+ return jd;
+}
+
+
+KCalendarSystemIndic::KCalendarSystemIndic( const KLocale * locale )
+ : KCalendarSystem( locale ), d( 0 )
+{
+}
+
+KCalendarSystemIndic::~KCalendarSystemIndic()
+{
+}
+
+QString KCalendarSystemIndic::calendarType() const
+{
+ return QLatin1String( "indic" );
+}
+
+QDate KCalendarSystemIndic::epoch() const
+{
+ return QDate::fromJulianDay( 1721426 );
+}
+
+QDate KCalendarSystemIndic::earliestValidDate() const
+{
+ return QDate::fromJulianDay( 1 );
+}
+
+QDate KCalendarSystemIndic::latestValidDate() const
+{
+ // Set to last day of year 9999 until confirm date formats & widets support > 9999
+ // In Indic this is 9999-12-31, which is is jd 5373484
+ // Can't call setDate( 9999, 12, 31 ) as it creates circular reference!
+ return QDate::fromJulianDay( 5373484 );
+}
+
+bool KCalendarSystemIndic::isValid( int year, int month, int day ) const
+{
+ // Limit to max year 9999 for now, QDate allows to be greater
+ if ( year <= 9999 ) {
+ return QDate::isValid( year, month, day );
+ }
+
+ return false;
+}
+
+bool KCalendarSystemIndic::isValid( const QDate &date ) const
+{
+ return KCalendarSystem::isValid( date );
+}
+
+bool KCalendarSystemIndic::setDate( QDate &date, int year, int month, int day ) const
+{
+ return KCalendarSystem::setDate( date, year, month, day );
+}
+
+// Deprecated
+bool KCalendarSystemIndic::setYMD( QDate &date, int y, int m, int d ) const
+{
+ return KCalendarSystem::setDate( date, y, m, d );
+}
+
+int KCalendarSystemIndic::year( const QDate &date ) const
+{
+ return KCalendarSystem::year( date ) - KCalendarSystemSaka::get_era_start();
+}
+
+int KCalendarSystemIndic::month( const QDate &date ) const
+{
+ double jdAtStartOfGregYear;
+ int leapMonth, IndianYear, yday, sakaMonth, sakaDayOfMonth, mday;
+ int sakaYear = KCalendarSystemIndic::year(date); // Year in Saka era
+ jdAtStartOfGregYear = KCalendarSystemSaka::gregorianToJD( date.year(), 1, 1); // JD at start of Gregorian year
+ double julianDay=KCalendarSystemSaka::gregorianToJD( date.year(), date.month(), date.day());
+ yday = (int)(julianDay - jdAtStartOfGregYear); // Day number in Gregorian year (starting from 0)
+ if (yday < KCalendarSystemSaka::get_year_start()) {
+ // Day is at the end of the preceding Saka year
+ sakaYear -= 1;
+ leapMonth = KCalendarSystem::isLeapYear(date.year() - 1) ? 31 : 30; // Days in leapMonth this year, previous Gregorian year
+ yday += leapMonth + (31 * 5) + (30 * 3) + 10;
+ } else {
+ leapMonth = KCalendarSystem::isLeapYear(date.year()) ? 31 : 30; // Days in leapMonth this year
+ yday -= KCalendarSystemSaka::get_year_start();
+ }
+ if (yday < leapMonth) {
+ sakaMonth = 0;
+ sakaDayOfMonth = yday + 1;
+ } else {
+ mday = yday - leapMonth;
+ if (mday < (31 * 5)) {
+ sakaMonth = (int)floor(mday / 31) + 1;
+ sakaDayOfMonth = (mday % 31) + 1;
+ } else {
+ mday -= 31 * 5;
+ sakaMonth = (int)floor(mday / 30) + 6;
+ sakaDayOfMonth = (mday % 30) + 1;
+ }
+ }
+
+ /*Month is 0 based.converting it to 1 based*/
+ if(sakaMonth == 12) {
+ sakaMonth = 1;
+ } else {
+ sakaMonth = sakaMonth +1;
+ }
+ return sakaMonth;
+
+}
+
+int KCalendarSystemIndic::day( const QDate &date ) const
+{
+ double jdAtStartOfGregYear;
+ int leapMonth, IndianYear, yday, sakaMonth, sakaDayOfMonth, mday;
+ int sakaYear = KCalendarSystemIndic::year(date); // Year in Saka era
+ jdAtStartOfGregYear = KCalendarSystemSaka::gregorianToJD( date.year(), 1, 1); // JD at start of Gregorian year
+ double julianDay=KCalendarSystemSaka::gregorianToJD( date.year(), date.month(), date.day());
+ yday = (int)(julianDay - jdAtStartOfGregYear); // Day number in Gregorian year (starting from 0)
+ if (yday < KCalendarSystemSaka::get_year_start()) {
+ // Day is at the end of the preceding Saka year
+ sakaYear -= 1;
+ leapMonth = KCalendarSystem::isLeapYear(date.year() - 1) ? 31 : 30; // Days in leapMonth this year, previous Gregorian year
+ yday += leapMonth + (31 * 5) + (30 * 3) + 10;
+ } else {
+ leapMonth = KCalendarSystem::isLeapYear(date.year()) ? 31 : 30; // Days in leapMonth this year
+ yday -= KCalendarSystemSaka::get_year_start();
+ }
+ if (yday < leapMonth) {
+ sakaMonth = 0;
+ sakaDayOfMonth = yday + 1;
+ } else {
+ mday = yday - leapMonth;
+ if (mday < (31 * 5)) {
+ sakaMonth = (int)floor(mday / 31) + 1;
+ sakaDayOfMonth = (mday % 31) + 1;
+ } else {
+ mday -= 31 * 5;
+ sakaMonth = (int)floor(mday / 30) + 6;
+ sakaDayOfMonth = (mday % 30) + 1;
+ }
+ }
+ return sakaDayOfMonth;
+}
+
+QDate KCalendarSystemIndic::addYears( const QDate &date, int nyears ) const
+{
+ QDate result = date;
+ int y = year( date ) + nyears;
+ setYMD( result, y, month( date ), day( date ) );
+ return result;
+}
+
+QDate KCalendarSystemIndic::addMonths( const QDate &date, int nmonths ) const
+{
+ return KCalendarSystem::addMonths( date, nmonths );
+}
+
+QDate KCalendarSystemIndic::addDays( const QDate &date, int ndays ) const
+{
+ return KCalendarSystem::addDays( date, ndays );
+}
+
+int KCalendarSystemIndic::monthsInYear( const QDate &date ) const
+{
+ Q_UNUSED( date )
+ return 12;
+}
+
+int KCalendarSystemIndic::weeksInYear( const QDate &date ) const
+{
+ return KCalendarSystem::weeksInYear( date );
+}
+
+int KCalendarSystemIndic::weeksInYear( int year ) const
+{
+ return KCalendarSystem::weeksInYear( year );
+}
+
+int KCalendarSystemIndic::daysInYear( const QDate &date ) const
+{
+ return KCalendarSystem::daysInYear( date );
+}
+
+int KCalendarSystemIndic::daysInMonth( const QDate &date ) const
+{
+ return KCalendarSystem::daysInMonth( date );
+}
+
+int KCalendarSystemIndic::daysInWeek( const QDate &date ) const
+{
+ Q_UNUSED( date );
+ return 7;
+}
+
+int KCalendarSystemIndic::dayOfYear( const QDate &date ) const
+{
+ //Base class takes the jd of the given date, and subtracts the jd of the first day of that year
+ //but in QDate 1 Jan -4713 is not a valid date, so special case it here.
+
+ // Don't bother with validity check here, not needed, leave to base class
+ if ( year( date ) == -4713 ) {
+ QDate secondDayOfYear;
+ if ( setDate( secondDayOfYear, -4713, 1, 2 ) ) {
+ return ( date.toJulianDay() - secondDayOfYear.toJulianDay() + 2 );
+ }
+ } else {
+ return KCalendarSystem::dayOfYear( date );
+ }
+
+ return -1;
+}
+
+int KCalendarSystemIndic::dayOfWeek( const QDate &date ) const
+{
+ return KCalendarSystem::dayOfWeek( date );
+}
+
+int KCalendarSystemIndic::weekNumber( const QDate &date, int * yearNum ) const
+{
+ return KCalendarSystem::weekNumber( date, yearNum );
+}
+
+bool KCalendarSystemIndic::isLeapYear( int year ) const
+{
+ // Use QDate's so we match it's weird changover from Indic to Julian
+ return QDate::isLeapYear( year );
+}
+
+bool KCalendarSystemIndic::isLeapYear( const QDate &date ) const
+{
+ return KCalendarSystem::isLeapYear( date );
+}
+
+QString KCalendarSystemIndic::monthName( int month, int year, MonthNameFormat format ) const
+{
+ Q_UNUSED( year );
+
+ if ( format == ShortNamePossessive ) {
+ switch ( month ) {
+ case 1:
+ return ki18nc( "of Chaitra", "of Chaitra" ).toString( locale() );
+ case 2:
+ return ki18nc( "of Vaisakha", "of Vaisakha" ).toString( locale() );
+ case 3:
+ return ki18nc( "of Jyaistha", "of Jyaistha" ).toString( locale() );
+ case 4:
+ return ki18nc( "of Asadha", "of Asadha" ).toString( locale() );
+ case 5:
+ return ki18nc( "of Sravana", "of Sravana" ).toString( locale() );
+ case 6:
+ return ki18nc( "of Bhadra", "of Bhadra" ).toString( locale() );
+ case 7:
+ return ki18nc( "of Asvina", "of Asvina" ).toString( locale() );
+ case 8:
+ return ki18nc( "of Kartika", "of Kartika" ).toString( locale() );
+ case 9:
+ return ki18nc( "of Agrahayana", "of Agrahayana" ).toString( locale() );
+ case 10:
+ return ki18nc( "of Pausa", "of Pausa" ).toString( locale() );
+ case 11:
+ return ki18nc( "of Magha", "of Magha" ).toString( locale() );
+ case 12:
+ return ki18nc( "of Phalguna", "of Phalguna" ).toString( locale() );
+ default:
+ return QString();
+ }
+ }
+
+ if ( format == LongNamePossessive ) {
+ switch ( month ) {
+ case 1:
+ return ki18n( "of Chaitra" ).toString( locale() );
+ case 2:
+ return ki18n( "of Vaisakha" ).toString( locale() );
+ case 3:
+ return ki18n( "of Jyaistha" ).toString( locale() );
+ case 4:
+ return ki18n( "of Asadha" ).toString( locale() );
+ case 5:
+ return ki18n( "of Sravana" ).toString( locale() );
+ case 6:
+ return ki18n( "of Bhadra" ).toString( locale() );
+ case 7:
+ return ki18n( "of Asvina" ).toString( locale() );
+ case 8:
+ return ki18n( "of Kartika" ).toString( locale() );
+ case 9:
+ return ki18n( "of Agrahayana" ).toString( locale() );
+ case 10:
+ return ki18n( "of Pausa" ).toString( locale() );
+ case 11:
+ return ki18n( "of Magha" ).toString( locale() );
+ case 12:
+ return ki18n( "of Phalguna" ).toString( locale() );
+ default:
+ return QString();
+ }
+ }
+
+ if ( format == ShortName ) {
+ switch ( month ) {
+ case 1:
+ return ki18nc( "Chaitra", "Chai" ).toString( locale() );
+ case 2:
+ return ki18nc( "Vaisakha", "Vai" ).toString( locale() );
+ case 3:
+ return ki18nc( "Jyaishtha", "Jyai" ).toString( locale() );
+ case 4:
+ return ki18nc( "Asadha", "Asa" ).toString( locale() );
+ case 5:
+ return ki18nc( "Sravana", "Sra" ).toString( locale() );
+ case 6:
+ return ki18nc( "Bhadra", "Bha" ).toString( locale() );
+ case 7:
+ return ki18nc( "Asvina", "Asvi" ).toString( locale() );
+ case 8:
+ return ki18nc( "Kartika", "Kar" ).toString( locale() );
+ case 9:
+ return ki18nc( "Agrahayana", "Agra" ).toString( locale() );
+ case 10:
+ return ki18nc( "Pausa", "Pausha" ).toString( locale() );
+ case 11:
+ return ki18nc( "Magha", "Magha" ).toString( locale() );
+ case 12:
+ return ki18nc( "Phalguna", "Phal" ).toString( locale() );
+ default:
+ return QString();
+ }
+ }
+
+ // Default to LongName
+ switch ( month ) {
+ case 1:
+ return ki18n( "Chaitra" ).toString( locale() );
+ case 2:
+ return ki18n( "Vaisakha" ).toString( locale() );
+ case 3:
+ return ki18n( "Jyaishtha" ).toString( locale() );
+ case 4:
+ return ki18n( "Asadha" ).toString( locale() );
+ case 5:
+ return ki18n( "Sravana" ).toString( locale() );
+ case 6:
+ return ki18n( "Bhadra" ).toString( locale() );
+ case 7:
+ return ki18n( "Asvina" ).toString( locale() );
+ case 8:
+ return ki18n( "Kartika" ).toString( locale() );
+ case 9:
+ return ki18n( "Agrahayana" ).toString( locale() );
+ case 10:
+ return ki18n( "Pausha" ).toString( locale() );
+ case 11:
+ return ki18n( "Magha" ).toString( locale() );
+ case 12:
+ return ki18n( "Phalguna" ).toString( locale() );
+ default:
+ return QString();
+ }
+}
+
+QString KCalendarSystemIndic::monthName( const QDate &date, MonthNameFormat format ) const
+{
+ return KCalendarSystem::monthName( date, format );
+}
+
+
+QString KCalendarSystemIndic::weekDayName( int weekDay, WeekDayNameFormat format ) const
+{
+ if ( format == ShortDayName ) {
+ switch ( weekDay ) {
+ case 1: return ki18nc( "Somvar", "Som" ).toString( locale() );
+ case 2: return ki18nc( "Mangalvar", "Mangal" ).toString( locale() );
+ case 3: return ki18nc( "Budhavar", "Budha" ).toString( locale() );
+ case 4: return ki18nc( "Brihaspativar", "Briha" ).toString( locale() );
+ case 5: return ki18nc( "Shukravar", "Shukra" ).toString( locale() );
+ case 6: return ki18nc( "Shanivar", "Shani" ).toString( locale() );
+ case 7: return ki18nc( "Ravivar", "Ravi" ).toString( locale() );
+ default: return QString();
+ }
+ }
+
+ switch ( weekDay ) {
+ case 1: return ki18n( "Somvar" ).toString( locale() );
+ case 2: return ki18n( "Mangalvar" ).toString( locale() );
+ case 3: return ki18n( "Budhavar" ).toString( locale() );
+ case 4: return ki18n( "Brihaspativar" ).toString( locale() );
+ case 5: return ki18n( "Shukravar" ).toString( locale() );
+ case 6: return ki18n( "Shanivar" ).toString( locale() );
+ case 7: return ki18n( "Ravivar" ).toString( locale() );
+ default: return QString();
+ }
+}
+
+QString KCalendarSystemIndic::weekDayName( const QDate &date, WeekDayNameFormat format ) const
+{
+ return KCalendarSystem::weekDayName( date, format );
+}
+
+QString KCalendarSystemIndic::yearString( const QDate &pDate, StringFormat format ) const
+{
+ return KCalendarSystem::yearString( pDate, format );
+}
+
+QString KCalendarSystemIndic::monthString( const QDate &pDate, StringFormat format ) const
+{
+ return KCalendarSystem::monthString( pDate, format );
+}
+
+QString KCalendarSystemIndic::dayString( const QDate &pDate, StringFormat format ) const
+{
+ return KCalendarSystem::dayString( pDate, format );
+}
+
+int KCalendarSystemIndic::yearStringToInteger( const QString &sNum, int &iLength ) const
+{
+ return KCalendarSystem::yearStringToInteger( sNum, iLength );
+}
+
+int KCalendarSystemIndic::monthStringToInteger( const QString &sNum, int &iLength ) const
+{
+ return KCalendarSystem::monthStringToInteger( sNum, iLength );
+}
+
+int KCalendarSystemIndic::dayStringToInteger( const QString &sNum, int &iLength ) const
+{
+ return KCalendarSystem::dayStringToInteger( sNum, iLength );
+}
+
+QString KCalendarSystemIndic::formatDate( const QDate &date, KLocale::DateFormat format ) const
+{
+ return KCalendarSystem::formatDate( date, format );
+}
+
+QDate KCalendarSystemIndic::readDate( const QString &str, bool *ok ) const
+{
+ return KCalendarSystem::readDate( str, ok );
+}
+
+QDate KCalendarSystemIndic::readDate( const QString &intstr, const QString &fmt, bool *ok ) const
+{
+ return KCalendarSystem::readDate( intstr, fmt, ok );
+}
+
+QDate KCalendarSystemIndic::readDate( const QString &str, KLocale::ReadDateFlags flags, bool *ok ) const
+{
+ return KCalendarSystem::readDate( str, flags, ok );
+}
+
+int KCalendarSystemIndic::weekStartDay() const
+{
+ return KCalendarSystem::weekStartDay();
+}
+
+int KCalendarSystemIndic::weekDayOfPray() const
+{
+ return 7; // sunday
+}
+
+bool KCalendarSystemIndic::isLunar() const
+{
+ return false;
+}
+
+bool KCalendarSystemIndic::isLunisolar() const
+{
+ return false;
+}
+
+bool KCalendarSystemIndic::isSolar() const
+{
+ return true;
+}
+
+bool KCalendarSystemIndic::isProleptic() const
+{
+ return false;
+}
+
+bool KCalendarSystemIndic::julianDayToDate( int jd, int &year, int &month, int &day ) const
+{
+ QDate date = QDate::fromJulianDay( jd );
+
+ if ( date.isValid() ) {
+ year = date.year();
+ month = date.month();
+ day = date.day();
+ }
+
+ return date.isValid();
+}
+
+bool KCalendarSystemIndic::dateToJulianDay( int year, int month, int day, int &jd ) const
+{
+ QDate date;
+
+ if ( date.setDate( year, month, day ) ) {
+ jd = date.toJulianDay();
+ return true;
+ }
+
+ return false;
+}
diff --git a/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.h b/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.h
new file mode 100644
index 0000000..510d6c5
--- /dev/null
+++ b/calendar/kde/kdelibs/kdecore/date/kcalendarsystemindic.h
@@ -0,0 +1,117 @@
+/*
+ Copyright (c) 2008 Santhosh Thottingal <santhosh.thottingal@gmail.com>
+
+ 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.
+*/
+
+#ifndef KCALENDARSYSTEMINDIC_H
+#define KCALENDARSYSTEMINDIC_H
+
+#include "kcalendarsystem.h"
+
+class KCalendarSystemIndicPrivate;
+
+/**
+ * @internal
+ * This is the Indic calendar implementation.
+ *
+ * The Indic calendar is the traditional Islamic calendar used in the Middle
+ * East.
+ *
+ * @b license GNU-LGPL v2+
+ *
+ * @see KLocale,KCalendarSystem
+ *
+ * @author Carlos Moro <cfmoro@correo.uniovi.es>
+ */
+class KDECORE_EXPORT KCalendarSystemIndic : public KCalendarSystem
+{
+public:
+ explicit KCalendarSystemIndic( const KLocale *locale = 0 );
+ virtual ~KCalendarSystemIndic();
+
+ virtual QString calendarType() const;
+
+ virtual QDate epoch() const;
+ virtual QDate earliestValidDate() const;
+ virtual QDate latestValidDate() const;
+ virtual bool isValid( int year, int month, int day ) const;
+ virtual bool isValid( const QDate &date ) const;
+
+ virtual bool setDate( QDate &date, int year, int month, int day ) const;
+ /** @deprecated */
+ virtual bool setYMD( QDate &date, int year, int month, int day ) const;
+
+ virtual int year( const QDate &date ) const;
+ virtual int month( const QDate &date ) const;
+ virtual int day( const QDate &date ) const;
+
+ virtual QDate addYears( const QDate &date, int nyears ) const;
+ virtual QDate addMonths( const QDate &date, int nmonths ) const;
+ virtual QDate addDays( const QDate &date, int ndays ) const;
+
+ virtual int monthsInYear( const QDate &date ) const;
+ virtual int weeksInYear( const QDate &date ) const;
+ virtual int weeksInYear( int year ) const;
+ virtual int daysInYear( const QDate &date ) const;
+ virtual int daysInMonth( const QDate &date ) const;
+ virtual int daysInWeek( const QDate &date ) const;
+
+ virtual int dayOfYear( const QDate &date ) const;
+ virtual int dayOfWeek( const QDate &date ) const;
+
+ virtual int weekNumber( const QDate &date, int *yearNum = 0 ) const;
+
+ virtual bool isLeapYear( int year ) const;
+ virtual bool isLeapYear( const QDate &date ) const;
+
+ virtual QString monthName( int month, int year, MonthNameFormat format = LongName ) const;
+ virtual QString monthName( const QDate &date, MonthNameFormat format = LongName ) const;
+
+ virtual QString weekDayName( int weekDay, WeekDayNameFormat format = LongDayName ) const;
+ virtual QString weekDayName( const QDate &date, WeekDayNameFormat format = LongDayName ) const;
+
+ virtual QString yearString( const QDate & pDate, StringFormat format = LongFormat ) const;
+ virtual QString monthString( const QDate &pDate, StringFormat format = LongFormat ) const;
+ virtual QString dayString( const QDate &pDate, StringFormat format = LongFormat ) const;
+
+ virtual int yearStringToInteger( const QString &sNum, int &iLength ) const;
+ virtual int monthStringToInteger( const QString &sNum, int &iLength ) const;
+ virtual int dayStringToInteger( const QString &sNum, int &iLength ) const;
+
+ virtual QString formatDate( const QDate &date, KLocale::DateFormat format = KLocale::LongDate ) const;
+
+ virtual QDate readDate( const QString &str, bool *ok = 0 ) const;
+ virtual QDate readDate( const QString &intstr, const QString &fmt, bool *ok = 0 ) const;
+ virtual QDate readDate( const QString &str, KLocale::ReadDateFlags flags, bool *ok = 0 ) const;
+
+ virtual int weekStartDay() const;
+ virtual int weekDayOfPray () const;
+
+ virtual bool isLunar() const;
+ virtual bool isLunisolar() const;
+ virtual bool isSolar() const;
+ virtual bool isProleptic() const;
+
+protected:
+ virtual bool julianDayToDate( int jd, int &year, int &month, int &day ) const;
+ virtual bool dateToJulianDay( int year, int month, int day, int &jd ) const;
+
+private:
+ KCalendarSystemIndicPrivate * const d;
+};
+
+#endif // KCALENDARSYSTEMINDIC_H
diff --git a/calendar/kde/kdelibs/kdecore/tests/kcalendartest.cpp b/calendar/kde/kdelibs/kdecore/tests/kcalendartest.cpp
new file mode 100644
index 0000000..1f30b5e
--- /dev/null
+++ b/calendar/kde/kdelibs/kdecore/tests/kcalendartest.cpp
@@ -0,0 +1,756 @@
+#include "qtest_kde.h"
+
+#include "kcalendarsystem.h"
+#include "kglobal.h"
+
+#include "kcalendartest.h"
+#include "kcalendartest.moc"
+#include "klocale.h"
+
+QTEST_KDEMAIN_CORE(KCalendarTest)
+
+void KCalendarTest::testTypes()
+{
+ const KCalendarSystem *calendar;
+ calendar = KCalendarSystem::create( QString("gregorian") );
+ QCOMPARE( calendar->calendarType(), QString("gregorian") );
+ calendar = KCalendarSystem::create( QString("hebrew") );
+ QCOMPARE( calendar->calendarType(), QString("hebrew") );
+ calendar = KCalendarSystem::create( QString("hijri") );
+ QCOMPARE( calendar->calendarType(), QString("hijri") );
+ calendar = KCalendarSystem::create( QString("jalali") );
+ QCOMPARE( calendar->calendarType(), QString("jalali") );
+ calendar = KCalendarSystem::create( QString("indic") );
+ QCOMPARE( calendar->calendarType(), QString("indic") );
+ calendar = KCalendarSystem::create( QString("invalid") );
+ QCOMPARE( calendar->calendarType(), QString("gregorian") );
+ calendar = KCalendarSystem::create( QString() );
+ QCOMPARE( calendar->calendarType(), QString("gregorian") );
+
+ QStringList lst = KCalendarSystem::calendarSystems();
+ QVERIFY( lst.contains("gregorian") );
+ QVERIFY( lst.contains("hebrew") );
+ QVERIFY( lst.contains("hijri") );
+ QVERIFY( lst.contains("jalali") );
+
+ QCOMPARE( KCalendarSystem::calendarLabel("gregorian"), QString("Gregorian") );
+ QCOMPARE( KCalendarSystem::calendarLabel("hebrew"), QString("Hebrew") );
+ QCOMPARE( KCalendarSystem::calendarLabel("hijri"), QString("Hijri") );
+ QCOMPARE( KCalendarSystem::calendarLabel("jalali"), QString("Jalali") );
+}
+
+void KCalendarTest::testLocale()
+{
+ KGlobal::locale()->setCalendar("gregorian");
+ const KCalendarSystem *calendar = KGlobal::locale()->calendar();
+ QCOMPARE( calendar->calendarType(), QString("gregorian") );
+ KGlobal::locale()->setCalendar("hebrew");
+ calendar = KGlobal::locale()->calendar();
+ QCOMPARE( calendar->calendarType(), QString("hebrew") );
+ KGlobal::locale()->setCalendar("hijri");
+ calendar = KGlobal::locale()->calendar();
+ QCOMPARE( calendar->calendarType(), QString("hijri") );
+ KGlobal::locale()->setCalendar("jalali");
+ calendar = KGlobal::locale()->calendar();
+ QCOMPARE( calendar->calendarType(), QString("jalali") );
+}
+
+void KCalendarTest::testGregorian()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "gregorian" ));
+ QDate testDate( 2005, 9, 10 );
+
+ QCOMPARE( calendar->dayOfYear( testDate ), 253 );
+
+ QVERIFY( calendar->setYMD( testDate, 2000, 3, 1 ) );
+ QCOMPARE( calendar->year( testDate ), 2000 );
+ QCOMPARE( calendar->month( testDate ), 3 );
+ QCOMPARE( calendar->day( testDate ), 1 );
+ QCOMPARE( calendar->daysInYear( testDate ), 366 );
+
+ QDate newDate = calendar->addYears( testDate, 4);
+ QCOMPARE( newDate.year(), 2004 );
+ QCOMPARE( calendar->daysInYear( newDate ), 366 );
+
+ newDate = calendar->addMonths( testDate, -4 );
+ QCOMPARE( newDate.year(), 1999 );
+ QCOMPARE( newDate.month(), 11 );
+ QCOMPARE( newDate.day(), 1 );
+
+ newDate = calendar->addDays( newDate, 20 );
+ QCOMPARE( newDate.year(), 1999 );
+ QCOMPARE( newDate.month(), 11 );
+ QCOMPARE( newDate.day(), 21 );
+}
+
+void KCalendarTest::testHijri()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "hijri" ));
+ QDate testDate( 2005, 9, 10 );
+
+ QCOMPARE( calendar->daysInYear(testDate), 355 );
+ QCOMPARE( calendar->daysInMonth(testDate), 29 );
+ QCOMPARE( calendar->weeksInYear(testDate.year()), 50 );
+ QCOMPARE( calendar->weekNumber(testDate), 31 );
+ QCOMPARE( calendar->dayOfYear(testDate), 213 );
+
+ QVERIFY( calendar->setYMD( testDate, 2000, 3, 1 ) );
+ QCOMPARE( calendar->year(testDate), 2000 );
+ QCOMPARE( calendar->month(testDate), 3 );
+ QCOMPARE( calendar->day(testDate), 1 );
+
+ QDate newDate = calendar->addYears(testDate, 4);
+ QCOMPARE( newDate.year(), 2566 );
+ QCOMPARE( calendar->daysInYear(newDate), 355 );
+
+ newDate = calendar->addMonths( testDate, -4 );
+ QCOMPARE( newDate.year(), 2561 );
+ QCOMPARE( newDate.month(), 11 );
+ QCOMPARE( newDate.day(), 10 );
+
+ newDate = calendar->addDays( newDate, 20 );
+ QCOMPARE( newDate.year(), 2561 );
+ QCOMPARE( newDate.month(), 11 );
+ QCOMPARE( newDate.day(), 30 );
+}
+
+
+void KCalendarTest::testGregorianBasic()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString("gregorian"));
+
+ QCOMPARE( calendar->calendarType(), QString("gregorian") );
+ QCOMPARE( KCalendarSystem::calendarLabel( QString("gregorian") ), QString("Gregorian") );
+
+ QEXPECT_FAIL("", "QDate is Julian, get right date", Continue);
+ QCOMPARE( calendar->epoch(), QDate( 1, 1, 1 ) );
+ QCOMPARE( calendar->earliestValidDate(), QDate( -4713, 1, 2 ) );
+ QCOMPARE( calendar->latestValidDate(), QDate( 9999, 12, 31 ) );
+
+ testValid( calendar, 10000, 13, 32, QDate( -5000, 1, 1 ) );
+
+ QCOMPARE( calendar->isLeapYear( 2007 ), false );
+ QCOMPARE( calendar->isLeapYear( 2008 ), true );
+ QCOMPARE( calendar->isLeapYear( 1900 ), false );
+ QCOMPARE( calendar->isLeapYear( 2000 ), true );
+ QCOMPARE( calendar->isLeapYear( QDate( 2007, 1, 1 ) ), false );
+ QCOMPARE( calendar->isLeapYear( QDate( 2008, 1, 1 ) ), true );
+
+ QCOMPARE( calendar->daysInWeek( QDate( 2007, 1, 1 ) ), 7 );
+ QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
+
+ testYear( calendar, QDate( 2007, 7, 9 ), 2007, QString("07"), QString("2007") );
+ testMonth( calendar, QDate( 2007, 7, 9 ), 7, QString("7"), QString("07") );
+ testDay( calendar, QDate( 2007, 7, 9 ), 9, QString("9"), QString("09") );
+
+ testWeekDayName( calendar, 6, QDate( 2007, 7, 28 ),
+ QString("Sat"), QString("Saturday") );
+ testMonthName( calendar, 12, 2007, QDate( 2007, 12, 20 ),
+ QString("Dec"), QString("December"),
+ QString("of Dec"), QString("of December") );
+
+ QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
+
+ QCOMPARE( calendar->weekStartDay(), 1 );
+ QCOMPARE( calendar->weekDayOfPray(), 7 );
+
+ QCOMPARE( calendar->isProleptic(), false );
+ QCOMPARE( calendar->isLunar(), false );
+ QCOMPARE( calendar->isLunisolar(), false );
+ QCOMPARE( calendar->isSolar(), true );
+}
+
+void KCalendarTest::testGregorianYmd()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString("gregorian"));
+ testYmd( calendar, 2007, 1, 1, QDate( 2007, 1, 1 ).toJulianDay() );
+}
+
+
+// Test Hijri Calendar System
+
+void KCalendarTest::testHijriBasic()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString("hijri"));
+
+ QCOMPARE( calendar->calendarType(), QString("hijri") );
+ QCOMPARE( KCalendarSystem::calendarLabel( QString("hijri") ), QString("Hijri") );
+
+ QCOMPARE( calendar->epoch(), QDate( 622, 7, 16 ) );
+ QCOMPARE( calendar->earliestValidDate(), QDate( 622, 7, 16 ) );
+ QCOMPARE( calendar->latestValidDate(), QDate( 10323, 10, 21) );
+
+ // Restore after Hijri converted
+ //testValid( calendar, 10000, 13, 31, QDate( 1, 1, 1 ) );
+
+ QCOMPARE( calendar->isLeapYear( 1427 ), false );
+ QCOMPARE( calendar->isLeapYear( 1428 ), true );
+ QCOMPARE( calendar->isLeapYear( QDate( 2007, 1, 1 ) ), false );
+ QCOMPARE( calendar->isLeapYear( QDate( 2008, 1, 1 ) ), true );
+
+ QCOMPARE( calendar->daysInWeek( QDate( 2007, 1, 1 ) ), 7 );
+ QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
+
+ testYear( calendar, QDate( 2005, 9, 10 ), 1426, QString("26"), QString("1426") );
+ testMonth( calendar, QDate( 2005, 9, 10 ), 8, QString("8"), QString("08") );
+ testDay( calendar, QDate( 2005, 9, 10 ), 6, QString("6"), QString("06") );
+
+ testWeekDayName( calendar, 6, QDate( 2005, 9, 10 ),
+ QString("Sab"), QString("Yaum al-Sabt") );
+ testMonthName( calendar, 12, 1428, QDate( 2007, 12, 20 ),
+ QString("Hijjah"), QString("Thu al-Hijjah"),
+ QString("of Hijjah"), QString("of Thu al-Hijjah") );
+
+ QCOMPARE( calendar->monthsInYear( QDate( 2005, 9, 10 ) ), 12 );
+
+ QCOMPARE( calendar->weekStartDay(), 1 );
+ QCOMPARE( calendar->weekDayOfPray(), 5 );
+
+ QCOMPARE( calendar->isProleptic(), false );
+ QCOMPARE( calendar->isLunar(), true );
+ QCOMPARE( calendar->isLunisolar(), false );
+ QCOMPARE( calendar->isSolar(), false );
+}
+
+void KCalendarTest::testHijriYmd()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString("hijri"));
+ testYmd( calendar, 1426, 8, 6, QDate( 2005, 9, 10 ).toJulianDay() );
+}
+
+
+// Jalali Calendar System
+
+void KCalendarTest::testJalaliBasic()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "jalali" ));
+
+ QCOMPARE( calendar->calendarType(), QString("jalali") );
+ QCOMPARE( KCalendarSystem::calendarLabel( QString("jalali") ), QString("Jalali") );
+
+ QCOMPARE( calendar->epoch(), QDate( 622, 3, 19 ) );
+ QCOMPARE( calendar->earliestValidDate(), QDate( 622, 3, 19 ) );
+ QCOMPARE( calendar->latestValidDate(), QDate( 10621, 3, 17 ) );
+
+ testValid( calendar, 10000, 13, 32, QDate( 1, 1, 1 ) );
+
+ QCOMPARE( calendar->isLeapYear( 1386 ), false );
+ QCOMPARE( calendar->isLeapYear( 1387 ), true );
+ QCOMPARE( calendar->isLeapYear( QDate( 2008, 1, 1 ) ), false );
+ QEXPECT_FAIL("", "Not working right, 2009-01-01 should be 1387, verify", Continue);
+ QCOMPARE( calendar->isLeapYear( QDate( 2009, 1, 1 ) ), true );
+
+ QCOMPARE( calendar->daysInWeek( QDate( 2007, 1, 1 ) ), 7 );
+ QCOMPARE( calendar->monthsInYear( QDate( 2007, 1, 1 ) ), 12 );
+
+ testYear( calendar, QDate( 2005, 8, 31 ), 1384, QString("84"), QString("1384") );
+ testMonth( calendar, QDate( 2005, 8, 31 ), 6, QString("6"), QString("06") );
+ testDay( calendar, QDate( 2005, 8, 31 ), 9, QString("9"), QString("09") );
+
+ testWeekDayName( calendar, 3, QDate( 2005, 8, 31 ),
+ QString("4sh"), QString("Chahar shanbe") );
+ testMonthName( calendar, 6, 1384, QDate( 2005, 8, 31 ),
+ QString("Sha"), QString("Shahrivar"),
+ QString("of Sha"), QString("of Shahrivar") );
+
+ QCOMPARE( calendar->monthsInYear( QDate( 2005, 8, 31 ) ), 12 );
+
+ QCOMPARE( calendar->weekStartDay(), 1 );
+ QCOMPARE( calendar->weekDayOfPray(), 5 );
+
+ QCOMPARE( calendar->isProleptic(), false );
+ QCOMPARE( calendar->isLunar(), false );
+ QCOMPARE( calendar->isLunisolar(), false );
+ QCOMPARE( calendar->isSolar(), true );
+}
+
+void KCalendarTest::testJalaliYmd()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create( QString("jalali") );
+ testYmd( calendar, 1384, 6, 9, QDate( 2005, 8, 31 ).toJulianDay() );
+}
+
+// generic test functions, call from calendar system specific ones
+
+// Simply tests valid ranges of ymd values, testYmd covers all other dates
+void KCalendarTest::testValid( const KCalendarSystem *calendar, int highInvalidYear,
+ int highInvalidMonth, int highInvalidDay, QDate invalidDate )
+{
+ // min/max year
+ QCOMPARE( calendar->isValid( 0, 1, 1 ), false );
+ QCOMPARE( calendar->isValid( highInvalidYear, 1, 1 ), false );
+
+ // min/max month
+ QCOMPARE( calendar->isValid( 1, 0, 1 ), false );
+ QCOMPARE( calendar->isValid( 1, highInvalidMonth, 1 ), false );
+
+ // min/max day
+ QCOMPARE( calendar->isValid( 1, 1, 0 ), false );
+ QCOMPARE( calendar->isValid( 1, 1, highInvalidDay ), false );
+
+ QCOMPARE( calendar->isValid( 1, 1, 1 ), true );
+
+ QCOMPARE( calendar->isValid( invalidDate ), false );
+ QCOMPARE( calendar->isValid( QDate( 2000, 1, 1 ) ), true );
+}
+
+void KCalendarTest::testYmd( const KCalendarSystem *calendar, int y, int m, int d, int jd )
+{
+ QDate testDate1 = QDate::fromJulianDay( jd );
+ QCOMPARE( calendar->year( testDate1 ), y );
+ QCOMPARE( calendar->month( testDate1 ), m );
+ QCOMPARE( calendar->day( testDate1 ), d );
+
+ QDate testDate2;
+ QVERIFY( calendar->setYMD( testDate2, y, m, d ) );
+ QCOMPARE( testDate1, testDate2 );
+}
+
+void KCalendarTest::testYear( const KCalendarSystem *calendar, QDate date,
+ int year, QString shortString, QString longString )
+{
+ QCOMPARE( calendar->year( date ), year );
+ QCOMPARE( calendar->yearString( date, KCalendarSystem::ShortFormat ), shortString );
+ QCOMPARE( calendar->yearString( date, KCalendarSystem::LongFormat ), longString );
+ int i;
+ QCOMPARE( calendar->yearStringToInteger( longString, i ), year );
+ QCOMPARE( i, longString.length() );
+}
+
+void KCalendarTest::testMonth( const KCalendarSystem *calendar, QDate date,
+ int month, QString shortString, QString longString )
+{
+ QCOMPARE( calendar->month( date ), month );
+ QCOMPARE( calendar->monthString( date, KCalendarSystem::ShortFormat ), shortString );
+ QCOMPARE( calendar->monthString( date, KCalendarSystem::LongFormat ), longString );
+ int i;
+ QCOMPARE( calendar->monthStringToInteger( longString, i ), month );
+ QCOMPARE( i, longString.length() );
+}
+
+void KCalendarTest::testDay( const KCalendarSystem *calendar, QDate date,
+ int day, QString shortString, QString longString )
+{
+ QCOMPARE( calendar->day( date ), day );
+ QCOMPARE( calendar->dayString( date, KCalendarSystem::ShortFormat ), shortString );
+ QCOMPARE( calendar->dayString( date, KCalendarSystem::LongFormat ), longString );
+ int i;
+ QCOMPARE( calendar->dayStringToInteger( longString, i ), day );
+ QCOMPARE( i, longString.length() );
+}
+
+// Pass in the week day number, the equivalent QDate, and the short and long day names
+// e.g. testWeekDayName( cal, 6, QDate(y,m,d), QString("Monday"), QString("Mon") )
+
+void KCalendarTest::testWeekDayName( const KCalendarSystem *calendar, int weekDay, QDate date,
+ QString shortName, QString longName )
+{
+ QCOMPARE( calendar->weekDayName( weekDay, KCalendarSystem::ShortDayName ), shortName );
+ QCOMPARE( calendar->weekDayName( weekDay, KCalendarSystem::LongDayName ), longName );
+ QCOMPARE( calendar->weekDayName( weekDay ), longName );
+
+ // Test week day < min
+ QCOMPARE( calendar->weekDayName( 0, KCalendarSystem::ShortDayName ), QString() );
+ QCOMPARE( calendar->weekDayName( 0, KCalendarSystem::LongDayName ), QString() );
+
+ // Test week day > max
+ QCOMPARE( calendar->weekDayName( calendar->daysInWeek( date ) + 1, KCalendarSystem::ShortDayName ), QString() );
+ QCOMPARE( calendar->weekDayName( calendar->daysInWeek( date ) + 1, KCalendarSystem::LongDayName ), QString() );
+
+ // QDate parameter tests, so always in valid range
+ QCOMPARE( calendar->weekDayName( date, KCalendarSystem::ShortDayName ), shortName );
+ QCOMPARE( calendar->weekDayName( date, KCalendarSystem::LongDayName ), longName );
+ QCOMPARE( calendar->weekDayName( date ), longName );
+}
+
+void KCalendarTest::testMonthName( const KCalendarSystem *calendar, int month, int year, QDate date,
+ QString shortName, QString longName,
+ QString shortNamePossessive, QString longNamePossessive )
+{
+ QCOMPARE( calendar->monthName( month, year, KCalendarSystem::ShortName ), shortName );
+ QCOMPARE( calendar->monthName( month, year, KCalendarSystem::LongName ), longName );
+ QCOMPARE( calendar->monthName( month, year, KCalendarSystem::ShortNamePossessive ),
+ shortNamePossessive );
+ QCOMPARE( calendar->monthName( month, year, KCalendarSystem::LongNamePossessive ),
+ longNamePossessive );
+ QCOMPARE( calendar->monthName( month, year ), longName );
+
+ // Test month < min
+ QCOMPARE( calendar->monthName( 0, year, KCalendarSystem::ShortName ), QString() );
+ QCOMPARE( calendar->monthName( 0, year, KCalendarSystem::LongName ), QString() );
+ QCOMPARE( calendar->monthName( 0, year, KCalendarSystem::ShortName ), QString() );
+ QCOMPARE( calendar->monthName( 0, year, KCalendarSystem::LongName ), QString() );
+
+ // Test month > max
+ QCOMPARE( calendar->monthName( calendar->monthsInYear( date ) + 1, year,
+ KCalendarSystem::ShortName ), QString() );
+ QCOMPARE( calendar->monthName( calendar->monthsInYear( date ) + 1, year,
+ KCalendarSystem::LongName ), QString() );
+ QCOMPARE( calendar->monthName( calendar->monthsInYear( date ) + 1, year,
+ KCalendarSystem::ShortName ), QString() );
+ QCOMPARE( calendar->monthName( calendar->monthsInYear( date ) + 1, year,
+ KCalendarSystem::LongName ), QString() );
+
+ // QDate parameter tests, so always in valid range
+ QCOMPARE( calendar->monthName( date, KCalendarSystem::ShortName ), shortName );
+ QCOMPARE( calendar->monthName( date, KCalendarSystem::LongName ), longName );
+ QCOMPARE( calendar->monthName( date, KCalendarSystem::ShortNamePossessive ),
+ shortNamePossessive );
+ QCOMPARE( calendar->monthName( date, KCalendarSystem::LongNamePossessive ),
+ longNamePossessive );
+ QCOMPARE( calendar->monthName( date ), longName );
+}
+
+
+// Tests to compare new base methods are equal to QDate for Gregorian case
+
+
+void KCalendarTest::testQDateYearMonthDay()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "gregorian" ));
+
+ testQDateYMD( calendar, 2000, 1, 1 );
+ testQDateYMD( calendar, 2000, 2, 28 );
+ testQDateYMD( calendar, 2000, 2, 29 );
+ testQDateYMD( calendar, 2000, 6, 15 );
+ testQDateYMD( calendar, 2000, 12, 31 );
+
+ testQDateYMD( calendar, 9999, 1, 1 );
+ testQDateYMD( calendar, 9999, 6, 15 );
+ testQDateYMD( calendar, 9999, 12, 31 );
+
+ testQDateYMD( calendar, 1, 1, 1 );
+ testQDateYMD( calendar, 1, 6, 15 );
+ testQDateYMD( calendar, 1, 12, 31 );
+
+ testQDateYMD( calendar, -4713, 1, 2 );
+ testQDateYMD( calendar, -4713, 6, 15 );
+ testQDateYMD( calendar, -4713, 12, 31 );
+}
+
+void KCalendarTest::testQDateYMD( const KCalendarSystem *calendar, int y, int m, int d )
+{
+ QDate testDate;
+
+ calendar->setDate( testDate, y, m, d );
+ QCOMPARE( calendar->year( testDate ), testDate.year() );
+ QCOMPARE( calendar->month( testDate ), testDate.month() );
+ QCOMPARE( calendar->day( testDate ), testDate.day() );
+}
+
+void KCalendarTest::testQDateAddYears()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "gregorian" ));
+
+ QDate testDate;
+
+ calendar->setDate( testDate, 2000, 1, 1 );
+ QCOMPARE( calendar->addYears( testDate, -1 ), testDate.addYears( -1 ) );
+ QCOMPARE( calendar->addYears( testDate, 1 ), testDate.addYears( 1 ) );
+
+ calendar->setDate( testDate, 2000, 2, 29 );
+ QCOMPARE( calendar->addYears( testDate, 1 ), testDate.addYears( 1 ) );
+
+ calendar->setDate( testDate, -2000, 1, 1 );
+ QCOMPARE( calendar->addYears( testDate, -1 ), testDate.addYears( -1 ) );
+ QCOMPARE( calendar->addYears( testDate, 1 ), testDate.addYears( 1 ) );
+}
+
+void KCalendarTest::testQDateAddMonths()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "gregorian" ));
+
+ QDate testDate;
+
+ calendar->setDate( testDate, 2000, 1, 1 );
+ QCOMPARE( calendar->addMonths( testDate, -1 ), testDate.addMonths( -1 ) );
+ QCOMPARE( calendar->addMonths( testDate, 1 ), testDate.addMonths( 1 ) );
+
+ calendar->setDate( testDate, 2000, 3, 1 );
+ QCOMPARE( calendar->addMonths( testDate, -1 ), testDate.addMonths( -1 ) );
+ QCOMPARE( calendar->addMonths( testDate, 1 ), testDate.addMonths( 1 ) );
+
+ calendar->setDate( testDate, 2000, 12, 1 );
+ QCOMPARE( calendar->addMonths( testDate, -1 ), testDate.addMonths( -1 ) );
+ QCOMPARE( calendar->addMonths( testDate, 1 ), testDate.addMonths( 1 ) );
+
+ calendar->setDate( testDate, 2000, 1, 1 );
+ QCOMPARE( calendar->addMonths( testDate, -30 ), testDate.addMonths( -30 ) );
+ QCOMPARE( calendar->addMonths( testDate, 30 ), testDate.addMonths( 30 ) );
+
+ calendar->setDate( testDate, -2000, 1, 1 );
+ QCOMPARE( calendar->addMonths( testDate, -1 ), testDate.addMonths( -1 ) );
+ QCOMPARE( calendar->addMonths( testDate, 1 ), testDate.addMonths( 1 ) );
+
+ calendar->setDate( testDate, -2000, 3, 1 );
+ QCOMPARE( calendar->addMonths( testDate, -1 ), testDate.addMonths( -1 ) );
+ QCOMPARE( calendar->addMonths( testDate, 1 ), testDate.addMonths( 1 ) );
+
+ calendar->setDate( testDate, -2000, 12, 1 );
+ QCOMPARE( calendar->addMonths( testDate, -1 ), testDate.addMonths( -1 ) );
+ QCOMPARE( calendar->addMonths( testDate, 1 ), testDate.addMonths( 1 ) );
+
+ calendar->setDate( testDate, -2000, 1, 1 );
+ QCOMPARE( calendar->addMonths( testDate, -30 ), testDate.addMonths( -30 ) );
+ QCOMPARE( calendar->addMonths( testDate, 30 ), testDate.addMonths( 30 ) );
+}
+
+void KCalendarTest::testQDateAddDays()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "gregorian" ));
+
+ QDate testDate;
+
+ calendar->setDate( testDate, 2000, 1, 1 );
+ QCOMPARE( calendar->addDays( testDate, -1 ), testDate.addDays( -1 ) );
+ QCOMPARE( calendar->addDays( testDate, 1 ), testDate.addDays( 1 ) );
+
+ calendar->setDate( testDate, -2000, 1, 1 );
+ QCOMPARE( calendar->addDays( testDate, -1 ), testDate.addDays( -1 ) );
+ QCOMPARE( calendar->addDays( testDate, 1 ), testDate.addDays( 1 ) );
+}
+
+void KCalendarTest::testQDateDaysInYear()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "gregorian" ));
+
+ QDate testDate;
+
+ calendar->setDate( testDate, 1900, 1, 1 );
+ QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
+ calendar->setDate( testDate, 1999, 1, 1 );
+ QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
+ calendar->setDate( testDate, 2000, 1, 1 );
+ QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
+ calendar->setDate( testDate, 2001, 1, 1 );
+ QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
+ calendar->setDate( testDate, 2002, 1, 1 );
+ QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
+ calendar->setDate( testDate, 2003, 1, 1 );
+ QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
+ calendar->setDate( testDate, 2004, 1, 1 );
+ QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
+ calendar->setDate( testDate, 2005, 1, 1 );
+ QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
+
+ calendar->setDate( testDate, -4700, 1, 1 );
+ QEXPECT_FAIL("", "Returns 365 instead of 366", Continue);
+ QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
+ calendar->setDate( testDate, -4000, 1, 1 );
+ QEXPECT_FAIL("", "Returns 365 instead of 366", Continue);
+ QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
+
+ calendar->setDate( testDate, 1, 1, 1 );
+ QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
+
+ calendar->setDate( testDate, 9996, 1, 1 );
+ QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
+ calendar->setDate( testDate, 9999, 1, 1 );
+ QCOMPARE( calendar->daysInYear( testDate ), testDate.daysInYear() );
+}
+
+
+void KCalendarTest::testQDateDaysInMonth()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "gregorian" ));
+
+ QDate testDate;
+
+ // Test all months
+ calendar->setDate( testDate, 2000, 1, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+ calendar->setDate( testDate, 2000, 2, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+ calendar->setDate( testDate, 2000, 3, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+ calendar->setDate( testDate, 2000, 4, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+ calendar->setDate( testDate, 2000, 5, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+ calendar->setDate( testDate, 2000, 6, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+ calendar->setDate( testDate, 2000, 7, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+ calendar->setDate( testDate, 2000, 8, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+ calendar->setDate( testDate, 2000, 9, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+ calendar->setDate( testDate, 2000, 10, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+ calendar->setDate( testDate, 2000, 11, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+ calendar->setDate( testDate, 2000, 12, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+
+ // Test Feb in leap and normal years
+ calendar->setDate( testDate, 2000, 2, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+ calendar->setDate( testDate, 2001, 2, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+
+ // Test max date
+ calendar->setDate( testDate, 9999, 12, 1 );
+ QCOMPARE( calendar->daysInMonth( testDate ), testDate.daysInMonth() );
+}
+
+void KCalendarTest::testQDateDayOfYear()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "gregorian" ));
+
+ QDate testDate;
+
+ calendar->setDate( testDate, 2000, 1, 1 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, 2000, 2, 29 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, 2000, 6, 1 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, 2000, 12, 1 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, 2000, 12, 31 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+
+ calendar->setDate( testDate, -2000, 1, 1 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, -2000, 2, 29 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, -2000, 6, 1 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, -2000, 12, 1 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, -2000, 12, 31 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+
+ calendar->setDate( testDate, -4713, 1, 2 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, -4713, 2, 29 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, -4713, 6, 1 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, -4713, 12, 1 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, -4713, 12, 31 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+
+ calendar->setDate( testDate, 9999, 1, 1 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, 9999, 2, 29 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, 9999, 6, 1 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, 9999, 12, 1 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+ calendar->setDate( testDate, 9999, 12, 31 );
+ QCOMPARE( calendar->dayOfYear( testDate ), testDate.dayOfYear() );
+
+}
+
+void KCalendarTest::testQDateDayOfWeek()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "gregorian" ));
+
+ QDate testDate;
+
+ calendar->setDate( testDate, 2000, 1, 1 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, 2000, 1, 2 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, 2000, 1, 3 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, 2000, 1, 4 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, 2000, 1, 5 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, 2000, 1, 6 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, 2000, 1, 7 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+
+ calendar->setDate( testDate, -4713, 1, 2 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, -4713, 1, 3 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, -4713, 1, 4 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, -4713, 1, 5 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, -4713, 1, 6 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, -4713, 1, 7 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, -4713, 1, 8 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+
+ calendar->setDate( testDate, 9999, 1, 1 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, 9999, 1, 2 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, 9999, 1, 3 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, 9999, 1, 4 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, 9999, 1, 5 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, 9999, 1, 6 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+ calendar->setDate( testDate, 9999, 1, 7 );
+ QCOMPARE( calendar->dayOfWeek( testDate ), testDate.dayOfWeek() );
+}
+
+// Don'r really need this as Gregorian currently uses QDate directly
+void KCalendarTest::testQDateIsLeapYear()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "gregorian" ));
+
+ QDate testDate;
+
+ calendar->setDate( testDate, 2000, 1, 1 );
+ QCOMPARE( calendar->isLeapYear( 2000 ), testDate.isLeapYear( 2000 ) );
+ QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( 2000 ) );
+ calendar->setDate( testDate, 2001, 1, 1 );
+ QCOMPARE( calendar->isLeapYear( 2001 ), testDate.isLeapYear( 2001 ) );
+ QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( 2001 ) );
+ calendar->setDate( testDate, 2004, 1, 1 );
+ QCOMPARE( calendar->isLeapYear( 2004 ), testDate.isLeapYear( 2004 ) );
+ QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( 2004 ) );
+
+ calendar->setDate( testDate, 1900, 1, 1 );
+ QCOMPARE( calendar->isLeapYear( 1900 ), testDate.isLeapYear( 1900 ) );
+ QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( 1900 ) );
+ calendar->setDate( testDate, 1901, 1, 1 );
+ QCOMPARE( calendar->isLeapYear( 1901 ), testDate.isLeapYear( 1901 ) );
+ QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( 1901 ) );
+ calendar->setDate( testDate, 1904, 1, 1 );
+ QCOMPARE( calendar->isLeapYear( 1904 ), testDate.isLeapYear( 1904 ) );
+ QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( 1904 ) );
+
+ calendar->setDate( testDate, -2000, 1, 1 );
+ QCOMPARE( calendar->isLeapYear( -2000 ), testDate.isLeapYear( -2000 ) );
+ QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( -2000 ) );
+ calendar->setDate( testDate, -2001, 1, 1 );
+ QCOMPARE( calendar->isLeapYear( -2001 ), testDate.isLeapYear( -2001 ) );
+ QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( -2001 ) );
+ calendar->setDate( testDate, -2004, 1, 1 );
+ QCOMPARE( calendar->isLeapYear( -2004 ), testDate.isLeapYear( -2004 ) );
+ QCOMPARE( calendar->isLeapYear( testDate ), testDate.isLeapYear( -2004 ) );
+}
+
+
+// Temporary tests to compare existing code to replacement code
+
+
+void KCalendarTest::testJalaliCompare()
+{
+ const KCalendarSystem *calendar = KCalendarSystem::create(QString( "jalali" ));
+
+ testCompare( calendar, 2000, 1, 1 );
+}
+
+void KCalendarTest::testCompare( const KCalendarSystem *calendar, int year, int month, int day )
+{
+ QDate dateOld, dateNew;
+ calendar->setYMD( dateOld, year, month, day );
+ calendar->setDate( dateNew, year, month, day );
+ QCOMPARE( dateOld, dateNew );
+ QCOMPARE( calendar->daysInYear( dateNew ), dateNew.daysInYear() );
+}