本文整理汇总了C++中Duration::setMonths方法的典型用法代码示例。如果您正苦于以下问题:C++ Duration::setMonths方法的具体用法?C++ Duration::setMonths怎么用?C++ Duration::setMonths使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Duration
的用法示例。
在下文中一共展示了Duration::setMonths方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Duration
Duration *TypeConverter::stringToDuration(const QString &duration)
{
if (duration.isEmpty()) {
m_errorMsg = "stringToDuration received an empty string";
return new Duration();
}
m_errorMsg = "-no errors-";
//Schema duration format: PnYnMnDTnHnMnS
Duration *d = new Duration();
int i = 0;
if (duration[i] == '-') {
d->setPositive(false);
i++;
}
if (duration[i] != 'P') {
m_errorMsg = "Invalid duration string: " + duration;
delete d;
return new Duration();
}
i++;
bool codeTAppeared = false;
while (i < duration.length()) {
QString buf;
for (; i < duration.length() && duration[i].isDigit(); i++) {
buf += duration[i];
}
if (i < duration.length()) {
if (codeTAppeared == false) {
// Before T (PnYnMnD T nHnMnS)
switch (duration[i].toAscii()) {
case 'Y':
d->setYears(buf.toInt());
break;
case 'M':
d->setMonths(buf.toInt());
break;
case 'D':
d->setDays(buf.toInt());
break;
case 'T':
codeTAppeared = true;
break;
default:
m_errorMsg = "Invalid duration string: " + duration;
delete d;
return new Duration();
}
} else {
// After T (PnYnMnD T nHnMnS)
switch (duration[i].toAscii()) {
case 'H':
d->setHours(buf.toInt());
break;
case 'M':
d->setMinutes(buf.toInt());
break;
case '.':
// Decimal point may be present in Seconds value
d->setSeconds(buf.toInt());
buf="";
for (i++; duration[i].isDigit() && i < duration.length(); i++) {
buf += duration[i];
}
if(duration[i] != 'S' || i >= duration.length()) {
m_errorMsg = "Error in duration, S not found after decimal point";
delete d;
return new Duration();
}
d->setMseconds(buf.toInt());
break;
case 'S':
d->setSeconds(buf.toInt());
break;
default:
m_errorMsg = "Invalid duration string: " + duration;
delete d;
return new Duration();
}
}
//.........这里部分代码省略.........