summaryrefslogtreecommitdiffabout
path: root/microkde/kdecore/klocale.cpp
Side-by-side diff
Diffstat (limited to 'microkde/kdecore/klocale.cpp') (more/less context) (show whitespace changes)
-rw-r--r--microkde/kdecore/klocale.cpp37
1 files changed, 37 insertions, 0 deletions
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
@@ -259,24 +259,61 @@ int KLocale::language( )
return mLanguage;
}
QString KLocale::translate( const char *index ) const
{
return i18n( index );
}
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);
// only "pm/am" here can grow, the rest shrinks, but
// I'm rather safe than sorry
QChar *buffer = new QChar[rst.length() * 3 / 2 + 30];
uint index = 0;
bool escape = false;
int number = 0;