bool WDate::operator== (const WDate& other) const { if ((!isValid() && !isNull()) || (!other.isValid() && !other.isNull())) throw InvalidDateException(); return (year_ == other.year_ && month_ == other.month_ && day_ == other.day_); }
WValidator::Result WDateValidator::validate(const WT_USTRING& input) const { if (input.empty()) return WValidator::validate(input); for (unsigned i = 0; i < formats_.size(); ++i) { try { WDate d = WDate::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, invalidNotADateText()); }
int WDate::daysTo(const WDate& other) const { if (!isValid() || !other.isValid()) throw InvalidDateException(); date dthis(year_, month_, day_); date dother(other.year_, other.month_, other.day_); date_duration dd = dother - dthis; return dd.days(); }
void Calendar::onSelect(std::string date) { selection_.clear(); WDate d = WDate::fromString(date, "dd/MM/yyyy"); if (d.isValid()) { selection_.insert(d); selectionChanged_.emit(); selected_.emit(); } else LOG_ERROR("could not parse date: '" << date << "'"); }
void WDatePicker::setFromLineEdit() { WDate d = WDate::fromString(forEdit_->text(), format_); if (d.isValid()) { if (calendar_->selection().empty()) { calendar_->select(d); calendar_->selectionChanged().emit(); } else { WDate j = Utils::first(calendar_->selection()); if (j != d) { calendar_->select(d); calendar_->selectionChanged().emit(); } } calendar_->browseTo(d); } }
bool WDate::operator< (const WDate& other) const { if (!isValid() || !other.isValid()) throw InvalidDateException(); if (year_ < other.year_) return true; else if (year_ == other.year_) { if (month_ < other.month_) return true; else if (month_ == other.month_) return day_ < other.day_; else return false; } else return false; }