WSL/SLF GitLab Repository

Commit 03c9a527 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Added more options to the parsing of dates (like NOW or NOW+3600) as well as some documentation

parent 183d33c1
......@@ -426,6 +426,23 @@ bool convertString(Date& t, const std::string& str, const double& time_zone, std
std::string s(str);
trim(s); //delete trailing and leading whitespaces and tabs
//special case: NOW or NOW±xxx (offset in seconds)
if (s.substr(0, 3)=="NOW") {
t.setFromSys();
t.setTimeZone(time_zone);
if (s.size()>3) {
const size_t beg = s.find_first_of(NUM);
if (beg==npos)
throw InvalidFormatException("Invalid date specification '"+s+"'", AT);
size_t end = s.find_first_not_of(NUM, beg+1);
if (end!=npos)
throw InvalidFormatException("Invalid date specification '"+s+"'", AT);
const int offset = atoi( s.substr(beg-1, std::string::npos).c_str());
t += static_cast<double>(offset)/(3600.*24.);
}
return true;
}
(void)f;
int year;
unsigned int month, day, hour, minute;
......@@ -481,7 +498,7 @@ bool convertString(Date& t, const std::string& str, const double& time_zone, std
t.setDate( (static_cast<double>(hour))/24. + (static_cast<double>(minute))/24./60. , tz);
return true;
} else {
} else { //purely numeric date: YYYYMMDDHHmmss where ss and mm can be skipped
const size_t wrong_dash1 = s.find("–");
const size_t wrong_dash2 = s.find("Ð");
if (wrong_dash1!=std::string::npos || wrong_dash2!=std::string::npos)
......
......@@ -43,12 +43,34 @@ namespace mio {
*
* Please see Date::FORMATS for supported display formats and http://en.wikipedia.org/wiki/Julian_day for
* the various date representation definitions. The following data representation are currently supported:
* - julian date, see Date::getJulianDate
* - julian date, see Date::getJulian
* - modified julian date, see Date::getModifiedJulianDate
* - truncated julian date, see Date::getTruncatedJulianDate
* - Unix date, see Date::getUnixDate
* - Excel date, see Date::getExcelDate
*
* When parsing a string to extract a date, various string representations are supported (the timezone term {TZ} is optional \em if a
* fallback timezone is available, most probably as Input::TIME_ZONE in the configuration file):
* - <A HREF="https://en.wikipedia.org/wiki/ISO_8601">ISO 8601</A> variations:
* - YYYY-MM-DDThh:mm:ss{TZ}
* - YYYY-MM-DDThh:mm{TZ}
* - similar to ISO but without the 'T' marker (some systems wrongfuly reject it):
* - YYYY-MM-DD hh:mm:ss{TZ}
* - YYYY-MM-DD hh:mm{TZ}
* - simplified:
* - YYYY-MM-DD{TZ}
* - hh:mm{TZ}
* - numeric:
* - YYYYMMDDHHmmss{TZ}
* - YYYYMMDDHHmm{TZ}
* - YYYYMMDDHH{TZ}
* - relative, with keyword (in this case a fallback time zone must be available from somewhere else):
* - NOW
* - NOW+{offset} (the offset is in seconds)
* - NOW-{offset} (the offset is in seconds)
*
* The timezone information {TZ} is as laid out in Date::parseTimeZone.
*
* @ingroup data_str
* @author Mathias Bavay
* @date 2010-04-15
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment