#include <DateTime.h>
Public Member Functions | |
| void | addDays (int d) |
| void | addHours (int h) |
| void | addMinutes (int m) |
| void | addMonths (int m) |
| void | addSeconds (double s) |
| void | addYears (int y) |
| QDate | date () const |
| QDateTime | dateTime () const |
| DateTimeData () | |
| DateTimeData (const QDateTime &dt) | |
| DateTimeData (const DateTimeData &o) | |
| double | fractions () const |
| bool | fromString (const QString &text, const QString &format) |
| void | fromTime_t (time_t t) |
| void | fromTime_t (QString t) |
| int | hour () const |
| bool | isNull () const |
| int | minute () const |
| bool | operator!= (const DateTimeData &o) |
| bool | operator< (const DateTimeData &o) |
| void | operator= (const DateTimeData &o) |
| bool | operator== (const DateTimeData &o) |
| bool | operator> (const DateTimeData &o) |
| int | second () const |
| double | secondsTo (const DateTimeData &o) const |
| bool | setDate (int year=1900, int month=1, int day=1) |
| void | setDate (const QDate &d) |
| void | setDateTime (const QDateTime &dt) |
| bool | setTime (int hour=0, int minute=0, int second=0, double fractions=0.0) |
| QString | toString (const QString &format, int precision) const |
| time_t | toTime_t () const |
| QString | toTime_t (int precision) const |
| ~DateTimeData () | |
| QGpCoreTools::DateTimeData::DateTimeData | ( | ) | [inline] |
{
_seconds=0;
_fractions=0.0;
}
| QGpCoreTools::DateTimeData::DateTimeData | ( | const QDateTime & | dt | ) | [inline] |
: QSharedData()
{
_date=dt.date();
_seconds=QTime(0,0).secsTo(dt.time());
_fractions=0;
}
| QGpCoreTools::DateTimeData::DateTimeData | ( | const DateTimeData & | o | ) | [inline] |
: QSharedData(o)
{
_date=o._date;
_seconds=o._seconds;
_fractions=o._fractions;
}
| QGpCoreTools::DateTimeData::~DateTimeData | ( | ) | [inline] |
{}
| void QGpCoreTools::DateTimeData::addDays | ( | int | d | ) | [inline] |
{
_date=_date.addDays(d);
}
| void QGpCoreTools::DateTimeData::addHours | ( | int | h | ) |
{
int d;
if(h<0) {
if(h<-24) {
d=h/24;
h-=d*24;
} else {
d=0;
}
_seconds+=h*60*60;
if(_seconds<0) {
d-=1;
_seconds+=86400;
}
} else {
if(h>24) {
d=h/24;
h-=d*24;
} else {
d=0;
}
_seconds+=h*60*60;
if(_seconds>86400) {
d+=1;
_seconds-=86400;
}
}
_date=_date.addDays((int)d);
}
| void QGpCoreTools::DateTimeData::addMinutes | ( | int | m | ) |
{
int d;
if(m<0) {
if(m<-60*24) {
d=m/(60*24);
m-=d*60*24;
} else {
d=0;
}
_seconds+=m*60;
if(_seconds<0) {
d-=1;
_seconds+=86400;
}
} else {
if(m>60*24) {
d=m/(60*24);
m-=d*60*24;
} else {
d=0;
}
_seconds+=m*60;
if(_seconds>86400) {
d+=1;
_seconds-=86400;
}
}
_date=_date.addDays((int)d);
}
| void QGpCoreTools::DateTimeData::addMonths | ( | int | m | ) | [inline] |
{
_date.addMonths(m);
}
| void QGpCoreTools::DateTimeData::addSeconds | ( | double | s | ) |
Add s seconds. can have have any size without any loss of precision.
{
double d;
if(s<0.0) {
if(s<-86400.0) {
d=floor(s/86400.0);
s-=d*86400.0;
} else {
d=0.0;
}
double sr=floor(s);
_seconds+=(int)sr;
s-=sr;
_fractions+=s;
if(_fractions<0.0) {
_fractions+=1.0;
_seconds-=1;
}
if(_seconds<0) {
d-=1;
_seconds+=86400;
}
} else {
if(s>86400.0) {
d=floor(s/86400.0);
s-=d*86400.0;
} else {
d=0.0;
}
double sr=floor(s);
_seconds+=(int)sr;
s-=sr;
_fractions+=s;
if(_fractions>=1.0) {
_fractions-=1.0;
_seconds+=1;
}
if(_seconds>86400) {
d+=1;
_seconds-=86400;
}
}
_date=_date.addDays((int)d);
}
| void QGpCoreTools::DateTimeData::addYears | ( | int | y | ) | [inline] |
{
_date.addYears(y);
}
| QDate QGpCoreTools::DateTimeData::date | ( | ) | const [inline] |
Referenced by QGpCoreTools::DateTimeToString::d_parsed(), QGpCoreTools::DateTimeToString::dd_parsed(), QGpCoreTools::DateTimeToString::ddd_parsed(), QGpCoreTools::DateTimeToString::dddd_parsed(), QGpCoreTools::DateTimeToString::M_parsed(), QGpCoreTools::DateTimeToString::MM_parsed(), QGpCoreTools::DateTimeToString::MMM_parsed(), QGpCoreTools::DateTimeToString::MMMM_parsed(), QGpCoreTools::DateTimeFromString::value(), QGpCoreTools::DateTimeToString::yy_parsed(), and QGpCoreTools::DateTimeToString::yyyy_parsed().
{return _date;}
| QDateTime QGpCoreTools::DateTimeData::dateTime | ( | ) | const [inline] |
{
QDateTime dt(_date);
dt=dt.addSecs(_seconds);
return dt;
}
| double QGpCoreTools::DateTimeData::fractions | ( | ) | const [inline] |
Referenced by setTime(), QGpCoreTools::DateTimeToString::ssz_parsed(), QGpCoreTools::DateTimeToString::sz_parsed(), QGpCoreTools::DateTimeToString::z_parsed(), and QGpCoreTools::DateTimeToString::zzz_parsed().
{return _fractions;}
| bool QGpCoreTools::DateTimeData::fromString | ( | const QString & | text, |
| const QString & | format | ||
| ) |
References QGpCoreTools::DateTimeParser::parse(), and QGpCoreTools::DateTimeFromString::value().
{
DateTimeFromString p(text);
if(p.parse(format)) {
bool ok;
*this=p.value(ok);
return ok;
} else {
return false;
}
}
| void QGpCoreTools::DateTimeData::fromTime_t | ( | time_t | t | ) |
Referenced by fromTime_t().
{
QDateTime dt;
dt.setTimeSpec(Qt::UTC);
dt.setTime_t(t);
_date=dt.date();
_seconds=dt.time().hour()*3600+dt.time().minute()*60+dt.time().second();
_fractions=0.0;
}
| void QGpCoreTools::DateTimeData::fromTime_t | ( | QString | t | ) |
References fromTime_t().
{
QRegExp dec("[\\.,]");
int decIndex=t.indexOf(dec, 0);
if(decIndex==-1) {
fromTime_t(t.toInt());
} else {
fromTime_t(t.left(decIndex).toInt());
_fractions=t.mid(decIndex).toDouble();
}
}
| int QGpCoreTools::DateTimeData::hour | ( | ) | const [inline] |
Referenced by QGpCoreTools::DateTimeToString::ap_parsed(), QGpCoreTools::DateTimeToString::AP_parsed(), QGpCoreTools::DateTimeToString::h_parsed(), QGpCoreTools::DateTimeToString::H_parsed(), QGpCoreTools::DateTimeToString::hh_parsed(), and QGpCoreTools::DateTimeToString::HH_parsed().
{return _seconds/3600;}
| bool QGpCoreTools::DateTimeData::isNull | ( | ) | const [inline] |
{return _date.isNull() && _seconds==0 && _fractions==0.0;}
| int QGpCoreTools::DateTimeData::minute | ( | ) | const [inline] |
Referenced by QGpCoreTools::DateTimeToString::m_parsed(), and QGpCoreTools::DateTimeToString::mm_parsed().
{return _seconds/60-hour()*60;}
| bool QGpCoreTools::DateTimeData::operator!= | ( | const DateTimeData & | o | ) | [inline] |
{
return _date!=o._date ||
_seconds!=o._seconds ||
_fractions!=o._fractions;
}
| bool QGpCoreTools::DateTimeData::operator< | ( | const DateTimeData & | o | ) | [inline] |
{
if(_date==o._date) {
if(_seconds==o._seconds) {
return _fractions<o._fractions;
} else {
return _seconds<o._seconds;
}
} else {
return _date<o._date;
}
}
| void QGpCoreTools::DateTimeData::operator= | ( | const DateTimeData & | o | ) | [inline] |
{
_date=o._date;
_seconds=o._seconds;
_fractions=o._fractions;
}
| bool QGpCoreTools::DateTimeData::operator== | ( | const DateTimeData & | o | ) | [inline] |
{
return _date==o._date &&
_seconds==o._seconds &&
_fractions==o._fractions;
}
| bool QGpCoreTools::DateTimeData::operator> | ( | const DateTimeData & | o | ) | [inline] |
{
if(_date==o._date) {
if(_seconds==o._seconds) {
return _fractions>o._fractions;
} else {
return _seconds>o._seconds;
}
} else {
return _date>o._date;
}
}
| int QGpCoreTools::DateTimeData::second | ( | ) | const [inline] |
Referenced by QGpCoreTools::DateTimeToString::s_parsed(), setTime(), QGpCoreTools::DateTimeToString::ss_parsed(), QGpCoreTools::DateTimeToString::ssz_parsed(), and QGpCoreTools::DateTimeToString::sz_parsed().
{return _seconds-(_seconds/60)*60;}
| double QGpCoreTools::DateTimeData::secondsTo | ( | const DateTimeData & | o | ) | const |
{
double s=0;
s+=_date.daysTo(o._date)*86400;
s+=o._seconds-_seconds;
s+=o._fractions-_fractions;
return s;
}
| bool QGpCoreTools::DateTimeData::setDate | ( | int | year = 1900, |
| int | month = 1, |
||
| int | day = 1 |
||
| ) | [inline] |
Referenced by QGpCoreTools::DateTimeFromString::value().
{
return _date.setDate(year, month, day);
}
| void QGpCoreTools::DateTimeData::setDate | ( | const QDate & | d | ) | [inline] |
{
_date=d;
}
| void QGpCoreTools::DateTimeData::setDateTime | ( | const QDateTime & | dt | ) | [inline] |
{
_date=dt.date();
_seconds=QTime(0,0,0).secsTo(dt.time());
_fractions=dt.time().msec()*0.001;
}
| bool QGpCoreTools::DateTimeData::setTime | ( | int | hour = 0, |
| int | minute = 0, |
||
| int | second = 0, |
||
| double | fractions = 0.0 |
||
| ) |
References fractions(), and second().
Referenced by QGpCoreTools::DateTimeFromString::value().
| QString QGpCoreTools::DateTimeData::toString | ( | const QString & | format, |
| int | precision | ||
| ) | const |
References QGpCoreTools::DateTimeParser::parse(), and QGpCoreTools::DateTimeToString::value().
{
DateTimeToString p(*this, precision);
p.parse(format);
return p.value();
}
| time_t QGpCoreTools::DateTimeData::toTime_t | ( | ) | const |
Referenced by toTime_t().
{
QDateTime dt;
dt.setDate(_date);
int h=_seconds/3600;
int m=_seconds/60-h*60;
int s=_seconds-m*60-h*3600;
dt.setTimeSpec(Qt::UTC);
dt.setTime(QTime(h, m, s));
return dt.toTime_t();
}
| QString QGpCoreTools::DateTimeData::toTime_t | ( | int | precision | ) | const |
References toTime_t().
{
QString s;
s+=QString::number(toTime_t());
s+=QString::number(_fractions, 'f', precision).mid(1);
return s;
}