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

KDECore

kcalendarsystemjalali.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2002-2003 Arash Bijanzadeh  and FarsiKDE Project <www.farsikde.org>
00003     Contact: Arash Bijanzadeh <a.bijanzadeh@linuxiran.org>
00004     Copyright (c) 2007 John Layt <john@layt.net>
00005 
00006     This program is part of FarsiKDE
00007 
00008     FarsiKDE is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     FarsiKDE is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022  */
00023 
00024 
00025 #include "kcalendarsystemjalali.h"
00026 
00027 #include <QtCore/QDate>
00028 #include <QtCore/QCharRef>
00029 #include <math.h>
00030 
00031 #include <kglobal.h>
00032 #include <klocale.h>
00033 #include <kdebug.h>
00034 #include <stdio.h>
00035 
00036 
00037 //===========================================================================
00038 //  This section holds the old Jalali <=> jd <=> Gregorian conversion code
00039 //  Delete once conversion to new code complete and fully tested
00040 //===========================================================================
00041 
00042 static const int  gMonthDay[2][13] =
00043     {
00044         {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
00045         {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
00046     };
00047 
00048 static const    int     jMonthDay[2][13] =
00049     {
00050         {0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29},
00051         {0, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30},
00052     };
00053 
00054 typedef struct
00055 {
00056     int day;
00057     int mon;
00058     int year;
00059 } SDATE;
00060 
00061 // converting funcs from
00062 
00063 static int Ceil( float number )
00064 {
00065     int ret;
00066 
00067     if( number > 0 ) {
00068         number += 0.5;
00069     }
00070     ret = ( int ) number;
00071 
00072     return ret;
00073 }
00074 
00075 static long jalali_jdn( int year, int month, int day )
00076 {
00077     const long PERSIAN_EPOCH = 1948321; /* The JDN of 1 Farvardin 1*/
00078     int epbase;
00079     long epyear;
00080     long mdays;
00081     long jdn;
00082 
00083     epbase = year - 474;
00084     epyear = 474 + ( epbase % 2820 );
00085     if ( month <= 7 ) {
00086         mdays = ( month - 1 ) * 31;
00087     } else {
00088         mdays = ( month - 1 ) * 30 + 6;
00089     }
00090     jdn = day + mdays ;
00091     jdn += ( ( ( epyear * 682 ) - 110 ) / 2816 ) ;
00092     jdn += ( epyear - 1 ) * 365;
00093     jdn += ( epbase / 2820 ) * 1029983 ;
00094     jdn += ( PERSIAN_EPOCH - 1 );
00095 
00096     return jdn;
00097 }
00098 
00099 
00100 static SDATE jdn_jalali( long jdn )
00101 {
00102     static SDATE ret;
00103     int day, month, year;
00104     int iYear, iMonth, iDay;
00105     int depoch;
00106     int cycle;
00107     int cyear;
00108     int ycycle;
00109     int aux1, aux2;
00110     int yday;
00111 
00112     day = 1;
00113     month = 1;
00114     year = 475;
00115     depoch = jdn - jalali_jdn( year, month, day );
00116     cycle = ( int ) ( depoch / 1029983 );
00117     cyear = depoch % 1029983;
00118     if( cyear == 1029982 ) {
00119         ycycle = 2820;
00120     } else {
00121         aux1 = cyear / 366;
00122         aux2 = cyear % 366;
00123         ycycle = ( ( ( 2134 * aux1 ) + ( 2816 * aux2 ) + 2815 ) / 1028522 ) + aux1 + 1;
00124     }
00125     iYear = ycycle + ( 2820 * cycle ) + 474;
00126     if ( iYear <= 0 ) {
00127         iYear = iYear - 1;
00128     }
00129     year = iYear;
00130     yday = ( jdn - jalali_jdn( year, month, day ) ) + 1;
00131     if( yday <= 186 ) {
00132         iMonth = Ceil( ( yday - 1 ) / 31 );
00133     } else {
00134         iMonth = Ceil( ( yday - 7 ) / 30 );
00135     }
00136     iMonth++;
00137     month = iMonth;
00138     iDay = ( jdn - jalali_jdn( year, month, day ) ) + 1;
00139     ret.day = iDay;
00140     ret.mon = iMonth;
00141     ret.year = iYear;
00142 
00143     return ret;
00144 }
00145 
00146 static long civil_jdn( int year, int month, int day )
00147 {
00148     long jdn = ( ( 1461 * ( year + 4800 + ( ( month - 14 ) / 12 ) ) ) / 4 )
00149                + ( ( 367 * ( month - 2 - 12 * ( ( ( month - 14 ) / 12 ) ) ) ) / 12 )
00150                - ( ( 3 * ( ( ( year + 4900 + ( ( month - 14 ) / 12 ) ) / 100 ) ) ) / 4 )
00151                + day - 32075;
00152 
00153     return jdn;
00154 }
00155 
00156 static SDATE jdn_civil( long jdn )
00157 {
00158     long l, n, i, j;
00159     static SDATE ret;
00160     int iday, imonth, iyear;
00161 
00162     l = jdn + 68569;
00163     n = ( ( 4 * l ) / 146097 );
00164     l = l - ( ( 146097 * n + 3 ) / 4 );
00165     i = ( ( 4000 * ( l + 1 ) ) / 1461001 );
00166     l = l - ( ( 1461 * i ) / 4 ) + 31;
00167     j = ( ( 80 * l ) / 2447 );
00168     iday = l - ( ( 2447 * j ) / 80 );
00169     l = ( j / 11 );
00170     imonth = j + 2 - 12 * l;
00171     iyear = 100 * ( n - 49 ) + i + l;
00172     ret.day = iday;
00173     ret.mon = imonth;
00174     ret.year = iyear;
00175 
00176     return ( ret );
00177 }
00178 
00179 static SDATE *jalaliToGregorian( int y, int m, int d )
00180 {
00181     static SDATE sd;
00182 
00183     long jday = jalali_jdn( y, m, d );
00184     sd = jdn_civil( jday );
00185 
00186     return ( &sd );
00187 }
00188 
00189 static SDATE *gregorianToJalali( int y, int m, int d )
00190 {
00191     static SDATE sd;
00192 
00193     long   jdn = civil_jdn( y, m, d );//QDate::gregorianToJulian(y, m, d);
00194     sd = jdn_jalali( jdn );
00195 
00196     return( &sd );
00197 }
00198 
00199 static void gregorianToJalali( const QDate &date, int *pYear, int *pMonth, int *pDay )
00200 {
00201     SDATE * sd;
00202 
00203     sd = gregorianToJalali( date.year(), date.month(), date.day() );
00204     if ( pYear ) {
00205         * pYear = sd->year;
00206     }
00207     if ( pMonth ) {
00208         * pMonth = sd->mon;
00209     }
00210     if ( pDay ) {
00211         * pDay = sd->day;
00212     }
00213 }
00214 
00215 // End of converting functions
00216 
00217 static int isJalaliLeap( int year )
00218 {
00219     int     tmp;
00220 
00221     tmp = year % 33;
00222     if ( tmp == 1 || tmp == 5 || tmp == 9 || tmp == 13 || tmp == 17 || tmp == 22 || tmp == 26 || tmp == 30 ) {
00223         return 1;
00224     } else {
00225         return 0;
00226     }
00227 }
00228 
00229 static int hndays( int m, int y )
00230 {
00231     return jMonthDay[isJalaliLeap( y )][m];
00232 }
00233 
00234 
00235 //===========================================================================
00236 
00237 
00238 KCalendarSystemJalali::KCalendarSystemJalali( const KLocale * locale )
00239                       : KCalendarSystem( locale ), d( 0 )
00240 {
00241 }
00242 
00243 KCalendarSystemJalali::~KCalendarSystemJalali()
00244 {
00245 }
00246 
00247 QString KCalendarSystemJalali::calendarType() const
00248 {
00249     return QLatin1String( "jalali" );
00250 }
00251 
00252 QDate KCalendarSystemJalali::epoch() const
00253 {
00254     // 19 March 622 in the Julian calendar
00255     return QDate::fromJulianDay( 1948321 );
00256 }
00257 
00258 QDate KCalendarSystemJalali::earliestValidDate() const
00259 {
00260     // 19 March 622 in the Julian calendar
00261     return KCalendarSystem::earliestValidDate();
00262 }
00263 
00264 QDate KCalendarSystemJalali::latestValidDate() const
00265 {
00266     // Set to last day of year 9999 until confirm date formats & widets support > 9999
00267     // Last day of Jalali year 9999 is 9999-12-29
00268     // Which in Gregorian is 10621-03-17
00269     // Which is jd xxxx FIXME Find out jd and use that instead
00270     // Can't call setDate() as it creates circular reference!
00271     return QDate( 10621, 3, 17 );
00272 }
00273 
00274 bool KCalendarSystemJalali::isValid( int y, int month, int day ) const
00275 {
00276     // taken from setYMD below, adapted to use new methods
00277     if ( y < year( earliestValidDate() ) || y > year( latestValidDate() ) ) {
00278         return false;
00279     }
00280 
00281     if ( month < 1 || month > 12 ) {  // Fix me!
00282         return false;
00283     }
00284 
00285     if ( day < 1 || day > hndays( month, y ) ) {
00286         return false;
00287     }
00288 
00289     return true;
00290 }
00291 
00292 bool KCalendarSystemJalali::isValid( const QDate &date ) const
00293 {
00294     return KCalendarSystem::isValid( date );
00295 }
00296 
00297 bool KCalendarSystemJalali::setDate( QDate &date, int year, int month, int day ) const
00298 {
00299     return KCalendarSystem::setDate( date, year, month, day );
00300 }
00301 
00302 //MAY BE BUGGY
00303 bool KCalendarSystemJalali::setYMD( QDate &date, int y, int m, int d ) const
00304 {
00305     // range checks
00306     // Removed deleted minValidYear and maxValidYear methods
00307     // Still use minimum of 1753 gregorain for now due to QDate using Julian calendar before then
00308     // Later change to following once new methods validated
00309     // if ( y < year( earliestValidDate() ) || y > year( latestValidDate() ) )
00310     if ( y < year( QDate( 1753, 1, 1 ) ) || y > 9999 ) {
00311         return false;
00312     }
00313 
00314     if ( m < 1 || m > 12 ) {
00315         return false;
00316     }
00317 
00318     if ( d < 1 || d > hndays( m, y ) ) {
00319         return false;
00320     }
00321 
00322     SDATE  *gd = jalaliToGregorian( y, m, d );
00323 
00324     return date.setYMD( gd->year, gd->mon, gd->day );
00325 }
00326 
00327 int KCalendarSystemJalali::year( const QDate &date ) const
00328 {
00329     kDebug( 5400 ) << "Jalali year...";
00330     int y;
00331 
00332     gregorianToJalali( date, &y, 0, 0 );
00333 
00334     return y;
00335 }
00336 
00337 int KCalendarSystemJalali::month ( const QDate& date ) const
00338 
00339 {
00340     kDebug( 5400 ) << "Jalali month...";
00341     int m;
00342 
00343     gregorianToJalali( date, 0 , &m, 0 );
00344 
00345     return m;
00346 }
00347 
00348 int KCalendarSystemJalali::day( const QDate &date ) const
00349 {
00350     kDebug( 5400 ) << "Jalali day...";
00351     int d;
00352 
00353     gregorianToJalali( date, 0, 0, &d );
00354 
00355     return d;
00356 }
00357 
00358 QDate KCalendarSystemJalali::addYears( const QDate &date, int nyears ) const
00359 {
00360     QDate result = date;
00361 
00362     int y = year( date ) + nyears;
00363     setYMD( result, y, month( date ), day( date ) );
00364 
00365     return result;
00366 }
00367 
00368 QDate KCalendarSystemJalali::addMonths( const QDate &date, int nmonths ) const
00369 {
00370     QDate result = date;
00371     int m = month( date );
00372     int y = year( date );
00373 
00374     if ( nmonths < 0 ) {
00375         m += 12;
00376         y -= 1;
00377     }
00378 
00379     --m; // this only works if we start counting at zero
00380     m += nmonths;
00381     y += m / 12;
00382     m %= 12;
00383     ++m;
00384 
00385     setYMD( result, y, m, day( date ) );
00386 
00387     return result;
00388 }
00389 
00390 QDate KCalendarSystemJalali::addDays( const QDate &date, int ndays ) const
00391 {
00392     return date.addDays( ndays );
00393 }
00394 
00395 int KCalendarSystemJalali::monthsInYear( const QDate &date ) const
00396 {
00397     Q_UNUSED( date )
00398 
00399     return 12;
00400 }
00401 
00402 int KCalendarSystemJalali::weeksInYear( const QDate &date ) const
00403 {
00404     return KCalendarSystem::weeksInYear( date );
00405 }
00406 
00407 int KCalendarSystemJalali::weeksInYear( int year ) const
00408 
00409 {
00410     Q_UNUSED( year );
00411 // couldn't understand it!
00412     return 52;
00413 }
00414 
00415 int KCalendarSystemJalali::daysInYear( const QDate &date ) const
00416 {
00417     Q_UNUSED( date );
00418     int result;
00419 //SDATE *sd = gregorianToJalali(year(date),month(date),day(date));
00420 //if (isJalaliLeap(sd->year))
00421     result = 366;
00422 //else
00423 // result=365;
00424     return result;
00425 }
00426 
00427 int KCalendarSystemJalali::daysInMonth( const QDate &date ) const
00428 {
00429     SDATE * sd = gregorianToJalali( date.year(), date.month(), date.day() );
00430     return hndays( sd->mon, sd->year );
00431 }
00432 
00433 int KCalendarSystemJalali::daysInWeek( const QDate &date ) const
00434 {
00435     return KCalendarSystem::daysInWeek( date );
00436 }
00437 
00438 //NOT TESTED YET
00439 int KCalendarSystemJalali::dayOfYear( const QDate &date ) const
00440 {
00441     QDate first;
00442     setYMD( first, year( date ), 1, 1 );
00443 
00444     return first.daysTo( date ) + 1;
00445 }
00446 
00447 int KCalendarSystemJalali::dayOfWeek( const QDate &date ) const
00448 {
00449     //same same I think?!
00450     return date.dayOfWeek();
00451 
00452 }
00453 
00454 int KCalendarSystemJalali::weekNumber( const QDate &date, int *yearNum ) const
00455 {
00456     QDate firstDayWeek1, lastDayOfYear;
00457     int y = year( date );
00458     int week;
00459     int weekDay1, dayOfWeek1InYear;
00460 
00461     // let's guess 1st day of 1st week
00462     setYMD( firstDayWeek1, y, 1, 1 );
00463     weekDay1 = dayOfWeek( firstDayWeek1 );
00464 
00465     // iso 8601: week 1  is the first containing thursday and week starts on
00466     // monday
00467     if ( weekDay1 > 4 /*Thursday*/ )
00468         firstDayWeek1 = addDays( firstDayWeek1 , 7 - weekDay1 + 1 ); // next monday
00469 
00470     dayOfWeek1InYear = dayOfYear( firstDayWeek1 );
00471 
00472     // if our date in prev year's week
00473     if ( dayOfYear( date ) < dayOfWeek1InYear ) {
00474         if ( yearNum ) {
00475             * yearNum = y - 1;
00476         }
00477         return weeksInYear( y - 1 );
00478     }
00479     // let' check if its last week belongs to next year
00480     setYMD( lastDayOfYear, y, 12, hndays( 12, y ) );
00481     // if our date is in last week && 1st week in next year has thursday
00482     if ( ( dayOfYear( date ) >= daysInYear( date ) - dayOfWeek( lastDayOfYear ) + 1 )
00483             && dayOfWeek( lastDayOfYear ) < 4 ) {
00484         if ( yearNum ) {
00485             * yearNum = y + 1;
00486         }
00487         week = 1;
00488     } else {
00489         week = firstDayWeek1.daysTo( date ) / 7 + 1;
00490     }
00491 
00492     return week;
00493 }
00494 
00495 bool KCalendarSystemJalali::isLeapYear( int year ) const
00496 {
00497     // from isJalaliLeap above
00498     int     tmp;
00499     tmp = year % 33;
00500     if ( tmp == 1 || tmp == 5 || tmp == 9 || tmp == 13 || tmp == 17 || tmp == 22 || tmp == 26 || tmp == 30 ) {
00501         return true;
00502     } else {
00503         return false;
00504     }
00505 }
00506 
00507 bool KCalendarSystemJalali::isLeapYear( const QDate &date ) const
00508 {
00509     return QDate::isLeapYear( year( date ) );
00510 }
00511 
00512 QString KCalendarSystemJalali::monthName( int month, int year, MonthNameFormat format )  const
00513 {
00514     Q_UNUSED( year );
00515 
00516     if ( format == ShortNamePossessive ) {
00517         switch ( month ) {
00518         case 1:
00519             return ki18nc( "of Farvardin short",   "of Far" ).toString( locale() );
00520         case 2:
00521             return ki18nc( "of Ordibehesht short", "of Ord" ).toString( locale() );
00522         case 3:
00523             return ki18nc( "of Khordad short",     "of Kho" ).toString( locale() );
00524         case 4:
00525             return ki18nc( "of Tir short",         "of Tir" ).toString( locale() );
00526         case 5:
00527             return ki18nc( "of Mordad short",      "of Mor" ).toString( locale() );
00528         case 6:
00529             return ki18nc( "of Shahrivar short",   "of Sha" ).toString( locale() );
00530         case 7:
00531             return ki18nc( "of Mehr short",        "of Meh" ).toString( locale() );
00532         case 8:
00533             return ki18nc( "of Aban short",        "of Aba" ).toString( locale() );
00534         case 9:
00535             return ki18nc( "of Azar short",        "of Aza" ).toString( locale() );
00536         case 10:
00537             return ki18nc( "of Dei short",         "of Dei" ).toString( locale() );
00538         case 11:
00539             return ki18nc( "of Bahman short",      "of Bah" ).toString( locale() );
00540         case 12:
00541             return ki18nc( "of Esfand short",      "of Esf" ).toString( locale() );
00542         default:
00543             return QString();
00544         }
00545     }
00546 
00547     if ( format == ShortName ) {
00548         switch ( month ) {
00549         case 1:
00550             return ki18nc( "Farvardin short",   "Far" ).toString( locale() );
00551         case 2:
00552             return ki18nc( "Ordibehesht short", "Ord" ).toString( locale() );
00553         case 3:
00554             return ki18nc( "Khordad short",     "Kho" ).toString( locale() );
00555         case 4:
00556             return ki18nc( "Tir short",         "Tir" ).toString( locale() );
00557         case 5:
00558             return ki18nc( "Mordad short",      "Mor" ).toString( locale() );
00559         case 6:
00560             return ki18nc( "Shahrivar short",   "Sha" ).toString( locale() );
00561         case 7:
00562             return ki18nc( "Mehr short",        "Meh" ).toString( locale() );
00563         case 8:
00564             return ki18nc( "Aban short",        "Aba" ).toString( locale() );
00565         case 9:
00566             return ki18nc( "Azar short",        "Aza" ).toString( locale() );
00567         case 10:
00568             return ki18nc( "Dei short",         "Dei" ).toString( locale() );
00569         case 11:
00570             return ki18nc( "Bahman short",      "Bah" ).toString( locale() );
00571         case 12:
00572             return ki18nc( "Esfand",            "Esf" ).toString( locale() );
00573         default:
00574             return QString();
00575         }
00576     }
00577 
00578     if ( format == LongNamePossessive ) {
00579         switch ( month ) {
00580         case 1:
00581             return ki18n( "of Farvardin" ).toString( locale() );
00582         case 2:
00583             return ki18n( "of Ordibehesht" ).toString( locale() );
00584         case 3:
00585             return ki18n( "of Khordad" ).toString( locale() );
00586         case 4:
00587             return ki18nc( "of Tir long", "of Tir" ).toString( locale() );
00588         case 5:
00589             return ki18n( "of Mordad" ).toString( locale() );
00590         case 6:
00591             return ki18n( "of Shahrivar" ).toString( locale() );
00592         case 7:
00593             return ki18n( "of Mehr" ).toString( locale() );
00594         case 8:
00595             return ki18n( "of Aban" ).toString( locale() );
00596         case 9:
00597             return ki18n( "of Azar" ).toString( locale() );
00598         case 10:
00599             return ki18nc( "of Dei long", "of Dei" ).toString( locale() );
00600         case 11:
00601             return ki18n( "of Bahman" ).toString( locale() );
00602         case 12:
00603             return ki18n( "of Esfand" ).toString( locale() );
00604         default:
00605             return QString();
00606         }
00607     }
00608 
00609     // Default to LongName format
00610     switch ( month ) {
00611     case 1:
00612         return ki18n( "Farvardin" ).toString( locale() );
00613     case 2:
00614         return ki18n( "Ordibehesht" ).toString( locale() );
00615     case 3:
00616         return ki18n( "Khordad" ).toString( locale() );
00617     case 4:
00618         return ki18nc( "Tir long", "Tir" ).toString( locale() );
00619     case 5:
00620         return ki18n( "Mordad" ).toString( locale() );
00621     case 6:
00622         return ki18n( "Shahrivar" ).toString( locale() );
00623     case 7:
00624         return ki18n( "Mehr" ).toString( locale() );
00625     case 8:
00626         return ki18n( "Aban" ).toString( locale() );
00627     case 9:
00628         return ki18n( "Azar" ).toString( locale() );
00629     case 10:
00630         return ki18nc( "Dei long", "Dei" ).toString( locale() );
00631     case 11:
00632         return ki18n( "Bahman" ).toString( locale() );
00633     case 12:
00634         return ki18n( "Esfand" ).toString( locale() );
00635     default:
00636         return QString();
00637     }
00638 }
00639 
00640 QString KCalendarSystemJalali::monthName( const QDate &date, MonthNameFormat format ) const
00641 {
00642     return monthName( month( date ), year( date ), format );
00643 }
00644 
00645 QString KCalendarSystemJalali::weekDayName( int day, WeekDayNameFormat format ) const
00646 {
00647     if ( format == ShortDayName ) {
00648         switch ( day ) {
00649         case 1:
00650             return ki18nc( "Do shanbe short",     "2sh" ).toString( locale() );
00651         case 2:
00652             return ki18nc( "Se shanbe short",     "3sh" ).toString( locale() );
00653         case 3:
00654             return ki18nc( "Chahar shanbe short", "4sh" ).toString( locale() );
00655         case 4:
00656             return ki18nc( "Panj shanbe short",   "5sh" ).toString( locale() );
00657         case 5:
00658             return ki18nc( "Jumee short",         "Jom" ).toString( locale() );
00659         case 6:
00660             return ki18nc( "Shanbe short",        "shn" ).toString( locale() );
00661         case 7:
00662             return ki18nc( "Yek-shanbe short",    "1sh" ).toString( locale() );
00663         default:
00664             return QString();
00665         }
00666     }
00667 
00668     // Default to ShortDayName format
00669     switch ( day ) {
00670     case 1:
00671         return ki18n( "Do shanbe" ).toString( locale() );
00672     case 2:
00673         return ki18n( "Se shanbe" ).toString( locale() );
00674     case 3:
00675         return ki18n( "Chahar shanbe" ).toString( locale() );
00676     case 4:
00677         return ki18n( "Panj shanbe" ).toString( locale() );
00678     case 5:
00679         return ki18n( "Jumee" ).toString( locale() );
00680     case 6:
00681         return ki18n( "Shanbe" ).toString( locale() );
00682     case 7:
00683         return ki18n( "Yek-shanbe" ).toString( locale() );
00684     default:
00685         return QString();
00686     }
00687 }
00688 
00689 QString KCalendarSystemJalali::weekDayName( const QDate &date, WeekDayNameFormat format ) const
00690 {
00691     return weekDayName( dayOfWeek( date ), format );
00692 }
00693 
00694 QString KCalendarSystemJalali::yearString( const QDate &pDate, StringFormat format ) const
00695 {
00696     return KCalendarSystem::yearString( pDate, format );
00697 }
00698 
00699 QString KCalendarSystemJalali::monthString( const QDate &pDate, StringFormat format ) const
00700 {
00701     return KCalendarSystem::monthString( pDate, format );
00702 }
00703 
00704 QString KCalendarSystemJalali::dayString( const QDate &pDate, StringFormat format ) const
00705 {
00706     return KCalendarSystem::dayString( pDate, format );
00707 }
00708 
00709 int KCalendarSystemJalali::yearStringToInteger( const QString &sNum, int &iLength ) const
00710 {
00711     return KCalendarSystem::yearStringToInteger( sNum, iLength );
00712 }
00713 
00714 int KCalendarSystemJalali::monthStringToInteger( const QString &sNum, int &iLength ) const
00715 {
00716     return KCalendarSystem::monthStringToInteger( sNum, iLength );
00717 }
00718 
00719 int KCalendarSystemJalali::dayStringToInteger( const QString & sNum, int & iLength ) const
00720 {
00721     return KCalendarSystem::dayStringToInteger( sNum, iLength );
00722 }
00723 
00724 QString KCalendarSystemJalali::formatDate( const QDate &date, KLocale::DateFormat format ) const
00725 {
00726     return KCalendarSystem::formatDate( date, format );
00727 }
00728 
00729 QDate KCalendarSystemJalali::readDate( const QString &str, bool *ok ) const
00730 {
00731     return KCalendarSystem::readDate( str, ok );
00732 }
00733 
00734 QDate KCalendarSystemJalali::readDate( const QString &intstr, const QString &fmt, bool *ok ) const
00735 {
00736     return KCalendarSystem::readDate( intstr, fmt, ok );
00737 }
00738 
00739 QDate KCalendarSystemJalali::readDate( const QString &str, KLocale::ReadDateFlags flags, bool *ok ) const
00740 {
00741     return KCalendarSystem::readDate( str, flags, ok );
00742 }
00743 
00744 int KCalendarSystemJalali::weekStartDay() const
00745 {
00746     return KCalendarSystem::weekStartDay();
00747 }
00748 
00749 int KCalendarSystemJalali::weekDayOfPray() const
00750 {
00751     return 5; // friday
00752 }
00753 
00754 bool KCalendarSystemJalali::isLunar() const
00755 {
00756     return false;
00757 }
00758 
00759 bool KCalendarSystemJalali::isLunisolar() const
00760 {
00761     return false;
00762 }
00763 
00764 bool KCalendarSystemJalali::isSolar() const
00765 {
00766     return true;
00767 }
00768 
00769 bool KCalendarSystemJalali::isProleptic() const
00770 {
00771     return false;
00772 }
00773 
00774 bool KCalendarSystemJalali::julianDayToDate( int jd, int &year, int &month, int &day ) const
00775 {
00776     // from jdn_jalali above.  Fix me!
00777     if ( jd >= earliestValidDate().toJulianDay() && jd <= latestValidDate().toJulianDay() ) {
00778         int y, m, d;
00779         int iYear, iMonth, iDay;
00780         int depoch;
00781         int cycle;
00782         int cyear;
00783         int ycycle;
00784         int aux1, aux2;
00785         int yday;
00786         d = 1;
00787         m = 1;
00788         y = 475;
00789         depoch = jd - jalali_jdn( y, m, d );
00790         cycle = ( int ) ( depoch / 1029983 );
00791         cyear = depoch % 1029983;
00792         if ( cyear == 1029982 ) {
00793             ycycle = 2820;
00794         } else {
00795             aux1 = cyear / 366;
00796             aux2 = cyear % 366;
00797             ycycle = ( ( ( 2134 * aux1 ) + ( 2816 * aux2 ) + 2815 ) / 1028522 ) + aux1 + 1;
00798         }
00799         iYear = ycycle + ( 2820 * cycle ) + 474;
00800         if ( iYear <= 0 ) {
00801             iYear = iYear - 1;
00802         }
00803         y = iYear;
00804         yday = ( jd - jalali_jdn( y, m, d ) ) + 1;
00805         if( yday <= 186 ) {
00806             iMonth = Ceil( ( yday - 1 ) / 31 );
00807         } else {
00808             iMonth = Ceil( ( yday - 7 ) / 30 );
00809         }
00810         iMonth++;
00811         m = iMonth;
00812         iDay = ( jd - jalali_jdn( y, m, d ) ) + 1;
00813         day = iDay;
00814         month = iMonth;
00815         year = iYear;
00816         return true;
00817     }
00818     return false;
00819 }
00820 
00821 bool KCalendarSystemJalali::dateToJulianDay( int year, int month, int day, int &jd ) const
00822 {
00823     // From jalali_jdn above.  Fix me!
00824     if ( isValid( year, month, day ) ) {
00825         int epbase;
00826         long epyear;
00827         long mdays;
00828         epbase = year - 474;
00829         epyear = 474 + ( epbase % 2820 );
00830         if ( month <= 7 ) {
00831             mdays = ( month - 1 ) * 31;
00832         } else {
00833             mdays = ( month - 1 ) * 30 + 6;
00834         }
00835         jd = day + mdays;
00836         jd += ( ( ( epyear * 682 ) - 110 ) / 2816 ) ;
00837         jd += ( epyear - 1 ) * 365;
00838         jd += ( epbase / 2820 ) * 1029983 ;
00839         jd += ( epoch().toJulianDay() - 1 );
00840         return true;
00841     }
00842     return false;
00843 }

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal