X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftime%2Fdatetime.cpp;h=f61e62e12ae2b3a18abc91fc6dcf9f8c953b06a5;hb=99b9121e2158603372c7313400283b622e6754d8;hp=e8170cc0246d26393b34d2d102d7005aa6d91e2e;hpb=2b6b7d97cb2b68c72299dcedc2dc986e775c8953;p=libs%2Fcore.git diff --git a/source/time/datetime.cpp b/source/time/datetime.cpp index e8170cc..f61e62e 100644 --- a/source/time/datetime.cpp +++ b/source/time/datetime.cpp @@ -45,52 +45,32 @@ namespace Time { DateTime::DateTime(const TimeStamp &ts) { - init(ts); + add_raw(ts.raw()); } -DateTime::DateTime(const TimeStamp &ts, const TimeZone &tz) +DateTime::DateTime(const TimeStamp &ts, const TimeZone &tz): + DateTime(ts) { - init(ts); convert_timezone(tz); } -DateTime::DateTime(int y, unsigned char m, unsigned char d) -{ - init(y, m, d, 0, 0, 0, 0); -} - -DateTime::DateTime(int y, unsigned char m, unsigned char d, unsigned char h, unsigned char n, unsigned char s) +DateTime::DateTime(int y, unsigned char m, unsigned char d): + DateTime(y, m, d, 0, 0, 0, 0) +{ } + +DateTime::DateTime(int y, unsigned char m, unsigned char d, unsigned char h, unsigned char n, unsigned char s): + DateTime(y, m, d, h, n, s, 0) +{ } + +DateTime::DateTime(int y, unsigned char m, unsigned char d, unsigned char h, unsigned char n, unsigned char s, unsigned u): + year(y), + month(m), + mday(d), + hour(h), + minute(n), + second(s), + usec(u) { - init(y, m, d, h, n, s, 0); -} - -DateTime::DateTime(int y, unsigned char m, unsigned char d, unsigned char h, unsigned char n, unsigned char s, unsigned u) -{ - init(y, m, d, h, n, s, u); -} - -void DateTime::init(const TimeStamp &ts) -{ - year = 1970; - month = 1; - mday = 1; - hour = 0; - minute = 0; - second = 0; - usec = 0; - add_raw(ts.raw()); -} - -void DateTime::init(int y, unsigned char m, unsigned char d, unsigned char h, unsigned char n, unsigned char s, unsigned u) -{ - year = y; - month = m; - mday = d; - hour = h; - minute = n; - second = s; - usec = u; - if(usec>=1000000) throw out_of_range("DateTime::DateTime usec"); if(second>=60) @@ -288,7 +268,7 @@ TimeStamp DateTime::get_timestamp() const string DateTime::format(const string &fmt) const { string result; - for(string::const_iterator i=fmt.begin(); i!=fmt.end(); ++i) + for(auto i=fmt.begin(); i!=fmt.end(); ++i) { if(*i=='%') {