summaryrefslogtreecommitdiffabout
path: root/microkde
authorzautrix <zautrix>2005-03-28 23:39:37 (UTC)
committer zautrix <zautrix>2005-03-28 23:39:37 (UTC)
commit4e7c45695672ecdbd0cd14cac0ea29a8e134ee78 (patch) (side-by-side diff)
tree6815e055d6cb35d56d43f036261f5be9d2a9c350 /microkde
parent4034290f894ff7d1b0cf1197078e0ed832566bb7 (diff)
downloadkdepimpi-4e7c45695672ecdbd0cd14cac0ea29a8e134ee78.zip
kdepimpi-4e7c45695672ecdbd0cd14cac0ea29a8e134ee78.tar.gz
kdepimpi-4e7c45695672ecdbd0cd14cac0ea29a8e134ee78.tar.bz2
montview sunday fix
Diffstat (limited to 'microkde') (more/less context) (show whitespace changes)
-rw-r--r--microkde/kdecore/klocale.cpp37
-rw-r--r--microkde/kdecore/klocale.h2
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
@@ -223,96 +223,133 @@ void KLocale::setDateFormatShort( QString s )
}
void KLocale::setHore24Format ( bool b )
{
mHourF24Format = b;
}
void KLocale::setWeekStartMonday( bool b )
{
mWeekStartsMonday = b;
}
KLocale::IntDateFormat KLocale::getIntDateFormat( )
{
return mIntDateFormat;
}
void KLocale::setIntDateFormat( KLocale::IntDateFormat i )
{
mIntDateFormat = i;
}
KLocale::IntDateFormat KLocale::getIntTimeFormat( )
{
return mIntTimeFormat;
}
void KLocale::setIntTimeFormat( KLocale::IntDateFormat i )
{
mIntTimeFormat = i;
}
void KLocale::setLanguage( int i )
{
mLanguage = i;
}
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;
for ( uint format_index = 0; format_index < rst.length(); format_index++ )
{
if ( !escape )
{
if ( rst.at( format_index ).unicode() == '%' )
escape = true;
else
buffer[index++] = rst.at( format_index );
}
else
{
switch ( rst.at( format_index ).unicode() )
{
case '%':
buffer[index++] = '%';
break;
case 'H':
put_it_in( buffer, index, pTime.hour() );
break;
case 'I':
put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 );
break;
case 'M':
put_it_in( buffer, index, pTime.minute() );
break;
case 'S':
if (includeSecs)
put_it_in( buffer, index, pTime.second() );
else
{
// we remove the seperator sign before the seconds and
// assume that works everywhere
--index;
break;
}
break;
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
@@ -20,97 +20,97 @@ QString i18n(const char *text1, const char *textn, int num);
// with our i18n method. we use uic -tr tr2i18n to redirect
// to the right i18n() function
inline QString tr2i18n(const char* message, const char* =0) {
return i18n( message);
}
class KLocale
{
public:
KLocale();
QString formatNumber(double num, int precision = -1) const;
QString formatNumber(const QString &numStr) const;
double readNumber(const QString &numStr, bool * ok = 0) const;
QString decimalSymbol() const;
QString thousandsSeparator() const;
QString positiveSign() const;
QString negativeSign() const;
QString translate( const char *index ) const;
QString translate( const char *index, const char *fallback) const;
enum IntDateFormat { Undefined=-1, Default=0, Format1=1, ISODate=2, Userdefined=3 };
QString formatDate(const QDate &pDate, bool shortFormat = false, IntDateFormat intIntDateFormat = Undefined) const;
QString formatTime(const QTime &pTime, bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const;
QString formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat = Undefined) const;
QString formatDateTime(const QDateTime &pDateTime,
bool shortFormat,
bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const;
QDate readDate(const QString &str, bool* ok = 0) const;
QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const;
QTime readTime(const QString &str, bool* ok = 0) const;
QDate readDate(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const;
QDateTime readDateTime(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const;
bool use12Clock() const;
bool weekStartsMonday() const;
int weekStartDay() const;
QString weekDayName(int,bool=false) const;
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;
void insertCatalogue ( const QString & );
KCalendarSystem *calendar();
void setHore24Format ( bool );
void setWeekStartMonday( bool );
void setIntDateFormat( IntDateFormat );
void setIntTimeFormat( IntDateFormat );
IntDateFormat getIntDateFormat( );
IntDateFormat getIntTimeFormat( );
void setLanguage( int );
int language();
void setDateFormat( QString );
void setDateFormatShort( QString );
QString m_decimalSymbol;
QString m_thousandsSeparator;
QString m_currencySymbol;
QString m_monetaryDecimalSymbol;
QString m_monetaryThousandsSeparator;
QString m_positiveSign;
QString m_negativeSign;
int timezoneOffset( QString );
QStringList timeZoneList() const;
void setDaylightSaving( bool, int , int );
int localTimeOffset(const QDateTime &);
void setTimezone( const QString &timeZone , bool oddTZ);
private:
QTime readTime(const QString &str, bool seconds, bool *ok) const;
QDate readDate(const QString &str, bool shortFormat, bool *ok) const;
KCalendarSystem *mCalendarSystem;
bool mWeekStartsMonday;
bool mHourF24Format;
IntDateFormat mIntDateFormat;
IntDateFormat mIntTimeFormat;
int mLanguage;
QString mDateFormat;
QString mDateFormatShort;
QStringList mTimeZoneList;
bool daylightEnabled;
int mDaylightTZoffset;
int mNondaylightTZoffset;
bool mSouthDaylight;
int daylightStart, daylightEnd, mTimeZoneOffset;