X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fdatetime.cpp;h=404cb31bf56b1d8ef6ccf5df74fc599520474e03;hb=9b22dd53fe62e312c1647310b7ec43aa127090af;hp=9e1a7f8eb3eb12d06acb283637e72eaf5c14c498;hpb=1b0c3b7f86935a772aad271bad4f3d1f37243c2d;p=fms.git diff --git a/src/datetime.cpp b/src/datetime.cpp index 9e1a7f8..404cb31 100644 --- a/src/datetime.cpp +++ b/src/datetime.cpp @@ -14,7 +14,7 @@ DateTime::DateTime() DateTime::DateTime(const time_t &timet) { - Set(timet); + SetT(timet); } DateTime::DateTime(const struct tm *stm) @@ -187,6 +187,11 @@ const bool DateTime::operator==(const struct tm &rhs) const return (m_tm.tm_year==rhs.tm_year && m_tm.tm_mon==rhs.tm_mon && m_tm.tm_mday==rhs.tm_mday && m_tm.tm_hour==rhs.tm_hour && m_tm.tm_min==rhs.tm_min && m_tm.tm_sec==rhs.tm_sec) ? true : false; } +const bool DateTime::operator<(const struct tm &rhs) const +{ + return (m_tm.tm_year tokens; - int vecpos; + std::vector::size_type vecpos; int tempint; year=month=day=hour=minute=second=-1; @@ -410,3 +415,27 @@ void DateTime::SetToLocalTime() m_tm=*localtime(&m_timet); Normalize(); } + +const time_t DateTime::TimeGM(struct tm *gmtimein) +{ + //This looks good but I don't think will work when TZ isn't set (Windows) + //http://developer.apple.com/documentation/Darwin/Reference/ManPages/man3/timegm.3.html + + //This should work + //http://lists2.ais.fraunhofer.de/pipermail/emx/1999-September/000874.html + + struct tm ttm; + time_t t, t2; + + ttm = *gmtimein; /* make a local copy to fiddle with */ + ttm.tm_isdst = 0; /* treat it as standard time */ + + t2 = t = mktime(&ttm); /* calculate the time as a local time */ + + ttm = *gmtime(&t2); /* now calculate the difference between */ + ttm.tm_isdst = 0; /* gm and local time */ + t2 = mktime(&ttm); + + t += t - t2; /* and adjust our answer by that difference */ + return t; +}