From kde-commits Mon Feb 28 23:00:59 2005 From: Stefan Siegel Date: Mon, 28 Feb 2005 23:00:59 +0000 To: kde-commits Subject: kdeextragear-1/amarok/src Message-Id: <20050228230059.1656316F7D () office ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=110963166810376 CVS commit by siegel: verboseTimeSince() again, this version doesn't return "... months ago" but the month and the year, so you don't need to do the maths ;-) CCMAIL: amarok-devel@lists.sf.net M +25 -41 contextbrowser.cpp 1.392 --- kdeextragear-1/amarok/src/contextbrowser.cpp #1.391:1.392 @@ -27,4 +27,5 @@ #include //kapp +#include // for verboseTimeSince() #include #include @@ -530,49 +531,32 @@ static QString verboseTimeSince( const QDateTime &datetime ) { - const QDate date = datetime.date(); - const QDate now = QDate::currentDate(); - if( date > now ) - return i18n( "The future" ); + const QDateTime now = QDateTime::currentDateTime(); + const int datediff = datetime.daysTo( now ); - if( date.year() == now.year() ) { - if( date.month() == now.month() ) { - if( date.day() == now.day() ) { - //the date is today, let's get more resolution - const QTime time = datetime.time(); - const QTime now = QTime::currentTime(); - if( time > now ) - return i18n( "The future" ); + if( datediff >= 6*7 /*six weeks*/ ) { // return absolute month/year + const KCalendarSystem *cal = KGlobal::locale()->calendar(); + const QDate date = datetime.date(); + return i18n( "monthname year", "%1 %2" ).arg( cal->monthName(date), cal->yearString(date, false) ); + } - int - minutes = now.hour() - time.hour(); - minutes *= 60; - minutes += QABS(now.minute() - time.minute()); + if( datediff >= 7 ) // return difference in weeks + return i18n( "One week ago", "%n weeks ago", (datediff+3)/7 ); - if( minutes < 90 ) - return i18n( "Within the last minute", "%n minutes ago", minutes == 0 ? 1 : minutes ); - else - return i18n( "Within the last hour", "%n hours ago", now.hour() - time.hour() ); - } - else - /*continue to days calculation section*/; - } + const int timediff = datetime.secsTo( now ); - const int days = date.daysTo( now ); + if( timediff >= 24*60*60 /*24 hours*/ ) // return difference in days + return datediff == 1 ? + i18n( "Yesterday" ) : + i18n( "One day ago", "%n days ago", (timediff+12*60*60)/(24*60*60) ); - if ( days > 28 ) - return i18n( "Last month", "%n months ago", now.month() - date.month() ); - else if( days < 7 ) - return i18n( "Yesterday", "%n days ago", days ); - else - return i18n( "Last week", "%n weeks ago", days / 7 ); - } + if( timediff >= 90*60 /*90 minutes*/ ) // return difference in hours + return i18n( "One hour ago", "%n hours ago", (timediff+30*60)/(60*60) ); - // it was played last year, but that could still be yesterday - //TODO it could still be yesterday, this whole function needs adaption + if( timediff >= 0 ) // return difference in minutes + return timediff/60 ? + i18n( "One minute ago", "%n minutes ago", (timediff+30)/60 ) : + i18n( "Within the last minute" ); - if( now.year() - date.year() == 1 && QABS(now.month() - date.month()) < 7 ) - return i18n( "Last month", "%n months ago", now.month() - date.month() ); - else - return i18n( "Last year", "%n years ago", now.year() - date.year() ); + return i18n( "The future" ); }