• Skip to content
  • Skip to link menu
KDE 4.3 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 //Does not cope when destination month has fewer days than current month
00359 QDate KCalendarSystemJalali::addYears( const QDate &date, int nyears ) const
00360 {
00361     QDate result = date;
00362 
00363     int y = year( date ) + nyears;
00364     int m = month( date );
00365 
00366     //Quick hack to support destination month with fewer days than current month
00367     if ( setYMD( result, y, m, 1 ) ) {
00368         setYMD( result, y, m, qMin( day( date ), daysInMonth( result ) ) );
00369     }
00370 
00371     return result;
00372 
00373 /*  Use this once new jd formulas are verified
00374     return KCalendarSystem::addYears( date, nyears );
00375 */
00376 }
00377 
00378 QDate KCalendarSystemJalali::addMonths( const QDate &date, int nmonths ) const
00379 {
00380     QDate result = date;
00381     int m = month( date );
00382     int y = year( date );
00383 
00384     if ( nmonths < 0 ) {
00385         m += 12;
00386         y -= 1;
00387     }
00388 
00389     --m; // this only works if we start counting at zero
00390     m += nmonths;
00391     y += m / 12;
00392     m %= 12;
00393     ++m;
00394 
00395     //Quick hack to support destination month with fewer days than current month
00396     if ( setYMD( result, y, m, 1 ) ) {
00397         setYMD( result, y, m, qMin( day( date ), daysInMonth( result ) ) );
00398     }
00399 
00400     return result;
00401 
00402 /*  Use this once new jd formulas are verified
00403     return KCalendarSystem::addMonths( date, nmonths );
00404 */
00405 }
00406 
00407 QDate KCalendarSystemJalali::addDays( const QDate &date, int ndays ) const
00408 {
00409     return date.addDays( ndays );
00410 }
00411 
00412 int KCalendarSystemJalali::monthsInYear( const QDate &date ) const
00413 {
00414     Q_UNUSED( date )
00415 
00416     return 12;
00417 }
00418 
00419 int KCalendarSystemJalali::weeksInYear( const QDate &date ) const
00420 {
00421     return KCalendarSystem::weeksInYear( date );
00422 }
00423 
00424 int KCalendarSystemJalali::weeksInYear( int year ) const
00425 
00426 {
00427     Q_UNUSED( year );
00428 // couldn't understand it!
00429     return 52;
00430 }
00431 
00432 int KCalendarSystemJalali::daysInYear( const QDate &date ) const
00433 {
00434     Q_UNUSED( date );
00435     int result;
00436 //SDATE *sd = gregorianToJalali(year(date),month(date),day(date));
00437 //if (isJalaliLeap(sd->year))
00438     result = 366;
00439 //else
00440 // result=365;
00441     return result;
00442 }
00443 
00444 int KCalendarSystemJalali::daysInMonth( const QDate &date ) const
00445 {
00446     SDATE * sd = gregorianToJalali( date.year(), date.month(), date.day() );
00447     return hndays( sd->mon, sd->year );
00448 }
00449 
00450 int KCalendarSystemJalali::daysInWeek( const QDate &date ) const
00451 {
00452     return KCalendarSystem::daysInWeek( date );
00453 }
00454 
00455 //NOT TESTED YET
00456 int KCalendarSystemJalali::dayOfYear( const QDate &date ) const
00457 {
00458     QDate first;
00459     setYMD( first, year( date ), 1, 1 );
00460 
00461     return first.daysTo( date ) + 1;
00462 }
00463 
00464 int KCalendarSystemJalali::dayOfWeek( const QDate &date ) const
00465 {
00466     //same same I think?!
00467     return date.dayOfWeek();
00468 
00469 }
00470 
00471 int KCalendarSystemJalali::weekNumber( const QDate &date, int *yearNum ) const
00472 {
00473     QDate firstDayWeek1, lastDayOfYear;
00474     int y = year( date );
00475     int week;
00476     int weekDay1, dayOfWeek1InYear;
00477 
00478     // let's guess 1st day of 1st week
00479     setYMD( firstDayWeek1, y, 1, 1 );
00480     weekDay1 = dayOfWeek( firstDayWeek1 );
00481 
00482     // iso 8601: week 1  is the first containing thursday and week starts on
00483     // monday
00484     if ( weekDay1 > 4 /*Thursday*/ )
00485         firstDayWeek1 = addDays( firstDayWeek1 , 7 - weekDay1 + 1 ); // next monday
00486 
00487     dayOfWeek1InYear = dayOfYear( firstDayWeek1 );
00488 
00489     // if our date in prev year's week
00490     if ( dayOfYear( date ) < dayOfWeek1InYear ) {
00491         if ( yearNum ) {
00492             * yearNum = y - 1;
00493         }
00494         return weeksInYear( y - 1 );
00495     }
00496     // let's check if its last week belongs to next year
00497     setYMD( lastDayOfYear, y, 12, hndays( 12, y ) );
00498     // if our date is in last week && 1st week in next year has thursday
00499     if ( ( dayOfYear( date ) >= daysInYear( date ) - dayOfWeek( lastDayOfYear ) + 1 )
00500             && dayOfWeek( lastDayOfYear ) < 4 ) {
00501         if ( yearNum ) {
00502             * yearNum = y + 1;
00503         }
00504         week = 1;
00505     } else {
00506         week = firstDayWeek1.daysTo( date ) / 7 + 1;
00507     }
00508 
00509     return week;
00510 }
00511 
00512 bool KCalendarSystemJalali::isLeapYear( int year ) const
00513 {
00514     // from isJalaliLeap above
00515     int     tmp;
00516     tmp = year % 33;
00517     if ( tmp == 1 || tmp == 5 || tmp == 9 || tmp == 13 || tmp == 17 || tmp == 22 || tmp == 26 || tmp == 30 ) {
00518         return true;
00519     } else {
00520         return false;
00521     }
00522 }
00523 
00524 bool KCalendarSystemJalali::isLeapYear( const QDate &date ) const
00525 {
00526     return QDate::isLeapYear( year( date ) );
00527 }
00528 
00529 QString KCalendarSystemJalali::monthName( int month, int year, MonthNameFormat format )  const
00530 {
00531     Q_UNUSED( year );
00532 
00533     if ( format == ShortNamePossessive ) {
00534         switch ( month ) {
00535         case 1:
00536             return ki18nc( "of Farvardin short",   "of Far" ).toString( locale() );
00537         case 2:
00538             return ki18nc( "of Ordibehesht short", "of Ord" ).toString( locale() );
00539         case 3:
00540             return ki18nc( "of Khordad short",     "of Kho" ).toString( locale() );
00541         case 4:
00542             return ki18nc( "of Tir short",         "of Tir" ).toString( locale() );
00543         case 5:
00544             return ki18nc( "of Mordad short",      "of Mor" ).toString( locale() );
00545         case 6:
00546             return ki18nc( "of Shahrivar short",   "of Sha" ).toString( locale() );
00547         case 7:
00548             return ki18nc( "of Mehr short",        "of Meh" ).toString( locale() );
00549         case 8:
00550             return ki18nc( "of Aban short",        "of Aba" ).toString( locale() );
00551         case 9:
00552             return ki18nc( "of Azar short",        "of Aza" ).toString( locale() );
00553         case 10:
00554             return ki18nc( "of Dei short",         "of Dei" ).toString( locale() );
00555         case 11:
00556             return ki18nc( "of Bahman short",      "of Bah" ).toString( locale() );
00557         case 12:
00558             return ki18nc( "of Esfand short",      "of Esf" ).toString( locale() );
00559         default:
00560             return QString();
00561         }
00562     }
00563 
00564     if ( format == ShortName ) {
00565         switch ( month ) {
00566         case 1:
00567             return ki18nc( "Farvardin short",   "Far" ).toString( locale() );
00568         case 2:
00569             return ki18nc( "Ordibehesht short", "Ord" ).toString( locale() );
00570         case 3:
00571             return ki18nc( "Khordad short",     "Kho" ).toString( locale() );
00572         case 4:
00573             return ki18nc( "Tir short",         "Tir" ).toString( locale() );
00574         case 5:
00575             return ki18nc( "Mordad short",      "Mor" ).toString( locale() );
00576         case 6:
00577             return ki18nc( "Shahrivar short",   "Sha" ).toString( locale() );
00578         case 7:
00579             return ki18nc( "Mehr short",        "Meh" ).toString( locale() );
00580         case 8:
00581             return ki18nc( "Aban short",        "Aba" ).toString( locale() );
00582         case 9:
00583             return ki18nc( "Azar short",        "Aza" ).toString( locale() );
00584         case 10:
00585             return ki18nc( "Dei short",         "Dei" ).toString( locale() );
00586         case 11:
00587             return ki18nc( "Bahman short",      "Bah" ).toString( locale() );
00588         case 12:
00589             return ki18nc( "Esfand",            "Esf" ).toString( locale() );
00590         default:
00591             return QString();
00592         }
00593     }
00594 
00595     if ( format == LongNamePossessive ) {
00596         switch ( month ) {
00597         case 1:
00598             return ki18n( "of Farvardin" ).toString( locale() );
00599         case 2:
00600             return ki18n( "of Ordibehesht" ).toString( locale() );
00601         case 3:
00602             return ki18n( "of Khordad" ).toString( locale() );
00603         case 4:
00604             return ki18nc( "of Tir long", "of Tir" ).toString( locale() );
00605         case 5:
00606             return ki18n( "of Mordad" ).toString( locale() );
00607         case 6:
00608             return ki18n( "of Shahrivar" ).toString( locale() );
00609         case 7:
00610             return ki18n( "of Mehr" ).toString( locale() );
00611         case 8:
00612             return ki18n( "of Aban" ).toString( locale() );
00613         case 9:
00614             return ki18n( "of Azar" ).toString( locale() );
00615         case 10:
00616             return ki18nc( "of Dei long", "of Dei" ).toString( locale() );
00617         case 11:
00618             return ki18n( "of Bahman" ).toString( locale() );
00619         case 12:
00620             return ki18n( "of Esfand" ).toString( locale() );
00621         default:
00622             return QString();
00623         }
00624     }
00625 
00626     // Default to LongName format
00627     switch ( month ) {
00628     case 1:
00629         return ki18n( "Farvardin" ).toString( locale() );
00630     case 2:
00631         return ki18n( "Ordibehesht" ).toString( locale() );
00632     case 3:
00633         return ki18n( "Khordad" ).toString( locale() );
00634     case 4:
00635         return ki18nc( "Tir long", "Tir" ).toString( locale() );
00636     case 5:
00637         return ki18n( "Mordad" ).toString( locale() );
00638     case 6:
00639         return ki18n( "Shahrivar" ).toString( locale() );
00640     case 7:
00641         return ki18n( "Mehr" ).toString( locale() );
00642     case 8:
00643         return ki18n( "Aban" ).toString( locale() );
00644     case 9:
00645         return ki18n( "Azar" ).toString( locale() );
00646     case 10:
00647         return ki18nc( "Dei long", "Dei" ).toString( locale() );
00648     case 11:
00649         return ki18n( "Bahman" ).toString( locale() );
00650     case 12:
00651         return ki18n( "Esfand" ).toString( locale() );
00652     default:
00653         return QString();
00654     }
00655 }
00656 
00657 QString KCalendarSystemJalali::monthName( const QDate &date, MonthNameFormat format ) const
00658 {
00659     return monthName( month( date ), year( date ), format );
00660 }
00661 
00662 QString KCalendarSystemJalali::weekDayName( int day, WeekDayNameFormat format ) const
00663 {
00664     if ( format == ShortDayName ) {
00665         switch ( day ) {
00666         case 1:
00667             return ki18nc( "Do shanbe short",     "2sh" ).toString( locale() );
00668         case 2:
00669             return ki18nc( "Se shanbe short",     "3sh" ).toString( locale() );
00670         case 3:
00671             return ki18nc( "Chahar shanbe short", "4sh" ).toString( locale() );
00672         case 4:
00673             return ki18nc( "Panj shanbe short",   "5sh" ).toString( locale() );
00674         case 5:
00675             return ki18nc( "Jumee short",         "Jom" ).toString( locale() );
00676         case 6:
00677             return ki18nc( "Shanbe short",        "shn" ).toString( locale() );
00678         case 7:
00679             return ki18nc( "Yek-shanbe short",    "1sh" ).toString( locale() );
00680         default:
00681             return QString();
00682         }
00683     }
00684 
00685     // Default to ShortDayName format
00686     switch ( day ) {
00687     case 1:
00688         return ki18n( "Do shanbe" ).toString( locale() );
00689     case 2:
00690         return ki18n( "Se shanbe" ).toString( locale() );
00691     case 3:
00692         return ki18n( "Chahar shanbe" ).toString( locale() );
00693     case 4:
00694         return ki18n( "Panj shanbe" ).toString( locale() );
00695     case 5:
00696         return ki18n( "Jumee" ).toString( locale() );
00697     case 6:
00698         return ki18n( "Shanbe" ).toString( locale() );
00699     case 7:
00700         return ki18n( "Yek-shanbe" ).toString( locale() );
00701     default:
00702         return QString();
00703     }
00704 }
00705 
00706 QString KCalendarSystemJalali::weekDayName( const QDate &date, WeekDayNameFormat format ) const
00707 {
00708     return weekDayName( dayOfWeek( date ), format );
00709 }
00710 
00711 QString KCalendarSystemJalali::yearString( const QDate &pDate, StringFormat format ) const
00712 {
00713     return KCalendarSystem::yearString( pDate, format );
00714 }
00715 
00716 QString KCalendarSystemJalali::monthString( const QDate &pDate, StringFormat format ) const
00717 {
00718     return KCalendarSystem::monthString( pDate, format );
00719 }
00720 
00721 QString KCalendarSystemJalali::dayString( const QDate &pDate, StringFormat format ) const
00722 {
00723     return KCalendarSystem::dayString( pDate, format );
00724 }
00725 
00726 int KCalendarSystemJalali::yearStringToInteger( const QString &sNum, int &iLength ) const
00727 {
00728     return KCalendarSystem::yearStringToInteger( sNum, iLength );
00729 }
00730 
00731 int KCalendarSystemJalali::monthStringToInteger( const QString &sNum, int &iLength ) const
00732 {
00733     return KCalendarSystem::monthStringToInteger( sNum, iLength );
00734 }
00735 
00736 int KCalendarSystemJalali::dayStringToInteger( const QString & sNum, int & iLength ) const
00737 {
00738     return KCalendarSystem::dayStringToInteger( sNum, iLength );
00739 }
00740 
00741 QString KCalendarSystemJalali::formatDate( const QDate &date, KLocale::DateFormat format ) const
00742 {
00743     return KCalendarSystem::formatDate( date, format );
00744 }
00745 
00746 QDate KCalendarSystemJalali::readDate( const QString &str, bool *ok ) const
00747 {
00748     return KCalendarSystem::readDate( str, ok );
00749 }
00750 
00751 QDate KCalendarSystemJalali::readDate( const QString &intstr, const QString &fmt, bool *ok ) const
00752 {
00753     return KCalendarSystem::readDate( intstr, fmt, ok );
00754 }
00755 
00756 QDate KCalendarSystemJalali::readDate( const QString &str, KLocale::ReadDateFlags flags, bool *ok ) const
00757 {
00758     return KCalendarSystem::readDate( str, flags, ok );
00759 }
00760 
00761 int KCalendarSystemJalali::weekStartDay() const
00762 {
00763     return KCalendarSystem::weekStartDay();
00764 }
00765 
00766 int KCalendarSystemJalali::weekDayOfPray() const
00767 {
00768     return 5; // friday
00769 }
00770 
00771 bool KCalendarSystemJalali::isLunar() const
00772 {
00773     return false;
00774 }
00775 
00776 bool KCalendarSystemJalali::isLunisolar() const
00777 {
00778     return false;
00779 }
00780 
00781 bool KCalendarSystemJalali::isSolar() const
00782 {
00783     return true;
00784 }
00785 
00786 bool KCalendarSystemJalali::isProleptic() const
00787 {
00788     return false;
00789 }
00790 
00791 bool KCalendarSystemJalali::julianDayToDate( int jd, int &year, int &month, int &day ) const
00792 {
00793     // from jdn_jalali above.  Fix me!
00794     if ( jd >= earliestValidDate().toJulianDay() && jd <= latestValidDate().toJulianDay() ) {
00795         int y, m, d;
00796         int iYear, iMonth, iDay;
00797         int depoch;
00798         int cycle;
00799         int cyear;
00800         int ycycle;
00801         int aux1, aux2;
00802         int yday;
00803         d = 1;
00804         m = 1;
00805         y = 475;
00806         depoch = jd - jalali_jdn( y, m, d );
00807         cycle = ( int ) ( depoch / 1029983 );
00808         cyear = depoch % 1029983;
00809         if ( cyear == 1029982 ) {
00810             ycycle = 2820;
00811         } else {
00812             aux1 = cyear / 366;
00813             aux2 = cyear % 366;
00814             ycycle = ( ( ( 2134 * aux1 ) + ( 2816 * aux2 ) + 2815 ) / 1028522 ) + aux1 + 1;
00815         }
00816         iYear = ycycle + ( 2820 * cycle ) + 474;
00817         if ( iYear <= 0 ) {
00818             iYear = iYear - 1;
00819         }
00820         y = iYear;
00821         yday = ( jd - jalali_jdn( y, m, d ) ) + 1;
00822         if( yday <= 186 ) {
00823             iMonth = Ceil( ( yday - 1 ) / 31 );
00824         } else {
00825             iMonth = Ceil( ( yday - 7 ) / 30 );
00826         }
00827         iMonth++;
00828         m = iMonth;
00829         iDay = ( jd - jalali_jdn( y, m, d ) ) + 1;
00830         day = iDay;
00831         month = iMonth;
00832         year = iYear;
00833         return true;
00834     }
00835     return false;
00836 }
00837 
00838 bool KCalendarSystemJalali::dateToJulianDay( int year, int month, int day, int &jd ) const
00839 {
00840     // From jalali_jdn above.  Fix me!
00841     if ( isValid( year, month, day ) ) {
00842         int epbase;
00843         long epyear;
00844         long mdays;
00845         epbase = year - 474;
00846         epyear = 474 + ( epbase % 2820 );
00847         if ( month <= 7 ) {
00848             mdays = ( month - 1 ) * 31;
00849         } else {
00850             mdays = ( month - 1 ) * 30 + 6;
00851         }
00852         jd = day + mdays;
00853         jd += ( ( ( epyear * 682 ) - 110 ) / 2816 ) ;
00854         jd += ( epyear - 1 ) * 365;
00855         jd += ( epbase / 2820 ) * 1029983 ;
00856         jd += ( epoch().toJulianDay() - 1 );
00857         return true;
00858     }
00859     return false;
00860 }

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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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