Bug 72756

Summary: calculating leap year birthdays
Product: [Applications] kontact Reporter: Michael Brennan Sayer <michaelb>
Component: summaryAssignee: kdepim bugs <kdepim-bugs>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version: 0.1   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: screenshot

Description Michael Brennan Sayer 2004-01-16 13:53:13 UTC
Version:           0.1 (using KDE 3.1.94 (CVS >= 20031206), Mandrake Linux Cooker i586 - Cooker)
Compiler:          gcc version 3.3.2 (Mandrake Linux 10.0 3.3.2-3mdk)
OS:          Linux (i686) release 2.6.0-1mdkenterprise

My wife was born 29/02/64 a leap year.  Kontact summary seems to have a hard time figuring out that this year is also a leap year.  I have attached a screen shot to explain.  Kontact is calculating her next birthday when she will be 41 - ignoring this current year of 2004 - it's also an interesting point of how Kontact will handle leap year birthdays as the only occur every 4 years, but leap year baby's have to celebrate their non leap years either on the 28th of Feb or the 1st of March.

Michael
Comment 1 Michael Brennan Sayer 2004-01-16 13:58:06 UTC
Created attachment 4193 [details]
screenshot
Comment 2 Tobias Koenig 2004-01-31 18:56:52 UTC
Subject: kdepim/kontact/plugins/kaddressbook

CVS commit by tokoe: 

Calculate the correct date for birthdays on XXXX-02-29 in leap years.
That fixes #72756.

CCMAIL:72756-done@bugs.kde.org


  M +12 -2     kabsummarywidget.cpp   1.29


--- kdepim/kontact/plugins/kaddressbook/kabsummarywidget.cpp  #1.28:1.29
@@ -260,7 +260,17 @@ bool KABSummaryWidget::eventFilter( QObj
 void KABSummaryWidget::dateDiff( const QDate &date, int &days, int &years )
 {
-  QDate currentDate( 0, QDate::currentDate().month(), QDate::currentDate().day() );
+  QDate currentDate;
+  QDate eventDate;
 
-  QDate eventDate( 0, date.month(), date.day() );
+  if ( QDate::leapYear( date.year() ) && date.month() == 2 && date.day() == 29 ) {
+    currentDate = QDate( date.year(), QDate::currentDate().month(), QDate::currentDate().day() );
+    if ( !QDate::leapYear( QDate::currentDate().year() ) )
+      eventDate = QDate( date.year(), date.month(), 28 ); // celebrate one day earlier ;)
+    else
+      eventDate = QDate( date.year(), date.month(), date.day() );
+  } else {
+    currentDate = QDate( 0, QDate::currentDate().month(), QDate::currentDate().day() );
+    eventDate = QDate( 0, date.month(), date.day() );
+  }
 
   int offset = currentDate.daysTo( eventDate );