int v_adv_med(struct command *c) { wout(c->who, "Meditate for %s.", weeks(c->wait)); return TRUE; }
quint32 CalendarCourse::weeksCount() const { const quint32 res = weeks().count(); if (res != calendar()->weeksCount()) qDebug() << Q_FUNC_INFO << "error" << res << "!=" << calendar()->weeksCount(); return res; }
int v_adv_med(struct command *c) { if (subkind(subloc(c->who)) != sub_tower || !alone_here(c->who)) { wout(c->who, "You must be alone in a tower to use Advanced Meditation."); return FALSE; }; wout(c->who, "Advanced meditation for %s.", weeks(c->wait)); return TRUE; }
double DateTime::duration(const double& time, double duration, DateTimeUnitOptions unit) { switch (unit) { case DATE_TIME_UNIT_NONE: case DATE_TIME_UNIT_DAY: return days(duration); case DATE_TIME_UNIT_WEEK: return weeks(duration); case DATE_TIME_UNIT_MONTH: return months(time, duration); case DATE_TIME_UNIT_YEAR: return years(time, duration); } return 0; }
int v_meditate(struct command *c) { if (!char_alone(c->who)) { wout(c->who, "You cannot meditate unless completely alone."); return FALSE; }; if (char_cur_aura(c->who) >= max_eff_aura(c->who)) { wout(c->who, "Current aura is already %d. It may not " "be increased further via meditation.", char_cur_aura(c->who)); return FALSE; } wout(c->who, "Meditate for %s.", weeks(c->wait)); return TRUE; }
int confOption::setValueFromFile(QString line) { // Used to set values in confOptions from a file line QString rval = line.section("=",1).trimmed(); qDebug() << "setting " << realName << " to " << rval << " (from file)"; if (type == BOOL) { if (rval == "true" || rval == "on" || rval == "yes") { value = true; return 0; } else if (rval == "false" || rval == "off" || rval == "no") { value = false; return 0; } qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; return -1; } else if (type == INTEGER) { bool ok; qlonglong rvalToNmbr = rval.toLongLong(&ok); if (ok && rvalToNmbr >= minVal && rvalToNmbr <= maxVal) { value = rvalToNmbr; return 0; } qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; return -1; } else if (type == STRING) { value = rval; return 0; } else if (type == LIST) { if (realName == "ShowStatus") // ShowStatus needs special treatment { if (rval.toLower() == "true" || rval.toLower() == "on") rval = "yes"; else if (rval.toLower() == "false" || rval.toLower() == "off") rval = "no"; } if (possibleVals.contains(rval)) { value = rval.toLower(); return 0; } qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; value = defVal; return -1; } else if (type == MULTILIST) { QVariantMap map; QStringList readList = rval.split(" ", QString::SkipEmptyParts); for (int i = 0; i < readList.size(); ++i) { if (!possibleVals.contains(readList.at(i))) { qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; return -1; } } for (int i = 0; i < possibleVals.size(); ++i) { if (readList.contains(possibleVals.at(i))) map[possibleVals.at(i)] = true; else map[possibleVals.at(i)] = false; } value = map; return 0; } else if (type == TIME) { int pos = 0; QRegExp rxValid; // These regex check whether rval is a valid time interval if (hasNsec) rxValid = QRegExp("^(?:\\d*\\.?\\d *(ns|nsec|us|usec|ms|msec|s|sec|second|seconds|m|min|minute|minutes|h|hr|hour|hours|d|day|days|w|week|weeks|month|months|y|year|years)? *)+$"); else rxValid = QRegExp("^(?:\\d*\\.?\\d *(us|usec|ms|msec|s|sec|second|seconds|m|min|minute|minutes|h|hr|hour|hours|d|day|days|w|week|weeks|month|months|y|year|years)? *)+$"); pos = rxValid.indexIn(rval); if (pos > -1) { pos = 0; seconds secs(0); // This regex parses individual elements of the time interval QRegExp rxTimeParse = QRegExp("(\\d*\\.?\\d+) *([a-z]*)"); while ((pos = rxTimeParse.indexIn(rval, pos)) != -1) { if (rxTimeParse.cap(2) == "ns" || rxTimeParse.cap(2) == "nsec" ) { nanoseconds ns(rxTimeParse.cap(1).trimmed().toDouble()); secs += ns; } else if (rxTimeParse.cap(2) == "us" || rxTimeParse.cap(2) == "usec" ) { microseconds us(rxTimeParse.cap(1).trimmed().toDouble()); secs += us; } else if (rxTimeParse.cap(2) == "ms" || rxTimeParse.cap(2) == "msec" ) { milliseconds ms(rxTimeParse.cap(1).trimmed().toDouble()); secs += ms; } else if (rxTimeParse.cap(2) == "s" || rxTimeParse.cap(2) == "sec" || rxTimeParse.cap(2) == "second" || rxTimeParse.cap(2) == "seconds" ) { seconds s(rxTimeParse.cap(1).trimmed().toDouble()); secs += s; } else if (rxTimeParse.cap(2) == "m" || rxTimeParse.cap(2) == "min" || rxTimeParse.cap(2) == "minute" || rxTimeParse.cap(2) == "minutes" ) { minutes min(rxTimeParse.cap(1).trimmed().toDouble()); secs += min; } else if (rxTimeParse.cap(2) == "h" || rxTimeParse.cap(2) == "hr" || rxTimeParse.cap(2) == "hour" || rxTimeParse.cap(2) == "hours" ) { hours hr(rxTimeParse.cap(1).trimmed().toDouble()); secs += hr; } else if (rxTimeParse.cap(2) == "d" || rxTimeParse.cap(2) == "day" || rxTimeParse.cap(2) == "days") { days dy(rxTimeParse.cap(1).trimmed().toDouble()); secs += dy; } else if (rxTimeParse.cap(2) == "w" || rxTimeParse.cap(2) == "week" || rxTimeParse.cap(2) == "weeks") { weeks w(rxTimeParse.cap(1).trimmed().toDouble()); secs += w; } else if (rxTimeParse.cap(2) == "month" || rxTimeParse.cap(2) == "months") { months m(rxTimeParse.cap(1).trimmed().toDouble()); secs += m; } else if (rxTimeParse.cap(2) == "y" || rxTimeParse.cap(2) == "year" || rxTimeParse.cap(2) == "years") { years y(rxTimeParse.cap(1).trimmed().toDouble()); secs += y; } else if (rxTimeParse.cap(2).isEmpty()) { // unitless number, convert it from defReadUnit to seconds seconds tmpSeconds(convertTimeUnit(rxTimeParse.cap(1).trimmed().toDouble(), defReadUnit, timeUnit::s).toDouble()); secs += tmpSeconds; } pos += rxTimeParse.matchedLength(); } // Convert the read value in seconds to defUnit if (defUnit == ns) value = nanoseconds(secs).count(); else if (defUnit == us) value = microseconds(secs).count(); else if (defUnit == ms) value = milliseconds(secs).count(); else if (defUnit == s) value = secs.count(); else if (defUnit == min) value = minutes(secs).count(); else if (defUnit == h) value = hours(secs).count(); else if (defUnit == d) value = days(secs).count(); else if (defUnit == w) value = weeks(secs).count(); else if (defUnit == month) value = months(secs).count(); else if (defUnit == year) value = years(secs).count(); value = value.toULongLong(); // Convert to ulonglong (we don't support float in ui) return 0; } else { qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; return -1; } } else if (type == RESLIMIT) { bool ok; int nmbr = rval.toUInt(&ok); if (ok) { value = nmbr; return 0; } else if (rval.toLower().trimmed() == "infinity" || rval.trimmed().isEmpty()) { value = -1; return 0; } qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; return -1; } else if (type == SIZE) { // RegExp to match a number (possibly with decimals) followed by a size unit (or no unit for byte) QRegExp rxSize = QRegExp("(\\b\\d+\\.?\\d*(K|M|G|T|P|E)?\\b)"); int pos = 0; pos = rxSize.indexIn(rval); if (pos > -1 && rxSize.cap(0) == rval.trimmed()) { // convert the specified size unit to megabytes if (rxSize.cap(0).contains("K")) value = rxSize.cap(0).remove("K").toDouble() / 1024; else if (rxSize.cap(0).contains("M")) value = rxSize.cap(0).remove("M").toDouble(); else if (rxSize.cap(0).contains("G")) value = rxSize.cap(0).remove("G").toDouble() * 1024; else if (rxSize.cap(0).contains("T")) value = rxSize.cap(0).remove("T").toDouble() * 1024 * 1024; else if (rxSize.cap(0).contains("P")) value = rxSize.cap(0).remove("P").toDouble() * 1024 * 1024 * 1024; else if (rxSize.cap(0).contains("E")) value = rxSize.cap(0).remove("E").toDouble() * 1024 * 1024 * 1024 * 1024; else value = rxSize.cap(0).toDouble() / 1024 / 1024; // Convert from double to ulonglong (we don't support float in ui) value = value.toULongLong(); return 0; } else { qDebug() << rval << "is not a valid value for setting" << realName << ". Ignoring..."; return -1; } } return -1; }
const DateTimeField *BaseChronology::weekOfWeekyear() { return UnsupportedDateTimeField::getInstance(DateTimeFieldType::weekOfWeekyear(), weeks()); }