void transactionview::choosedate(int idx) { if(!transactionproxymodel) return; qdate current = qdate::currentdate(); daterangewidget->setvisible(false); switch(datewidget->itemdata(idx).toint()) { case all: transactionproxymodel->setdaterange( transactionfilterproxy::min_date, transactionfilterproxy::max_date); break; case today: transactionproxymodel->setdaterange( qdatetime(current), transactionfilterproxy::max_date); break; case thisweek: { // find last monday qdate startofweek = current.adddays(-(current.dayofweek()-1)); transactionproxymodel->setdaterange( qdatetime(startofweek), transactionfilterproxy::max_date); } break; case thismonth: transactionproxymodel->setdaterange( qdatetime(qdate(current.year(), current.month(), 1)), transactionfilterproxy::max_date); break; case lastmonth: transactionproxymodel->setdaterange( qdatetime(qdate(current.year(), current.month()-1, 1)), qdatetime(qdate(current.year(), current.month(), 1))); break; case thisyear: transactionproxymodel->setdaterange( qdatetime(qdate(current.year(), 1, 1)), transactionfilterproxy::max_date); break; case range: daterangewidget->setvisible(true); daterangechanged(); break; } }
QDateTime pttoqt(const boost::posix_time::ptime &pt) { boost::gregorian::date gd = pt.date(); boost::posix_time::time_duration gt = pt.time_of_day(); QDate qdate(gd.year(), gd.month(), gd.day()); QTime qtime(gt.hours(), gt.minutes(), gt.seconds()); return QDateTime(qdate, qtime); }
int FlowRead::f(ptime time, int dt) { boost::gregorian::date gd = time.date(); boost::posix_time::time_duration gt = time.time_of_day(); QDate qdate(gd.year(), gd.month(), gd.day()); QTime qtime(gt.hours(), gt.minutes(), gt.seconds()); QDateTime current(qdate, qtime); ctxt.setOutPort(&out, current, dt); return dt; }
QString Ut::conv(QString s) { const int TIME = 28; int year = s.mid(TIME+0,4).toInt(); int month = s.mid(TIME+4, 2).toInt(); int day = s.mid(TIME+6, 2).toInt(); QDate qdate(year, month, day); int hour = s.mid(TIME+8, 2).toInt(); int minute = s.mid(TIME+10, 2).toInt(); int second = s.mid(TIME+12, 2).toInt(); QTime qtime(hour, minute, second); QDateTime qdt(qdate, qtime); qDebug() << "LST " << year << zero(month) << zero(day) << zero(hour) << zero(minute) << zero(second) << endl; qDebug() << qdate << qtime << qdt; // double Longitude = hours(13, 3, 52.65); // Zeiss-Triplet QString hhmmss; if (ui.ST2UT->isChecked()) { double UT = ST2UT(qdt); hhmmss = h2hhmmss(UT); qtime = QTime::fromString(hhmmss, "hhmmss"); qdt = QDateTime(qdate, qtime); if (qtime.hour() < 12) qdt = qdt.addDays(1); /* предполагаме, че датата е началото на нощта и не е сменяна през цялата нощ */ /* предполагаме, че датата в началото на нощта е същата, както в часова зона 0 */ } else { qdt = qdt.addSecs(-dsavingtime(qdt)*60*60); // LT -> UT // UT = hours(qdt.time().hour(), qdt.time().minute(), qdt.time().second()); } QString sout = s.left(TIME) + qdt.toString("yyyyMMddhhmmss") + s.mid(TIME+14); qDebug() << s; qDebug() << sout; return sout; }
void TodoList::mousePressEvent(QMouseEvent *event){ int x = event->globalPos().x() - this->pos().x(); int y = event->globalPos().y() - this->pos().y(); pressX = x; pressY = y; oldMoveY = moveY; mousePre = true; if(y < 76 && (x >= 68 && x <= 105)){ viewDate.ToLastMonth(); ChangeState(WINSTATE::LIST); } if(y < 76 && (x >= 318 && x <= 355)){ viewDate.ToNextMonth(); ChangeState(WINSTATE::LIST); } //qDebug("%d %d",x,y); if(y < 76 && (x >= 255 && x <= 320)){ viewState = VIEWSTATE((int(viewState) + 1)%3); ChangeState(WINSTATE::LIST); } mouseList[mouseCount ++] = event->button()==Qt::LeftButton; mouseTime = 20; //以下把y转为绘制画面的相对坐标 //相对选择项目的坐标 int sy = y - moveY; selectIndex = (sy - 95) / 80; if(ValidIndex()) oldMoveX = indexPosX[selectIndex]; if(ValidIndex() && indexID[selectIndex] != -1){ int id = indexID[selectIndex]; int viewYear = viewDate.year; int viewMonth = viewDate.month; TodoItem &item = pa.GetItem(id,viewYear,viewMonth); int offset = selectIndex * 80; if(85 <= x && x <= 120 && 110 + offset <= sy && sy <= 140 + offset){ pa.MarkAsDone(id,viewYear,viewMonth,!item.HaveDone()); } if(mouseCount >= 2 && mouseList[0] && mouseList[1]){ //跳转到添加新Todo界面 ui->nameBox->setText(QString::fromStdString(item.GetName())); switch (item.GetLevel()) { case 0: ui->radioButton_4->setChecked(true);break; case 1: ui->radioButton_2->setChecked(true);break; case 2: ui->radioButton_3->setChecked(true);break; case 3: ui->radioButton_1->setChecked(true);break; } ui->horizontalSlider->setValue(item.GetWarnTime()/5); SetWarnText(ui->horizontalSlider->value()); Date date = item.GetTime(); QDate qdate(date.year,date.month,date.day); QTime qtime(date.hour,date.minute); ui->dateTimeEdit->setDateTime(QDateTime(qdate,qtime)); ui->placeBox->setText(QString::fromStdString(item.GetPlace())); ui->labelBox->setText(QString::fromStdString(item.GetLabel())); ui->contentBox->setText(QString::fromStdString(item.GetContent())); ui->comboBox->setCurrentIndex(item.GetKind()); selectID = id; ChangeState(WINSTATE::DETAIL); mouseCount = 0; } if(mouseCount >= 2 && !mouseList[0] && !mouseList[1]){ pa.RemoveTodo(id,viewYear,viewMonth); mouseCount = 0; } } }
// Ported to Qt4 from KDElibs4 QDateTime RssParser::parseDate(const QString &string) { const QString str = string.trimmed(); if (str.isEmpty()) return QDateTime::currentDateTime(); int nyear = 6; // indexes within string to values int nmonth = 4; int nday = 2; int nwday = 1; int nhour = 7; int nmin = 8; int nsec = 9; // Also accept obsolete form "Weekday, DD-Mon-YY HH:MM:SS ±hhmm" QRegExp rx("^(?:([A-Z][a-z]+),\\s*)?(\\d{1,2})(\\s+|-)([^-\\s]+)(\\s+|-)(\\d{2,4})\\s+(\\d\\d):(\\d\\d)(?::(\\d\\d))?\\s+(\\S+)$"); QStringList parts; if (!str.indexOf(rx)) { // Check that if date has '-' separators, both separators are '-'. parts = rx.capturedTexts(); bool h1 = (parts[3] == QLatin1String("-")); bool h2 = (parts[5] == QLatin1String("-")); if (h1 != h2) return QDateTime::currentDateTime(); } else { // Check for the obsolete form "Wdy Mon DD HH:MM:SS YYYY" rx = QRegExp("^([A-Z][a-z]+)\\s+(\\S+)\\s+(\\d\\d)\\s+(\\d\\d):(\\d\\d):(\\d\\d)\\s+(\\d\\d\\d\\d)$"); if (str.indexOf(rx)) return QDateTime::currentDateTime(); nyear = 7; nmonth = 2; nday = 3; nwday = 1; nhour = 4; nmin = 5; nsec = 6; parts = rx.capturedTexts(); } bool ok[4]; const int day = parts[nday].toInt(&ok[0]); int year = parts[nyear].toInt(&ok[1]); const int hour = parts[nhour].toInt(&ok[2]); const int minute = parts[nmin].toInt(&ok[3]); if (!ok[0] || !ok[1] || !ok[2] || !ok[3]) return QDateTime::currentDateTime(); int second = 0; if (!parts[nsec].isEmpty()) { second = parts[nsec].toInt(&ok[0]); if (!ok[0]) return QDateTime::currentDateTime(); } bool leapSecond = (second == 60); if (leapSecond) second = 59; // apparently a leap second - validate below, once time zone is known int month = 0; for ( ; month < 12 && parts[nmonth] != shortMonth[month]; ++month) ; int dayOfWeek = -1; if (!parts[nwday].isEmpty()) { // Look up the weekday name while (++dayOfWeek < 7 && shortDay[dayOfWeek] != parts[nwday]) ; if (dayOfWeek >= 7) for (dayOfWeek = 0; dayOfWeek < 7 && longDay[dayOfWeek] != parts[nwday]; ++dayOfWeek) ; } // if (month >= 12 || dayOfWeek >= 7 // || (dayOfWeek < 0 && format == RFCDateDay)) // return QDateTime; int i = parts[nyear].size(); if (i < 4) { // It's an obsolete year specification with less than 4 digits year += (i == 2 && year < 50) ? 2000: 1900; } // Parse the UTC offset part int offset = 0; // set default to '-0000' bool negOffset = false; if (parts.count() > 10) { rx = QRegExp("^([+-])(\\d\\d)(\\d\\d)$"); if (!parts[10].indexOf(rx)) { // It's a UTC offset ±hhmm parts = rx.capturedTexts(); offset = parts[2].toInt(&ok[0]) * 3600; int offsetMin = parts[3].toInt(&ok[1]); if (!ok[0] || !ok[1] || offsetMin > 59) return QDateTime(); offset += offsetMin * 60; negOffset = (parts[1] == QLatin1String("-")); if (negOffset) offset = -offset; } else { // Check for an obsolete time zone name QByteArray zone = parts[10].toLatin1(); if (zone.length() == 1 && isalpha(zone[0]) && toupper(zone[0]) != 'J') negOffset = true; // military zone: RFC 2822 treats as '-0000' else if (zone != "UT" && zone != "GMT") { // treated as '+0000' offset = (zone == "EDT") ? -4*3600 : (zone == "EST" || zone == "CDT") ? -5*3600 : (zone == "CST" || zone == "MDT") ? -6*3600 : (zone == "MST" || zone == "PDT") ? -7*3600 : (zone == "PST") ? -8*3600 : 0; if (!offset) { // Check for any other alphabetic time zone bool nonalpha = false; for (int i = 0, end = zone.size(); i < end && !nonalpha; ++i) nonalpha = !isalpha(zone[i]); if (nonalpha) return QDateTime(); // TODO: Attempt to recognize the time zone abbreviation? negOffset = true; // unknown time zone: RFC 2822 treats as '-0000' } } } } QDate qdate(year, month+1, day); // convert date, and check for out-of-range if (!qdate.isValid()) return QDateTime::currentDateTime(); QTime qTime(hour, minute, second); QDateTime result(qdate, qTime, Qt::UTC); if (offset) result = result.addSecs(-offset); if (!result.isValid()) return QDateTime::currentDateTime(); // invalid date/time if (leapSecond) { // Validate a leap second time. Leap seconds are inserted after 23:59:59 UTC. // Convert the time to UTC and check that it is 00:00:00. if ((hour*3600 + minute*60 + 60 - offset + 86400*5) % 86400) // (max abs(offset) is 100 hours) return QDateTime::currentDateTime(); // the time isn't the last second of the day } return result; }
bool Timehelper::beforenow(QString date, QString time) { QDate qdate(date.mid(0,4).toInt(),date.mid(5,2).toInt(),date.mid(8,2).toInt()); QTime qtime(time.mid(0,2).toInt(),time.mid(3,2).toInt()); return QDateTime::currentDateTime().secsTo(QDateTime(qdate,qtime)) < 0; }
qint64 Timehelper::daysfromtoday(QString date) { QDate qdate(date.mid(0,4).toInt(),date.mid(5,2).toInt(),date.mid(8,2).toInt()); return QDate::currentDate().daysTo(qdate); }
void clearcf() {m_cfdate = qdate();}