From 4e7c45695672ecdbd0cd14cac0ea29a8e134ee78 Mon Sep 17 00:00:00 2001 From: zautrix Date: Mon, 28 Mar 2005 23:39:37 +0000 Subject: montview sunday fix --- (limited to 'microkde/kdecore') diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp index 7f31ab1..1d8ae9f 100644 --- a/microkde/kdecore/klocale.cpp +++ b/microkde/kdecore/klocale.cpp @@ -268,6 +268,43 @@ QString KLocale::translate( const char *, const char *fallback) const return i18n( fallback ); } +int KLocale::weekNum ( const QDate & date ) +{ + QDate seda = date; + int weekNum = 0; + int dayofweek = seda.dayOfWeek(); // 1... 7 Mo .. So. Do = 4 + int daystoprevthursday = (dayofweek + 3) % 7 ; + int dayofyear = seda.dayOfYear(); + int prevThursday = dayofyear - ( daystoprevthursday ); + int subweeknum = 0; + if ( prevThursday < 1 ) { + seda = seda.addDays( - daystoprevthursday ); + dayofyear = seda.dayOfYear(); + prevThursday = dayofyear; + subweeknum = prevThursday / 7; + if ( prevThursday % 7 != 0 ) + ++subweeknum; + } else { + if ( dayofyear >= 360 ) { //maybe week 1 + seda = seda.addDays( 7 - daystoprevthursday ); + dayofyear = seda.dayOfYear(); + if ( dayofyear < 360 && ( dayofweek < 4 || dayofweek == 7 && !mWeekStartsMonday ) ) + return 1; + } + } + if ( ! weekNum ) { + weekNum = prevThursday / 7; + if ( prevThursday % 7 != 0 ) + ++weekNum; + if ( dayofweek < 4 ) + ++weekNum; + else if ( dayofweek == 7 && !mWeekStartsMonday ) + ++weekNum; + if ( weekNum > subweeknum ) + weekNum -= subweeknum; + } + return weekNum; +} QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat intIntDateFormat) const { const QString rst = timeFormat(intIntDateFormat); diff --git a/microkde/kdecore/klocale.h b/microkde/kdecore/klocale.h index 14660d6..58e0b39 100644 --- a/microkde/kdecore/klocale.h +++ b/microkde/kdecore/klocale.h @@ -65,7 +65,7 @@ class KLocale QString monthName(int,bool=false) const; QString country() const; - + int weekNum ( const QDate & ); QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const; QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const; QString timeFormat(IntDateFormat intIntDateFormat = Undefined) const; -- cgit v0.9.0.2