author | erik <erik> | 2007-01-29 21:39:43 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-29 21:39:43 (UTC) |
commit | b2c306a99b8dc82c981390f02db859149fac8cf0 (patch) (unidiff) | |
tree | 5d3b06d7534611b8a6ea56f592d95b59b18a218c | |
parent | 597643805ce89c1237035e7f38ec953cfc0d080f (diff) | |
download | opie-b2c306a99b8dc82c981390f02db859149fac8cf0.zip opie-b2c306a99b8dc82c981390f02db859149fac8cf0.tar.gz opie-b2c306a99b8dc82c981390f02db859149fac8cf0.tar.bz2 |
Reformat according to current Opie coding style.
-rw-r--r-- | core/pim/datebook/datebookweek.cpp | 74 |
1 files changed, 48 insertions, 26 deletions
diff --git a/core/pim/datebook/datebookweek.cpp b/core/pim/datebook/datebookweek.cpp index ce0b10b..8caa827 100644 --- a/core/pim/datebook/datebookweek.cpp +++ b/core/pim/datebook/datebookweek.cpp | |||
@@ -591,24 +591,42 @@ QDate DateBookWeek::weekDate() const | |||
591 | 591 | ||
592 | // this used to only be needed by datebook.cpp, but now we need it inside | 592 | // This used to only be needed by datebook.cpp, but now we need it |
593 | // week view since | 593 | // inside week view since we need to be able to figure out our total |
594 | // we need to be able to figure out our total number of weeks on the fly... | 594 | // number of weeks on the fly. This is probably the best place to put |
595 | // this is probably the best place to put it.. | 595 | // it. |
596 | 596 | ||
597 | // For Weeks that start on Monday... (EASY!) | 597 | // For Weeks that start on Monday... (EASY!) |
598 | // At the moment we will use ISO 8601 method for computing | 598 | // At the moment we will use the ISO 8601 method for computing the week. |
599 | // the week. Granted, other countries use other methods, | 599 | // Granted, other countries use other methods, but we aren't doing any |
600 | // bet we aren't doing any Locale stuff at the moment. So, | 600 | // Locale stuff at the moment. Without locale info it is too hard to |
601 | // this should pass. This Algorithim is public domain and | 601 | // guess what method should be used. So, this should pass. This |
602 | // available at: | 602 | // algorithim is public domain and available at: |
603 | // http://personal.ecu.edu/mccartyr/ISOwdALG.txt | 603 | // http://personal.ecu.edu/mccartyr/ISOwdALG.txt |
604 | // the week number is return, and the year number is returned in year | 604 | // the week number is returned, and the year number is returned in year |
605 | // for Instance 2001/12/31 is actually the first week in 2002. | 605 | // for Instance 2001/12/31 is actually the first week in 2002. |
606 | // There is a more mathematical definition, but I will implement it when | 606 | // There is a more mathematical definition, it should be implemented. |
607 | // we are pass our deadline. | ||
608 | 607 | ||
609 | // For Weeks that start on Sunday... (ahh... home rolled) | 608 | // For Weeks that start on Sunday... (ahh... home rolled) |
610 | // okay, if Jan 1 is on Friday or Saturday, | 609 | // okay, if Jan 1 is on Friday or Saturday, it will go to the previous |
611 | // it will go to the pervious | 610 | // week. |
612 | // week... | 611 | |
613 | 612 | /*! | |
613 | * The week number and year number of a date may actually be different | ||
614 | * then the date itself as specified by the ISO 8601 standard. For | ||
615 | * example if Jan 1 year falls on a Friday, the week number will | ||
616 | * be the last week number for the previous year (52 of year - 1). Another | ||
617 | * example is that the date 2001-12-31 falls on a Monday, its week number | ||
618 | * is 1 and its year is 2002. This function provides stripped down | ||
619 | * version of the alogrithm described in | ||
620 | * http://personal.ecu.edu/mccartyr/ISOwdALG.txt to provide the correct | ||
621 | * week number and year number for a given date. | ||
622 | * | ||
623 | * \param d The date that you want to know the week number for. | ||
624 | * \param week A reference to the variable you want to store the week | ||
625 | * number in. | ||
626 | * \param year A reference to the variable you want to store the year | ||
627 | * number in. | ||
628 | * \param startOnMonday Inform the function whether weeks start on | ||
629 | * Sunday or Monday. Set to true if your weeks start on Monday. | ||
630 | * \return false if the supplied date is invalid, true otherwise. | ||
631 | */ | ||
614 | bool calcWeek( const QDate &d, int &week, int &year, | 632 | bool calcWeek( const QDate &d, int &week, int &year, |
@@ -616,7 +634,5 @@ bool calcWeek( const QDate &d, int &week, int &year, | |||
616 | { | 634 | { |
617 | int weekNumber; | 635 | int weekNumber = -1; |
618 | int yearNumber; | 636 | int yearNumber = -1; |
619 | 637 | ||
620 | // remove a pesky warning, (Optimizations on g++) | ||
621 | weekNumber = -1; | ||
622 | int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); | 638 | int jan1WeekDay = QDate(d.year(), 1, 1).dayOfWeek(); |
@@ -631,3 +647,4 @@ bool calcWeek( const QDate &d, int &week, int &year, | |||
631 | yearNumber = d.year() - 1; | 647 | yearNumber = d.year() - 1; |
632 | if ( jan1WeekDay == 5 || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) | 648 | if ( jan1WeekDay == 5 |
649 | || ( jan1WeekDay == 6 && QDate::leapYear(yearNumber) ) ) | ||
633 | weekNumber = 53; | 650 | weekNumber = 53; |
@@ -637,2 +654,3 @@ bool calcWeek( const QDate &d, int &week, int &year, | |||
637 | yearNumber = d.year(); | 654 | yearNumber = d.year(); |
655 | |||
638 | if ( yearNumber == d.year() ) { | 656 | if ( yearNumber == d.year() ) { |
@@ -642,3 +660,4 @@ bool calcWeek( const QDate &d, int &week, int &year, | |||
642 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) | 660 | if ( ((totalDays - d.dayOfYear()) < (4 - dayOfWeek) ) |
643 | || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) { | 661 | || (jan1WeekDay == 7) && (totalDays - d.dayOfYear()) < 3) |
662 | { | ||
644 | yearNumber++; | 663 | yearNumber++; |
@@ -656,6 +675,8 @@ bool calcWeek( const QDate &d, int &week, int &year, | |||
656 | if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 | 675 | if ( d.dayOfYear() <= (7 - jan1WeekDay) && jan1WeekDay > 4 |
657 | && jan1WeekDay != 7 ) { | 676 | && jan1WeekDay != 7 ) |
677 | { | ||
658 | yearNumber = d.year() - 1; | 678 | yearNumber = d.year() - 1; |
659 | if ( jan1WeekDay == 6 | 679 | if ( jan1WeekDay == 6 |
660 | || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) { | 680 | || (jan1WeekDay == 7 && QDate::leapYear(yearNumber) ) ) |
681 | { | ||
661 | weekNumber = 53; | 682 | weekNumber = 53; |
@@ -665,2 +686,3 @@ bool calcWeek( const QDate &d, int &week, int &year, | |||
665 | yearNumber = d.year(); | 686 | yearNumber = d.year(); |
687 | |||
666 | if ( yearNumber == d.year() ) { | 688 | if ( yearNumber == d.year() ) { |
@@ -677,3 +699,4 @@ bool calcWeek( const QDate &d, int &week, int &year, | |||
677 | weekNumber = j / 7; | 699 | weekNumber = j / 7; |
678 | if ( jan1WeekDay > 4 ) { | 700 | |
701 | if ( jan1WeekDay > 4 ) | ||
679 | weekNumber--; | 702 | weekNumber--; |
@@ -681,3 +704,2 @@ bool calcWeek( const QDate &d, int &week, int &year, | |||
681 | } | 704 | } |
682 | } | ||
683 | year = yearNumber; | 705 | year = yearNumber; |