Exemplo n.º 1
1
    Glib::Date MALItem::get_date(const std::string& in) const {
        Glib::Date        out;
        Glib::Date::Day   day   = 0;
        Glib::Date::Month month = Glib::Date::BAD_MONTH;
        Glib::Date::Year  year  = 0;

        try {
            year = std::stoi(in.substr(0,4));
            day = std::stoi(in.substr(8,2));
            switch (std::stoi(in.substr(5,2))) {
                case 1:  month = Glib::Date::JANUARY;   break;
                case 2:  month = Glib::Date::FEBRUARY;  break;
                case 3:  month = Glib::Date::MARCH;     break;
                case 4:  month = Glib::Date::APRIL;     break;
                case 5:  month = Glib::Date::MAY;       break;
                case 6:  month = Glib::Date::JUNE;      break;
                case 7:  month = Glib::Date::JULY;      break;
                case 8:  month = Glib::Date::AUGUST;    break;
                case 9:  month = Glib::Date::SEPTEMBER; break;
                case 10: month = Glib::Date::OCTOBER;   break;
                case 11: month = Glib::Date::NOVEMBER;  break;
                case 12: month = Glib::Date::DECEMBER;  break;
                default: month = Glib::Date::BAD_MONTH; break;
            }
        } catch (std::exception e) {
        }

        if (Glib::Date::valid_year(year))
            out.set_year(year);
        if (Glib::Date::valid_month(month))
            out.set_month(month);
        if (Glib::Date::valid_day(day))
            out.set_day(day);

        return out;
    }
Exemplo n.º 2
0
void
Item::ensure_integrity()
{
	if (_ensured) 
		return;
	static const Glib::ustring _empty("Empty title");
	if (_link.empty() && !_guid.empty())
		_link = _guid;
	if (_title.empty())
		_title = _empty;
	const Glib::ustring s = _description;
	remove_markup (s, _description);

    bool rd_is_valid = false;
    if (!_rcvdate.empty())
    {
        Glib::Date my;
        int y, m, d;
        sscanf (_rcvdate.c_str(), "%d-%d-%d", &y, &m, &d);
        my.set_day (d);
        my.set_year (y);
        my.set_month (Glib::Date::JANUARY);
        my.add_months (m-1);
        rd_is_valid = my.valid();
    }
    if (!rd_is_valid)
    {
        g_warning ("Invalid date: %s ... fixing", _rcvdate.c_str());
        Glib::Date now;
        now.set_time_current();
        _rcvdate = now.format_string ("%Y-%m-%d");
    }
	_ensured = true;
}