src/Generic/common/TimexUtils.cpp
/** 
 * Parse dates from the ACE regression test data and 
 * non-delmited or extended ISO strings.
 **/
Parse dates from the ACE regression test data and
non-delmited or extended ISO strings.
Parse dates from the ACE regression test data and non - delmited or extended ISO strings .
void TimexUtils::parseDateTime(std::wstring timeString,
							   boost::optional<boost::gregorian::date> &date, 
					           boost::optional<boost::posix_time::time_duration> &timeOfDay, 
                               boost::optional<boost::local_time::posix_time_zone> &timeZone) 
{
	boost::algorithm::trim(timeString);
	boost::wsmatch matchObj;
	if (boost::regex_search(timeString, matchObj, _timex_regex_time_zone)) {
		std::wstring timeZoneString = matchObj[1];
		timeZone = boost::local_time::posix_time_zone(UnicodeUtil::toUTF8StdString(timeZoneString));
		timeString = boost::regex_replace(timeString, _timex_regex_time_zone, L"");
	}
	std::string ts = UnicodeUtil::toUTF8StdString(timeString);
	boost::optional<boost::posix_time::ptime> ptime;
	ptime = ptimeFromString(ts, "%Y%m%d");
	if (ptime && ts.size() == 8) { 
		date = ptime->date();
		return;
	}
	ptime = ptimeFromString(ts, "%Y-%m-%d");
	if (ptime && ts.size() == 10) { 
		date = ptime->date();
		return;
	}
	ptime = ptimeFromString(ts, "%Y-%m-%dT%H:%M:%S");
	if (ptime) {
		date = ptime->date();
		timeOfDay = ptime->time_of_day();
		return;
	}
	ptime = ptimeFromString(ts, "%Y-%m-%d %H:%M:%S");
	if (ptime) {
		date = ptime->date();
		timeOfDay = ptime->time_of_day();
		return;
	}
	ptime = ptimeFromString(ts, "%Y%m%d-%H:%M:%S");
	if (ptime) {
		date = ptime->date();
		timeOfDay = ptime->time_of_day();
		return;
	}
	ptime = ptimeFromString(ts, "%Y%m%dT%H%M%S");
	if (ptime) {
		date = ptime->date();
		timeOfDay = ptime->time_of_day();
		return;
	}
	return;
}
void TimexUtils :: parseDateTime ( std :: wstring timeString , boost :: optional < boost :: gregorian :: date > & date , boost :: optional < boost :: posix_time :: time_duration > & timeOfDay , boost :: optional < boost :: local_time :: posix_time_zone > & timeZone ) { boost :: algorithm :: trim ( timeString ) ; boost :: wsmatch matchObj ; if ( boost :: regex_search ( timeString , matchObj , _timex_regex_time_zone ) ) { std :: wstring timeZoneString = matchObj [ 1 ] ; timeZone = boost :: local_time :: posix_time_zone ( UnicodeUtil :: toUTF8StdString ( timeZoneString ) ) ; timeString = boost :: regex_replace ( timeString , _timex_regex_time_zone , L" " ) ; } std :: string ts = UnicodeUtil :: toUTF8StdString ( timeString ) ; boost :: optional < boost :: posix_time :: ptime > ptime ; ptime = ptimeFromString ( ts , " " ) ; if ( ptime && ts . size ( ) == 8 ) { date = ptime -> date ( ) ; return ; } ptime = ptimeFromString ( ts , " " ) ; if ( ptime && ts . size ( ) == 10 ) { date = ptime -> date ( ) ; return ; } ptime = ptimeFromString ( ts , " " ) ; if ( ptime ) { date = ptime -> date ( ) ; timeOfDay = ptime -> time_of_day ( ) ; return ; } ptime = ptimeFromString ( ts , " " ) ; if ( ptime ) { date = ptime -> date ( ) ; timeOfDay = ptime -> time_of_day ( ) ; return ; } ptime = ptimeFromString ( ts , " " ) ; if ( ptime ) { date = ptime -> date ( ) ; timeOfDay = ptime -> time_of_day ( ) ; return ; } ptime = ptimeFromString ( ts , " " ) ; if ( ptime ) { date = ptime -> date ( ) ; timeOfDay = ptime -> time_of_day ( ) ; return ; } return ; }
Parse dates from the ACE regression test data and
 non-delmited or extended ISO strings.
Parse dates from the ACE regression test data and non - delmited or extended ISO strings .
// Strip off time zone indicator if it exists
 /* The simple formats go first because we want to catch the 
	   case where we don't have a time of day. If we tried a format 
	   with H, M, S in it, that could also match the 8 digit case, 
	   and we wouldn't know that we couldn't find a time. 
	*/ // Just date 20050123
 // Just date 2005-01-23
 // Full date and time: 2005-01-23T16:39:00
 // Full date and time: 2005-01-23 16:39:00
 // Full date and time: 20050123-16:39:00
 // Non-delimited ISO string: 20050123T163900
