setLayout(vl=new QVBoxLayout);
vl->addLayout(fl=new QFormLayout,0);
if(m_addr.isValid())
- fl->addRow(tr("Last used:"),new QLabel(QDateTime::fromTime_t(m_addr.lastused()).toString()));
+ fl->addRow(tr("Last used:"),new QLabel(MLocalFormat().formatDateTime(m_addr.lastused())));
fl->addRow(tr("Name:"),m_name=new QLineEdit(m_addr.name()));
fl->addRow(tr("Address:"),m_addr1=new QLineEdit(m_addr.addr1()));
fl->addRow(tr("Address:"),m_addr2=new QLineEdit(m_addr.addr2()));
#include "eventedit.h"
+#include "tzdata.h"
+
#include <QBoxLayout>
#include <QCheckBox>
#include <QDateTimeEdit>
starttime->setDateTime(tt);
endtime->setDateTime(tt.addSecs(3600));
}else{//valid event: use the date and time from event
- starttime->setDateTime(QDateTime::fromTime_t(event.start()));
- endtime->setDateTime(QDateTime::fromTime_t(event.end()));
+ starttime->setDateTime(TimeStamp(event.start()));
+ endtime->setDateTime(TimeStamp(event.end()));
}
gl->addWidget(lab=new QLabel(tr("Room/Place:")),++lctr,0);
{
//copy contents to event
event.settitle(title->text());
- event.setstart(starttime->dateTime().toTime_t());
- event.setend(endtime->dateTime().toTime_t());
+ event.setstart(TimeStamp(starttime->dateTime(),true).toUnix());
+ event.setend(TimeStamp(endtime->dateTime(),true).toUnix());
event.setiscancelled(cancelcheck->isChecked());
event.setcancelreason(cancelreason->text());
event.setdescription(description->toPlainText());
lang.toAscii().data(),
gl.errorType().toAscii().data(),
gl.errorString().toAscii().data());
- goto script;
+ //go to fallback
+ gl=MTGetLanguage::query("C","qm");
+ if(gl.hasError()){
+ qDebug("MSInterface: cannot retrieve language 'C', giving up on languages.");
+ goto script;
+ }
}
servertranslation=gl.getfile().value();
QTranslator *trn=new QTranslator(this);
trn->load((const uchar*)servertranslation.data(),servertranslation.size());
qApp->installTranslator(trn);
qDebug("MSInterface: successfully loaded server language %s",lang.toAscii().data());
+ MLocalFormat::setDefaultFormat(gl.getformats().value());
}
//TODO: retrieve scripts
script: ;
#include "misc.h"
+#include <tzdata.h>
+
#include <math.h>
+#include "MOServerFormat.h"
+
#include <QCoreApplication>
#include <QDateTime>
{
m_moneydecimals=2;
m_thousanddigits=3;
+ m_timezone="UTC";
//set defaults
setWeekDays();setShortWeekDays();
setMonths();setShortMonths();
setMoneyFormat(s.currencysymbol(),s.moneydecimals(),s.moneynegative());
setNumberFormat(s.decimaldot().value().at(0),s.thousandseparator().value().at(0),s.thousanddigits().value());
setAP(s.amtext(),s.pmtext());
+ setTimeZone(s.timezone());
}
void MLocalFormat::setDefaultFormat(const MLocalFormat& f)
{
defaultformat=f;
+ TimeStamp::setDefaultZone(f.m_timezone);
}
m_am=f.m_am;
m_pm=f.m_pm;
m_moneyneg=f.m_moneyneg;
+ m_timezone=f.m_timezone;
return *this;
}
{
if(w.size()==0){
m_day=QStringList()
+ <<QCoreApplication::translate("MLocalFormat","Sunday")
<<QCoreApplication::translate("MLocalFormat","Monday")
<<QCoreApplication::translate("MLocalFormat","Tuesday")
<<QCoreApplication::translate("MLocalFormat","Wednesday")
<<QCoreApplication::translate("MLocalFormat","Thursday")
<<QCoreApplication::translate("MLocalFormat","Friday")
- <<QCoreApplication::translate("MLocalFormat","Saturday")
- <<QCoreApplication::translate("MLocalFormat","Sunday");
+ <<QCoreApplication::translate("MLocalFormat","Saturday");
}else
if(w.size()==7)
m_day=w;
{
if(w.size()==0){
m_sday=QStringList()
+ <<QCoreApplication::translate("MLocalFormat","Sun","short weekday")
<<QCoreApplication::translate("MLocalFormat","Mon","short weekday")
<<QCoreApplication::translate("MLocalFormat","Tue","short weekday")
<<QCoreApplication::translate("MLocalFormat","Wed","short weekday")
<<QCoreApplication::translate("MLocalFormat","Thu","short weekday")
<<QCoreApplication::translate("MLocalFormat","Fri","short weekday")
- <<QCoreApplication::translate("MLocalFormat","Sat","short weekday")
- <<QCoreApplication::translate("MLocalFormat","Sun","short weekday");
+ <<QCoreApplication::translate("MLocalFormat","Sat","short weekday");
}else
if(w.size()==7)
m_sday=w;
QString MLocalFormat::formatDate(const QDate&date,QString format)const
{
+ return formatDate(TimeStamp(date,m_timezone),format);
+}
+QString MLocalFormat::formatDate(const TimeStamp& date, QString format) const
+{
if(format=="")format=QCoreApplication::translate("MLocalFormat","%Y-%M-%D","date format");
- return formatDateTime(QDateTime(date),format);
+ return formatDateTime(date,format);
}
QString MLocalFormat::formatDate(qint64 date,QString format)const
{
- return formatDate(unix2localTime(date).date(),format);
+ return formatDate(TimeStamp(date,m_timezone),format);
}
-QString MLocalFormat::formatTime(const QTime&time,QString format)const
+QString MLocalFormat::formatTime(const TimeStamp& time, QString format) const
{
if(format=="")format=QCoreApplication::translate("MLocalFormat","%h:%I","time format");
- return formatDateTime(QDateTime(QDate::currentDate(),time),format);
+ return formatDateTime(time,format);
+}
+QString MLocalFormat::formatTime(const QTime&time,QString format)const
+{
+ return formatTime(TimeStamp(time,m_timezone),format);
}
QString MLocalFormat::formatTime(qint64 time,QString format)const
{
- return formatTime(unix2localTime(time).time(),format);
+ return formatTime(TimeStamp(time,m_timezone),format);
}
QString MLocalFormat::formatDateTime(const QDateTime&time,QString format)const
{
+ return formatDateTime(TimeStamp(time,m_timezone),format);
+}
+QString MLocalFormat::formatDateTime(const TimeStamp& ts, QString format) const
+{
if(format=="")format=QCoreApplication::translate("MLocalFormat","%Y-%M-%D %h:%I","date and time format");
//parse
+ TimeStamp time=ts.toZone(m_timezone);
QString out;
bool inp=false;
for(int i=0;i<format.size();i++){
if(inp){
switch(format[i].unicode()){
//date format codes
- case 'Y':out+=QString::number(time.date().year());break;
+ case 'Y':out+=QString::number(time.year());break;
case 'y':{
- QString y=QString::number(time.date().year()%100);
+ QString y=QString::number(time.year()%100);
if(y.size()<2)y="0"+y;
out+=y;
break;
}
- case 'm':out+=QString::number(time.date().month());break;
+ case 'm':out+=QString::number(time.month());break;
case 'M':{
- QString m=QString::number(time.date().month());
+ QString m=QString::number(time.month());
if(m.size()<2)m="0"+m;
out+=m;
break;
}
- case 'n':out+=m_smonth[time.date().month()-1];break;
- case 'N':out+=m_month[time.date().month()-1];break;
- case 'd':out+=QString::number(time.date().day());break;
+ case 'n':out+=m_smonth[time.month()-1];break;
+ case 'N':out+=m_month[time.month()-1];break;
+ case 'd':out+=QString::number(time.day());break;
case 'D':{
- QString m=QString::number(time.date().day());
+ QString m=QString::number(time.day());
if(m.size()<2)m="0"+m;
out+=m;
break;
}
- case 'w':out+=m_sday[time.date().dayOfWeek()-1];break;
- case 'W':out+=m_day[time.date().dayOfWeek()-1];break;
+ case 'w':out+=m_sday[time.weekDay()];break;
+ case 'W':out+=m_day[time.weekDay()];break;
//time formats
- case 'h':out+=QString::number(time.time().hour());break;
+ case 'h':out+=QString::number(time.hour());break;
case 'H':{
- QString t=QString::number(time.time().hour());
+ QString t=QString::number(time.hour());
if(t.size()<2)t="0"+t;
out+=t;
break;
}
- case 'i':out+=QString::number(time.time().minute());break;
+ case 'i':out+=QString::number(time.minute());break;
case 'I':{
- QString t=QString::number(time.time().minute());
+ QString t=QString::number(time.minute());
if(t.size()<2)t="0"+t;
out+=t;
break;
}
- case 's':out+=QString::number(time.time().second());break;
+ case 's':out+=QString::number(time.second());break;
case 'S':{
- QString t=QString::number(time.time().second());
+ QString t=QString::number(time.second());
if(t.size()<2)t="0"+t;
out+=t;
break;
}
- case 'z':out+=QString::number(time.time().msec());break;
+ case 'z':out+=QString::number(time.msecs());break;
case 'Z':{
- QString t=QString::number(time.time().msec());
+ QString t=QString::number(time.msecs());
while(t.size()<3)t="0"+t;
out+=t;
break;
}
case 'a':{
- int t=time.time().hour()%12;if(t==0)t=12;
+ int t=time.hour()%12;if(t==0)t=12;
out+=QString::number(t);
break;
}
case 'A':{
- int th=time.time().hour()%12;if(th==0)th=12;
+ int th=time.hour()%12;if(th==0)th=12;
QString t=QString::number(th);
if(t.size()<2)t="0"+t;
out+=t;
break;
}
case 'p':{
- int t=time.time().hour();
+ int t=time.hour();
if(t>=1 && t<=12)out+="am";
else out+="pm";
break;
}
case 'P':{
- int t=time.time().hour();
+ int t=time.hour();
if(t>=1 && t<=12)out+="AM";
else out+="PM";
break;
}
- case 't':case 'T':{
+ case 't':out+=time.zoneAbbreviation();break;
+ case 'T':{
//get diff from UTC
- int d=time.secsTo(time.toUTC())/60;
+ int d=time.offsetFromUTC()/60;
//west(-) or east(+)?
QString t;
if(d<0){t="+";d*=-1;}else t="-";
out+=t;
break;
}
+ case 'o':out+=m_timezone;break;
// % sign
case '%':out+="%";break;
//mistakes
//return result
return out;
}
+
QString MLocalFormat::formatDateTime(qint64 time,QString format)const
{
- return formatDateTime(unix2localTime(time),format);
-}
-QDateTime MLocalFormat::unix2localTime(qint64 time)const
-{
- //TODO: use proper time zones
- return QDateTime::fromTime_t(time);
+ return formatDateTime(TimeStamp(time,m_timezone),format);
}
QString MLocalFormat::formatNumber(qint64 n)const
return QRegExp(r);
}
-qint64 MLocalFormat::localTime2unix(QDateTime ) const
-{
-//TODO!!
-}
-
-void MLocalFormat::setTimeZone(QString olsenname)
+void MLocalFormat::setTimeZone(QString olsonname)
{
-//TODO!!
+ if(TimeStamp::loadZone(olsonname))
+ m_timezone=olsonname;
}
#include <QStringList>
#include <QRegExp>
-#include "MOServerFormat.h"
+class TimeStamp;
+class MOServerFormat;
/**converts special HTML characters into harmless &-codes, so the text can be included*/
QString htmlize(QString str);
<tr><td>%%p<td>"am" or "pm" according to current time, this is the one set with setAP</tr>
<tr><td>%%P<td>"AM" or "PM" according to current time, this is toUpper executed on the one set with setAP</tr>
<tr><td>%%T<td>ISO timezone as +/-hhmm (eg. -0100 or +0100) - does not work reliably on all systems</tr>
+<tr><td>%%t<td>timezone as abbreviation - the abbreviation comes from the background time zone DB and is not globally unique (eg. "CET")</tr>
+<tr><td>%%o<td>timezone as Olson name (eg. "Europe/Berlin")</tr>
</table>
Any occurrence of "%%" will be translated to a literal "%" sign.
/**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*/
+ /**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 Sunday*/
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)*/
+ /**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 Sunday (Sun)*/
virtual void setShortWeekDays(const QStringList&l=QStringList());
/**overrides the full names of months, an empty list resets to the local translation, otherwise the list must be exactly seven entries long and starts with January*/
virtual void setAP(QString am="--",QString pm="--");
/**overrides the local time zone
- \param olsenname the name of the local timezone in olsen notation, eg. "Europe/Berlin"
- \param transitions a list of time transitions, if missing the system attempts to locate the transition DB itself*/
- virtual void setTimeZone(QString olsenname);
+ \param olsenname the name of the local timezone in Olson notation, eg. "Europe/Berlin"*/
+ virtual void setTimeZone(QString olsonname);
+
+ /**returns the currently set time zone of this formatter*/
+ virtual QString timeZone()const{return m_timezone;}
/**overrides the formatting to be non-localized, numbers use decimal dot and no thousand separator, no currency symbol and "-" as negative sign; otherwise things stay the same; this is a helper for the shortcut methods like cent2str*/
virtual void setNonLocalized();
/**formats a date according to the given format, if none is given, the translation default is used
- \param date a QDate used as input, it is assumed to be local, even if Qt sais it is UTC
- \param format a format string as specified by QDate::toString */
+ \param date a QDate used as input, it is assumed to be local
+ \param format a format string */
virtual QString formatDate(const QDate&date,QString format=QString())const;
/**formats a date according to the given format, if none is given, the translation default is used
- \param date a unix timestamp, it is converted to local time*/
+ \param date a unix timestamp, it is converted to the local time of this local format object
+ \param format a format string */
virtual QString formatDate(qint64 date,QString format=QString())const;
+ /**formats a date according to the given format, if none is given, the translation default is used
+ \param date a timestamp, it is converted to the local time of this local format object
+ \param format a format string */
+ virtual QString formatDate(const TimeStamp& date,QString format=QString())const;
/**formats a time according to the given format, if none is given, the translation default is used
- \param time a QTime used as input
- \param format a format string as specified by QTime::toString */
+ \param time a QTime used as input, it is assumed to be local
+ \param format a format string */
virtual QString formatTime(const QTime&time,QString format=QString())const;
/**formats a time according to the given format, if none is given, the translation default is used
- \param time a unix timestamp, it is converted to local time*/
+ \param time a unix timestamp, it is converted to local time
+ \param format a format string */
virtual QString formatTime(qint64 time,QString format=QString())const;
+ /**formats a time according to the given format, if none is given, the translation default is used
+ \param time a timestamp, it is converted to the local time of this local format object
+ \param format a format string */
+ virtual QString formatTime(const TimeStamp& time,QString format=QString())const;
/**formats a date and time according to the given format, if none is given, the translation default is used
- \param time a QDateTime used as input
+ \param time a QDateTime used as input, it is assumed to be local
\param format a format string as specified by QDateTime::toString */
virtual QString formatDateTime(const QDateTime&time,QString format=QString())const;
/**formats a date and time according to the given format, if none is given, the translation default is used
- \param time a unix timestamp, it is converted to local time*/
+ \param time a unix timestamp, it is converted to local time
+ \param format a format string as specified by QDateTime::toString */
virtual QString formatDateTime(qint64 time,QString format=QString())const;
+ /**formats a date and time according to the given format, if none is given, the translation default is used
+ \param time a TimeStamp used as input, it is converted to the local time of this local format object
+ \param format a format string as specified by QDateTime::toString */
+ virtual QString formatDateTime(const TimeStamp&time,QString format=QString())const;
/**formats an integer number*/
QRegExp moneyRegExp(bool allownegative=false,bool allowcurrency=false)const;
protected:
QStringList m_day,m_sday,m_month,m_smonth;
- QString m_currency,m_am,m_pm,m_moneyneg;
+ QString m_currency,m_am,m_pm,m_moneyneg,m_timezone;
QChar m_decimal,m_thousand;
int m_moneydecimals,m_thousanddigits;
- /** \internal helper to convert a unix timestamp to local time*/
- virtual QDateTime unix2localTime(qint64)const;
-
- /** \internal helper to convert a local timestamp to unix time*/
- virtual qint64 localTime2unix(QDateTime)const;
-
/** \internal constructs the default object from the translation*/
MLocalFormat(int);
/** \internal default format*/
#include "eventstab.h"
+#include "tzdata.h"
+
#include <QApplication>
#include <QBoxLayout>
#include <QCheckBox>
}
QList<MOEvent>evl=gae.getevents();
//calculate max age
- QDateTime now=QDateTime::currentDateTime().addDays(-1);
+ TimeStamp now=TimeStamp::now();
bool showveryold=false;
bool showold;
if(showoldevents)showold=showoldevents->isChecked();
set.beginGroup("profiles/"+profilekey);
int maxage=set.value("maxeventage", 0).toInt();
if(maxage==0)showveryold=true;
- now=now.addDays(-maxage);
+ now.addDays(-maxage);
}
//fill model
eventmodel->clear();
eventmodel->setHorizontalHeaderLabels(QStringList()<<tr("Start Time")<<tr("Title")<<tr("Free")<<tr("Reserved")<<tr("Sold")<<tr("Capacity"));
for(int i=0,j=0;i<evl.size();i++){
//filter by time
- QDateTime stime=QDateTime::fromTime_t(evl[i].start());
+ TimeStamp stime=TimeStamp(evl[i].start());
if(!showveryold && stime<now)continue;
//show
eventmodel->insertRow(j);
#include "orderstab.h"
+#include "tzdata.h"
+
#include <QBoxLayout>
#include <QComboBox>
#include <QDateTimeEdit>
//zero means no limit
if(age<=0)return 0;
//calculate
- return QDateTime::currentDateTime().addDays(-age).toTime_t();
+ TimeStamp ts=TimeStamp::now();ts.addDays(-age);
+ return ts.toUnix();
}
//helper: finds out whether an order should be printed.
d.setLayout(vl=new QVBoxLayout);
vl->addWidget(new QLabel(tr("Please select the date and time:")));
QDateTimeEdit*dte;
- vl->addWidget(dte=new QDateTimeEdit(QDateTime::fromTime_t(oldestOrderStamp())));
+ vl->addWidget(dte=new QDateTimeEdit(TimeStamp(oldestOrderStamp()).toDateTime()));
dte->setDisplayFormat(tr("ddd MMMM d yyyy, h:mm ap","time format"));
dte->setCalendarPopup(true);
vl->addSpacing(10);vl->addStretch(1);
#include "overview.h"
#include "centbox.h"
+#include "tzdata.h"
#include <QBoxLayout>
#include <QCheckBox>
#include "MOEvent.h"
#include <QCoreApplication>
-#include <QDateTime>
#include <QRegExp>
#include <QStringList>
return status()!=Placed;
}
-QDateTime MOOrder::orderDateTime()
+TimeStamp MOOrder::orderDateTime()
{
- if(ordertime().value()==0)return QDateTime();
- return QDateTime::fromTime_t(ordertime());
+ if(ordertime().value()==0)return TimeStamp();
+ return TimeStamp(ordertime());
}
QString MOOrder::orderDateTimeStr()
{
if(ordertime().value()==0)return "";
- return QDateTime::fromTime_t(ordertime()).toString(QCoreApplication::translate("MOOrder","yyyy-MM-dd hh:mm ap","date/time format"));
-}
-
-QDate MOOrder::orderDate()
-{
- return QDateTime::fromTime_t(ordertime()).date();
+ return unix2dateTime(ordertime());
}
QString MOOrder::orderDateStr()
{
if(ordertime().value()==0)return "";
- return QDateTime::fromTime_t(ordertime()).toString(QCoreApplication::translate("MOOrder","yyyy-MM-dd","date format"));
+ return unix2date(ordertime());
}
-QDateTime MOOrder::sentDateTime()
+TimeStamp MOOrder::sentDateTime()
{
- return QDateTime::fromTime_t(senttime());
+ return TimeStamp(senttime());
}
QString MOOrder::sentDateTimeStr()
{
if(senttime().value()==0)return "";
- return QDateTime::fromTime_t(senttime()).toString(QCoreApplication::translate("MOOrder","yyyy-MM-dd hh:mm ap","date/time format"));
-}
-
-QDate MOOrder::sentDate()
-{
- return QDateTime::fromTime_t(senttime()).date();
+ return unix2dateTime(senttime());
}
QString MOOrder::sentDateStr()
{
if(senttime().value()==0)return "";
- return QDateTime::fromTime_t(senttime()).toString(QCoreApplication::translate("MOOrder","yyyy-MM-dd","date format"));
+ return unix2date(senttime());
}
QString MOOrder::fullInvoiceAddress(bool allowfallback)const
#include "MOOrderAbstract.h"
#include "misc.h"
-#include <QDate>
-#include <QDateTime>
+#include "tzdata.h"
/**this class represents a complete order*/
class MOOrder:public MOOrderAbstract
QString amountToRefundStr()const{return cent2str(amountToRefund());}
/**return the order date+time*/
- QDateTime orderDateTime();
+ TimeStamp orderDateTime();
/**returns the order date+time as string*/
QString orderDateTimeStr();
- /**returns the order date only*/
- QDate orderDate();
-
/**returns the order date only as string*/
QString orderDateStr();
/**returns the shipping date+time*/
- QDateTime sentDateTime();
+ TimeStamp sentDateTime();
/**returns the shipping date+time as string*/
QString sentDateTimeStr();
- /**returns the shipping date only*/
- QDate sentDate();
-
/**returns the shipping date only as string*/
QString sentDateStr();