Ejemplo n.º 1
0
Time & Time::nextPeriod(Time::PeriodType type, int times)
{
	switch (type)
	{
	case kPeriodMinute:
		addSecond(Time::MINUTE_SECONDS * times);
		break;
	case kPeriodHour:
		addSecond(Time::HOUR_SECONDS * times);
		break;
	case kPeriodDay:
		addSecond(Time::DAY_SECONDS * times);
		break;
	case kPeriodWeek:
		addSecond(Time::WEEK_SECONDS * times);
		break;
	case kPeriodMonth:
		set(toDate().addMonth(times).stamp());
		break;
	case kPeriodYear:
		set(toDate().addYear(times).stamp());
		break;
	default:
		break;
	}

	return *this;
}
Ejemplo n.º 2
0
void MyMoneyReport::validDateRange ( QDate& _db, QDate& _de )
{
  _db = fromDate();
  _de = toDate();

  // if either begin or end date are invalid we have one of the following
  // possible date filters:
  //
  // a) begin date not set - first transaction until given end date
  // b) end date not set   - from given date until last transaction
  // c) both not set       - first transaction until last transaction
  //
  // If there is no transaction in the engine at all, we use the current
  // year as the filter criteria.

  if ( !_db.isValid() || !_de.isValid() ) {
    QValueList<MyMoneyTransaction> list = MyMoneyFile::instance()->transactionList ( *this );
    QDate tmpBegin, tmpEnd;

    if ( !list.isEmpty() ) {
      qHeapSort ( list );
      tmpBegin = list.front().postDate();
      tmpEnd = list.back().postDate();
    } else {
      tmpBegin = QDate ( QDate::currentDate().year(), 1, 1 ); // the first date in the file
      tmpEnd = QDate ( QDate::currentDate().year(), 12, 31 );// the last date in the file
    }
    if ( !_db.isValid() )
      _db = tmpBegin;
    if ( !_de.isValid() )
      _de = tmpEnd;
  }
  if ( _db > _de )
    _db = _de;
}
Ejemplo n.º 3
0
bool SoftUpdatePrefsXMLSerializer::unserialize( TiXmlNode* node )
{
	bool result = true;

	if (node) 
	{
		_prefs.setVersionToIgnore ( 	    fromNode( node, "versionToIgnore"   ) );
		_prefs.setDateLastIgnored(	toDate( fromNode( node, "dateLastIgnored" ) ) );
		_prefs.setAutoCheck       ( toBool( fromNode( node, "autoCheck"		  ) ) );
	}

	return result;
}
QByteArray OpCancelBookingRequ::marshall()
{

    QByteArray serialized_data;
    QDataStream stream(&serialized_data, QIODevice::WriteOnly);
    stream << localRequestId();
    stream << leaveYear();
    stream << fromDate();
    stream << toDate();
    stream << firstDayHalf();
    stream << lastDayHalf();
    stream << dayHalf();
    stream << note();
    return serialized_data;
}
Ejemplo n.º 5
0
static void writeCsvRow(SOCKET fd, struct Data* row){
	char date[11];
	toDate(date, row->ts - row->dr);

 // This is the time marking the start of the interval
	char timeFrom[9];
	toTime(timeFrom, row->ts - row->dr);

 // This is the time marking the end of the interval
	char timeTo[9];
	toTime(timeTo, row->ts);

	char rowTxt[256];
	sprintf(rowTxt, "%s,%s,%s,%llu,%llu,%s,%s\n", date, timeFrom, timeTo, row->dl, row->ul, (row->hs == NULL) ? "" : row->hs, row->ad);	
	writeText(fd, rowTxt);
	
	freeData(row);
}
Ejemplo n.º 6
0
	Transaction Transaction::from_line(const std::vector<std::string>& line)
	{
		if(line.size() != 11)
			throw std::runtime_error("Transaction csv is not valid");

		Transaction result;
		result.id = boost::lexical_cast<Id>(line[0]);
		result.chain = boost::lexical_cast<Id>(line[1]);
		result.dept = boost::lexical_cast<Id>(line[2]);
		result.category = boost::lexical_cast<Id>(line[3]);
		result.company = boost::lexical_cast<Id>(line[4]);
		result.brand = boost::lexical_cast<Id>(line[5]);
		result.date = toDate(line[6]);
		result.productsize = boost::lexical_cast<float>(line[7]);
		result.productmeasure = toProductmeasure(line[8]);
		result.purchasequantity = boost::lexical_cast<uint64_t>(line[9]);
		result.purchaseamount = boost::lexical_cast<float>(line[10]);
		return result;
	}
Ejemplo n.º 7
0
// here we use DataTime instead of QT's built-in time conversion
// since the latter does not properly handle fractions of seconds
// in the ISO8601 specification.
QString Soprano::LiteralValue::toString() const
{
    if ( d ) {
        if ( !d->stringCacheValid ) {
            if( isInt() )
                d->stringCache = QString::number( toInt() );
            else if( isInt64() )
                d->stringCache = QString::number( toInt64() );
            else if( isUnsignedInt() )
                d->stringCache = QString::number( toUnsignedInt() );
            else if( isUnsignedInt64() )
                d->stringCache = QString::number( toUnsignedInt64() );
            else if( isBool() )
                d->stringCache = ( toBool() ? QString("true") : QString("false" ) );
            else if( isDouble() ) // FIXME: decide on a proper double encoding or check if there is one in xml schema
                d->stringCache = QString::number( toDouble(), 'e', 10 );
            else if( isDate() )
                d->stringCache = DateTime::toString( toDate() );
            else if( isTime() )
                d->stringCache = DateTime::toString( toTime() );
            else if( isDateTime() )
                d->stringCache = DateTime::toString( toDateTime() );
            else if ( isByteArray() )
                d->stringCache = QString::fromAscii( toByteArray().toBase64() );
            else
                d->stringCache = d->value.toString();

            d->stringCacheValid = true;
        }

        return d->stringCache;
    }
    else {
        return QString();
    }
}
Ejemplo n.º 8
0
QString PostFilter::match(const QMap<QString, Token> &tokens, QString filter, bool invert)
{
	// Invert the filter by prepending '-'
	if (filter.startsWith('-'))
	{
		filter = filter.right(filter.length() - 1);
		invert = !invert;
	}

	// Tokens
	if (filter.startsWith('%') && filter.endsWith('%'))
	{
		QString key = filter.mid(1, filter.length() - 2);
		bool cond = tokens.contains(key) && !isVariantEmpty(tokens[key].value());

		if (cond && invert)
		{ return QObject::tr("image has a \"%1\" token").arg(key); }
		else if (!cond && !invert)
		{ return QObject::tr("image does not have a \"%1\" token").arg(key); }
	}

	// Meta-tags
	else if (filter.contains(":"))
	{
		QString type = filter.section(':', 0, 0).toLower();
		filter = filter.section(':', 1).toLower();
		if (!tokens.contains(type))
		{
			QStringList keys = tokens.keys();
			return QObject::tr("unknown type \"%1\" (available types: \"%2\")").arg(type, keys.join("\", \""));
		}

		QVariant token = tokens[type].value();
		if (token.type() == QVariant::Int || token.type() == QVariant::DateTime || token.type() == QVariant::ULongLong)
		{
			int input = 0;
			if (token.type() == QVariant::Int)
			{ input = token.toInt(); }
			else if (token.type() == QVariant::DateTime)
			{ input = token.toDateTime().toString("yyyyMMdd").toInt(); }
			else if (token.type() == QVariant::ULongLong)
			{ input = token.toULongLong(); }

			bool cond;
			if (token.type() == QVariant::DateTime)
			{
				if (filter.startsWith("..") || filter.startsWith("<="))
				{ cond = input <= toDate(filter.right(filter.size()-2)); }
				else if (filter.endsWith(".."))
				{ cond = input >= toDate(filter.left(filter.size()-2)); }
				else if (filter.startsWith(">="))
				{ cond = input >= toDate(filter.right(filter.size()-2)); }
				else if (filter.startsWith("<"))
				{ cond = input < toDate(filter.right(filter.size()-1)); }
				else if (filter.startsWith(">"))
				{ cond = input > toDate(filter.right(filter.size()-1)); }
				else if (filter.contains(".."))
				{ cond = input >= toDate(filter.left(filter.indexOf(".."))) && input <= toDate(filter.right(filter.size()-filter.indexOf("..")-2));	}
				else
				{ cond = input == toDate(filter); }
			}
			else
			{
				if (filter.startsWith("..") || filter.startsWith("<="))
				{ cond = input <= filter.rightRef(filter.size()-2).toInt(); }
				else if (filter.endsWith(".."))
				{ cond = input >= filter.leftRef(filter.size()-2).toInt(); }
				else if (filter.startsWith(">="))
				{ cond = input >= filter.rightRef(filter.size()-2).toInt(); }
				else if (filter.startsWith("<"))
				{ cond = input < filter.rightRef(filter.size()-1).toInt(); }
				else if (filter.startsWith(">"))
				{ cond = input > filter.rightRef(filter.size()-1).toInt(); }
				else if (filter.contains(".."))
				{ cond = input >= filter.leftRef(filter.indexOf("..")).toInt() && input <= filter.rightRef(filter.size()-filter.indexOf("..")-2).toInt();	}
				else
				{ cond = input == filter.toInt(); }
			}

			if (!cond && !invert)
			{ return QObject::tr("image's %1 does not match").arg(type); }
			if (cond && invert)
			{ return QObject::tr("image's %1 match").arg(type); }
		}
		else
		{
			if (type == "rating")
			{
				QMap<QString, QString> assoc;
				assoc["s"] = "safe";
				assoc["q"] = "questionable";
				assoc["e"] = "explicit";

				if (assoc.contains(filter))
					filter = assoc[filter];

				bool cond = !filter.isEmpty() && token.toString().toLower().startsWith(filter.at(0));
				if (!cond && !invert)
				{ return QObject::tr("image is not \"%1\"").arg(filter); }
				if (cond && invert)
				{ return QObject::tr("image is \"%1\"").arg(filter); }
			}
			else if (type == "source")
			{
				QRegExp rx(filter + "*", Qt::CaseInsensitive, QRegExp::Wildcard);
				bool cond = rx.exactMatch(token.toString());
				if (!cond && !invert)
				{ return QObject::tr("image's source does not starts with \"%1\"").arg(filter); }
				if (cond && invert)
				{ return QObject::tr("image's source starts with \"%1\"").arg(filter); }
			}
			else
			{
				QString input = token.toString();

				bool cond = input == filter;

				if (!cond && !invert)
				{ return QObject::tr("image's %1 does not match").arg(type); }
				if (cond && invert)
				{ return QObject::tr("image's %1 match").arg(type); }
			}
		}
	}
	else if (!filter.isEmpty())
	{
		QStringList tags = tokens["allos"].value().toStringList();

		// Check if any tag match the filter (case insensitive plain text with wildcards allowed)
		bool cond = false;
		for (const QString &tag : tags)
		{
			QRegExp reg(filter.trimmed(), Qt::CaseInsensitive, QRegExp::Wildcard);
			if (reg.exactMatch(tag))
			{
				cond = true;
				break;
			}
		}

		if (!cond && !invert)
		{ return QObject::tr("image does not contains \"%1\"").arg(filter); }
		if (cond && invert)
		{ return QObject::tr("image contains \"%1\"").arg(filter); }
	}

	return QString();
}
Ejemplo n.º 9
0
	Strings::FastString Time::toDate(const bool iso8601) const
	{
		char buffer[30];
		toDate(buffer, iso8601);
		return Strings::FastString(buffer);
	}