-rw-r--r-- | microkde/kdecore/klocale.cpp | 37 | ||||
-rw-r--r-- | microkde/kdecore/klocale.h | 2 |
2 files changed, 38 insertions, 1 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 | |||
@@ -267,8 +267,45 @@ QString KLocale::translate( const char *, const char *fallback) const | |||
267 | { | 267 | { |
268 | return i18n( fallback ); | 268 | return i18n( fallback ); |
269 | } | 269 | } |
270 | 270 | ||
271 | int KLocale::weekNum ( const QDate & date ) | ||
272 | { | ||
273 | QDate seda = date; | ||
274 | int weekNum = 0; | ||
275 | int dayofweek = seda.dayOfWeek(); // 1... 7 Mo .. So. Do = 4 | ||
276 | int daystoprevthursday = (dayofweek + 3) % 7 ; | ||
277 | int dayofyear = seda.dayOfYear(); | ||
278 | int prevThursday = dayofyear - ( daystoprevthursday ); | ||
279 | int subweeknum = 0; | ||
280 | if ( prevThursday < 1 ) { | ||
281 | seda = seda.addDays( - daystoprevthursday ); | ||
282 | dayofyear = seda.dayOfYear(); | ||
283 | prevThursday = dayofyear; | ||
284 | subweeknum = prevThursday / 7; | ||
285 | if ( prevThursday % 7 != 0 ) | ||
286 | ++subweeknum; | ||
287 | } else { | ||
288 | if ( dayofyear >= 360 ) { //maybe week 1 | ||
289 | seda = seda.addDays( 7 - daystoprevthursday ); | ||
290 | dayofyear = seda.dayOfYear(); | ||
291 | if ( dayofyear < 360 && ( dayofweek < 4 || dayofweek == 7 && !mWeekStartsMonday ) ) | ||
292 | return 1; | ||
293 | } | ||
294 | } | ||
295 | if ( ! weekNum ) { | ||
296 | weekNum = prevThursday / 7; | ||
297 | if ( prevThursday % 7 != 0 ) | ||
298 | ++weekNum; | ||
299 | if ( dayofweek < 4 ) | ||
300 | ++weekNum; | ||
301 | else if ( dayofweek == 7 && !mWeekStartsMonday ) | ||
302 | ++weekNum; | ||
303 | if ( weekNum > subweeknum ) | ||
304 | weekNum -= subweeknum; | ||
305 | } | ||
306 | return weekNum; | ||
307 | } | ||
271 | QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat intIntDateFormat) const | 308 | QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat intIntDateFormat) const |
272 | { | 309 | { |
273 | const QString rst = timeFormat(intIntDateFormat); | 310 | const QString rst = timeFormat(intIntDateFormat); |
274 | 311 | ||
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 | |||
@@ -64,9 +64,9 @@ class KLocale | |||
64 | QString weekDayName(int,bool=false) const; | 64 | QString weekDayName(int,bool=false) const; |
65 | QString monthName(int,bool=false) const; | 65 | QString monthName(int,bool=false) const; |
66 | 66 | ||
67 | QString country() const; | 67 | QString country() const; |
68 | 68 | int weekNum ( const QDate & ); | |
69 | QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const; | 69 | QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const; |
70 | QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const; | 70 | QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const; |
71 | QString timeFormat(IntDateFormat intIntDateFormat = Undefined) const; | 71 | QString timeFormat(IntDateFormat intIntDateFormat = Undefined) const; |
72 | 72 | ||