From: konrad Date: Sun, 20 Jun 2010 08:48:09 +0000 (+0000) Subject: date modifiers for localizer X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=f477d2811ac283c0db6a96d15f1e635ec1ea7fe6;p=web%2Fkonrad%2Fsmoke.git date modifiers for localizer git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@507 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/src/misc/misc.cpp b/src/misc/misc.cpp index 391d8f9..b175de1 100644 --- a/src/misc/misc.cpp +++ b/src/misc/misc.cpp @@ -126,6 +126,11 @@ MLocalFormat::MLocalFormat() MLocalFormat::MLocalFormat(const MLocalFormat&f) { + operator=(f); +} + +MLocalFormat& MLocalFormat::operator=(const MLocalFormat&f) +{ m_day=f.m_day; m_sday=f.m_sday; m_month=f.m_month; @@ -135,6 +140,9 @@ MLocalFormat::MLocalFormat(const MLocalFormat&f) m_thousand=f.m_thousand; m_moneydecimals=f.m_moneydecimals; m_thousanddigits=f.m_thousanddigits; + m_am=f.m_am; + m_pm=f.m_pm; + return *this; } MLocalFormat::~MLocalFormat(){} @@ -215,6 +223,14 @@ void MLocalFormat::setMoneyFormat(QString c,int n) m_moneydecimals=n; } +void MLocalFormat::setAP(QString am,QString pm) +{ + if(am=="--")m_am=CoreApplication::translate("MLocalFormat","am","AM/PM time component"); + else m_am=am; + if(pm=="--")m_pm=CoreApplication::translate("MLocalFormat","pm","AM/PM time component"); + else m_pm=pm; +} + void MLocalFormat::setNumberFormat(QChar dec,QChar thou,int dig) { if(dec.isNull())m_decimal=QCoreApplication::translate("MLocalFormat",".","decimal dot")[0]; @@ -229,13 +245,13 @@ void MLocalFormat::setNumberFormat(QChar dec,QChar thou,int dig) QString MLocalFormat::formatDate(const QDate&date,QString format)const { if(format=="")format=QCoreApplication::translate("MLocalFormat","%Y-%M-%D","date format"); - return formatDateTime(date,format); + return formatDateTime(QDateTime(date),format); } QString MLocalFormat::formatDate(qint64 date,QString format)const { return formatDate(unix2localTime(date).date(),format); } -QString MLocalFormat::formatTime(const QTime&time,QString format=QString())const +QString MLocalFormat::formatTime(const QTime&time,QString format)const { if(format=="")format=QCoreApplication::translate("MLocalFormat","%h:%I","time format"); return formatDateTime(QDateTime(QDate::currentDate(),time),format); @@ -248,13 +264,103 @@ QString MLocalFormat::formatDateTime(const QDateTime&time,QString format)const { if(format=="")format=QCoreApplication::translate("MLocalFormat","%Y-%M-%D %H:%I","date and time format"); //parse - ... + QString out; + bool inp=false; + for(int i=0;i=1 && t<=12)out+="am"; + else out+="pm"; + break; + } + case 'P':{ + int t=time.time().hour(); + if(t>=1 && t<=12)out+="AM"; + else out+="PM"; + break; + } + //% sign + case '%':out+="%";break; + //mistakes + default:out+="%"+format[i];break; + } + }else{ + if(format[i]=='%')inp=true; + else out+=format[i]; + } + } + //catch mistaken % at end + if(inp)out+="%"; + //return result + return out; } QString MLocalFormat::formatDateTime(qint64 time,QString format)const { return formatDateTime(unix2localTime(time),format); } -QDateTime MLocalFormat::unix2localTime(qint64 time) +QDateTime MLocalFormat::unix2localTime(qint64 time)const { //TODO: use proper time zones return QDateTime::fromTime_t(time); diff --git a/src/misc/misc.h b/src/misc/misc.h index 40a1fa0..343076d 100644 --- a/src/misc/misc.h +++ b/src/misc/misc.h @@ -89,6 +89,9 @@ class MLocalFormat /**deletes the formatter object*/ virtual ~MLocalFormat(); + /**copies a formatter object*/ + virtual MLocalFormat& operator=(const MLocalFormat&); + /**overrides the full names of week days, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Monday*/ virtual void setWeekDays(const QStringList&l=QStringList()); /**overrides the short week day names, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with Monday (Mon)*/ @@ -110,6 +113,9 @@ class MLocalFormat \param digitsDiv defines the amount of digits in a block, eg. the value 3 will format 1000 as 1,000*/ virtual void setNumberFormat(QChar decimal=QChar(),QChar thousandDiv=QChar(),int digitsDiv=-1); + /**overrides the formatting of the AM/PM part of time display, resets to the localization if none given*/ + virtual void setAP(QString am="--",QString pm="--"); + /**formats a date according to the given format, if none is given, the translation default is used \param date a QDate used as input \param format a format string as specified by QDate::toString */ @@ -135,12 +141,12 @@ class MLocalFormat virtual QString formatDateTime(qint64 time,QString format=QString())const; protected: QStringList m_day,m_sday,m_month,m_smonth; - QString m_currency; + QString m_currency,m_am,m_pm; QChar m_decimal,m_thousand; int m_moneydecimals,m_thousanddigits; /** \internal helper to convert a unix timestamp to local time*/ - virtual QDateTime unix2localTime(qint64); + virtual QDateTime unix2localTime(qint64)const; }; #endif