432 :
433 m_time(unix_epoch, utc_zone)
434{
435 if (!str || !str[0]) return;
436 TZ_Ptr tzptr;
437 try
438 {
439 if (auto res = fast_iso8601_utc_parse (str))
440 {
441 m_time = LDT_from_date_time(res->date(), res->time_of_day(), utc_zone);
442 return;
443 }
444 static const boost::regex delim_iso("^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(?:\\.\\d{0,9})?)\\s*([+-]\\d{2}(?::?\\d{2})?)?$");
445 static const boost::regex non_delim("^(\\d{14}(?:\\.\\d{0,9})?)\\s*([+-]\\d{2}\\s*(:?\\d{2})?)?$");
446 PTime pdt;
447 boost::cmatch sm;
448 if (regex_match(str, sm, non_delim))
449 {
450 std::string time_str(sm[1]);
451 time_str.insert(8, "T");
452 pdt = boost::posix_time::from_iso_string(time_str);
453 }
454 else if (regex_match(str, sm, delim_iso))
455 {
456 pdt = boost::posix_time::time_from_string(sm[1]);
457 }
458 else
459 {
460 throw(std::invalid_argument("The date string was not formatted in a way that GncDateTime(const char*) knows how to parse."));
461 }
462 std::string tzstr("");
463 if (sm[2].matched)
464 tzstr += sm[2];
465 tzptr = tz_from_string(tzstr);
466 m_time = LDT_from_date_time(pdt.date(), pdt.time_of_day(), tzptr);
467 }
468 catch(boost::gregorian::bad_year&)
469 {
470 throw(std::invalid_argument("The date string was outside of the supported year range."));
471 }
472 catch(std::out_of_range&)
473 {
474 throw(std::invalid_argument("The date string was outside of the supported year range."));
475 }
476
477
478
479
480
481
482 auto offset = tzptr->base_utc_offset().seconds();
483 if (offset != 0 && std::abs(offset) < 3600)
484 m_time = m_time.local_time_in(utc_zone);
485}