Beispiel #1
0
bool WTime::operator<= (const WTime& other) const
{
  if (!isValid() && !other.isValid())
    return true;

  if (!isValid() || !other.isValid())
    throw InvalidTimeException();

  return time_ <= other.time_;
}
Beispiel #2
0
void WTimePicker::setTime(const WTime& time)
{
    if (!time.isValid()) {
        LOG_ERROR("Time is invalid!");
        return;
    }

    int hours = 0;

    if (formatAp()) {
      hours = time.pmhour();

      if (time.hour() < 12)
	cbAP_->setCurrentIndex(0);
      else
	cbAP_->setCurrentIndex(1);
    } else
      hours = time.hour();

    int minutes = time.minute();
    int seconds = time.second();
    int millisecond = time.msec();

    sbhour_->setValue(hours);
    sbminute_->setValue(minutes);
    sbsecond_->setValue(seconds);

    if (formatMs()) {
        sbmillisecond_->setValue(millisecond);
    }
}
Beispiel #3
0
WValidator::Result WTimeValidator::validate(const WT_USTRING& input) const
{
  if (input.empty())
    return WValidator::validate(input);

  for (unsigned i = 0; i < formats_.size(); ++i) {
    try {
      WTime d = WTime::fromString(input, formats_[i]);

      if (d.isValid()) {
	if (!bottom_.isNull())
	  if (d < bottom_)
	    return Result(Invalid, invalidTooEarlyText());

	if (!top_.isNull())
	  if (d > top_)
	    return Result(Invalid, invalidTooLateText());
    
	return Result(Valid);
      }
    } catch (std::exception& e) {
      LOG_WARN("validate(): " << e.what());
    }
  }

  return Result(Invalid, invalidNotATimeText());
}
Beispiel #4
0
int WTime::msecsTo(const WTime& t) const
{
  if (!isValid() || !t.isValid())
    throw InvalidTimeException();

  return t.time_ - time_;
}
Beispiel #5
0
void WTimePicker::setTime(const WTime& time)
{

    if(!time.isValid()) {
        LOG_ERROR("Time is invalid!");
        return;
    }

	std::string hoursStr("0"), minutesStr("00"), secondsStr("00");

    try {
        hoursStr = time.toString("hh").toUTF8();
        minutesStr = time.toString("mm").toUTF8();
		secondsStr = time.toString("ss").toUTF8();
    } catch(const boost::bad_lexical_cast& ex) {
        LOG_ERROR("boost::bad_lexical_cast caught in WTimePicker::time()");
    }

    hourText_->setText(hoursStr);
    minuteText_->setText(minutesStr);
    secondText_->setText(secondsStr);
}