author | alwin <alwin> | 2005-03-21 14:31:01 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-03-21 14:31:01 (UTC) |
commit | 5b2632bcae03b159d137fe9489eb2620c0f65f1a (patch) (side-by-side diff) | |
tree | 7984efeeff1bba3083494b38378aaa223a82d117 /core/pim/datebook/holiday/national/nationalholiday.cpp | |
parent | 18825d8195f05d1a82affc0111f524371dbdeb5f (diff) | |
download | opie-5b2632bcae03b159d137fe9489eb2620c0f65f1a.zip opie-5b2632bcae03b159d137fe9489eb2620c0f65f1a.tar.gz opie-5b2632bcae03b159d137fe9489eb2620c0f65f1a.tar.bz2 |
design bug fixed.
xml-file now may contain floating holidays. syntax of it - see german.xml as
example and/or README file in OPIEDIR/etc/nationaldays/
Diffstat (limited to 'core/pim/datebook/holiday/national/nationalholiday.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/holiday/national/nationalholiday.cpp | 155 |
1 files changed, 150 insertions, 5 deletions
diff --git a/core/pim/datebook/holiday/national/nationalholiday.cpp b/core/pim/datebook/holiday/national/nationalholiday.cpp index 52f3489..a7ab9a5 100644 --- a/core/pim/datebook/holiday/national/nationalholiday.cpp +++ b/core/pim/datebook/holiday/national/nationalholiday.cpp @@ -37,2 +37,3 @@ void NationalHoliday::load_days() QStringList::ConstIterator it; + floatingDates.clear(); NHcfg readit; @@ -42,7 +43,9 @@ void NationalHoliday::load_days() } - tholidaylist::ConstIterator it; - for (it=readit.days().begin();it!=readit.days().end();++it) { - _days[it.key()]+=(it.data()); - } + tentrylist::ConstIterator it; + + for (it=readit.fixDates().begin();it!=readit.fixDates().end();++it) { + _days[(*it).date()]+=(*it).name(); + } + floatingDates+=readit.floatingDates(); } @@ -51,2 +54,137 @@ void NationalHoliday::load_days() +void NationalHoliday::calc_easterDate() +{ + unsigned long n = 0; + unsigned long p = 0; + + if ( _lastyear > 1582 ) { + unsigned long a = _lastyear%19; + unsigned long b = _lastyear/100; + unsigned long c = _lastyear%100; + unsigned long d = b/4; + unsigned long e = b%4; + unsigned long f = (b+8)/25; + unsigned long g = (b+f+1)/3; + unsigned long h = (19*a+b-d-g+15)%30; + unsigned long i = c/4; + unsigned long j = c%4; + unsigned long k = j%100; + unsigned long l = (32+2*e+2*i-h-k)%7; + unsigned long m = (a+11*h+22*l)/451; + n = (h+l-7*m+114)/31; + p = (h+l-7*m+114)%31; + } else { + unsigned long a = _lastyear%4; + unsigned long b = _lastyear%7; + unsigned long c = _lastyear%19; + unsigned long d = (19*c+15)%30; + unsigned long e = (2*a+4*b-d+34)%7; + n = (d+e+114)/31; + p = (d+e+114)%31; + } + p++; + easterDate = QDate(_lastyear,n,p); + odebug << "Easterdate = " << easterDate << oendl; +} + + +void NationalHoliday::setyear(const QDate&aDate) +{ + if (aDate.year()==_lastyear) return; + odebug << "calc year" << oendl; + _lastyear = aDate.year(); + _fdays.clear(); + calc_easterDate(); + tentrylist::ConstIterator it; + QDate tempdate,t; + + for (it = floatingDates.begin();it!=floatingDates.end();++it) { + odebug << "Float day " << (*it).name() << oendl; + + if ( (*it).date().year()==9999) { + tempdate = QDate(easterDate.year(),easterDate.month(),easterDate.day()); + } else { + tempdate = QDate(_lastyear,(*it).date().month(),(*it).date().day()); + } + + odebug << "Start calc date: " << tempdate << oendl; + int weekday = weektonumber((*it).weekday()); + int mo; + + if (weekday>0) { + /* specific weekday set */ + bool dir = true; + if (!(*it).daydep().isEmpty()) { + dir = ((*it).daydep()=="before"?true:false); + tempdate = movedateday(tempdate,weekday,dir); + } else if (!(*it).dayofmonth().isEmpty() && + (mo=monthtonumber((*it).month())) !=0 ) { + t = QDate(_lastyear,mo,1); + if ((*it).dayofmonth()=="last") { + int l = t.daysInMonth(); + tempdate.setYMD(_lastyear,mo,l); + tempdate = movedateday(tempdate,weekday,true); + } else { + tempdate = movedateday(t,weekday,false); + tempdate = tempdate.addDays(dayoftoint((*it).dayofmonth())); + } + } + + } + tempdate = tempdate.addDays((*it).offset()); + odebug << "Moved date to " << tempdate << oendl; + _fdays[tempdate]+=(*it).name(); + } +} + +int NationalHoliday::dayoftoint(const QString&d) +{ + if (d=="first") return 0; + else if (d=="second") return 7; + else if (d=="third") return 14; + else if (d=="fourth") return 21; + return 0; +} + +int NationalHoliday::monthtonumber(const QString&m) +{ + if (m=="january")return 1; + else if (m=="february")return 2; + else if (m=="march") return 3; + else if (m=="april") return 4; + else if (m=="may") return 5; + else if (m=="june") return 6; + else if (m=="july") return 7; + else if (m=="august") return 8; + else if (m=="september") return 9; + else if (m=="october") return 10; + else if (m=="november") return 11; + else if (m=="december") return 12; + return 0; +} + +QDate NationalHoliday::movedateday(const QDate&start,int weekday,bool direction) +{ + QDate d = start; + if (weekday==0) return d; + int c = (direction?-1:1); + + while (d.dayOfWeek()!=weekday) { + d = d.addDays(c); + } + return d; +} + +int NationalHoliday::weektonumber(const QString&w) +{ + if (w=="monday") return 1; + else if (w=="tuesday") return 2; + else if (w=="wednesday") return 3; + else if (w=="thursday" ) return 4; + else if (w=="friday") return 5; + else if (w=="saturday") return 6; + else if (w=="sunday") return 7; + return 0; +} + QStringList NationalHoliday::entries(const QDate&aDate) @@ -54,2 +192,4 @@ QStringList NationalHoliday::entries(const QDate&aDate) load_days(); + setyear(aDate); + QStringList ret; @@ -61,3 +201,7 @@ QStringList NationalHoliday::entries(const QDate&aDate) } - + QDate d2(_lastyear,d.month(),d.day()); + it = _fdays.find(d2); + if (it!=_fdays.end()) { + ret+=*it; + } return ret; @@ -73,2 +217,3 @@ QMap<QDate,QStringList> NationalHoliday::entries(const QDate&start,const QDate&e load_days(); + setyear(start); QMap<QDate,QStringList> ret; |