707 :
708 m_greg(boost::gregorian::day_clock::local_day())
709{
711 [&fmt](
const GncDateFormat& v){
return (v.m_fmt == fmt); } );
713 throw std::invalid_argument(N_("Unknown date format specifier passed as argument."));
714
715 if (iter->m_str_to_date)
716 {
717 try
718 {
719 m_greg = (*iter->m_str_to_date)(str);
720 return;
721 }
722 catch (...) {}
723 }
724
725 if (iter->m_re.empty())
726 throw std::invalid_argument ("No regex pattern available");
727
728 boost::smatch what;
729 if(!boost::regex_search(str, what, iter->m_re))
730 throw std::invalid_argument (N_("Value can't be parsed into a date using the selected date format."));
731
732
733 auto fmt_has_year = (fmt.find('y') != std::string::npos);
734 if (!fmt_has_year && (what.length("YEAR") != 0))
735 throw std::invalid_argument (N_("Value appears to contain a year while the selected format forbids this."));
736
737 int year;
738 if (fmt_has_year)
739 {
740
741 year = std::stoi (what.str("YEAR"));
742
743
744 if (year < 69)
745 year += 2000;
746 else if (year < 100)
747 year += 1900;
748 }
749 else
750 year = m_greg.year();
751
752 m_greg = Date(year,
753 static_cast<Month>(std::stoi (what.str("MONTH"))),
754 std::stoi (what.str("DAY")));
755}
static const std::vector< GncDateFormat > c_formats
A vector with all the date formats supported by the string constructor.