// Use this replacement for QDateTime::setTime_t(uint) since our time // values are signed. static QDateTime fromTime_t(qint32 seconds) { static const QDate epochDate(1970,1,1); static const QTime epochTime(0,0,0); int days = seconds / 86400; seconds -= days * 86400; if (seconds < 0) { --days; seconds += 86400; } return QDateTime(epochDate.addDays(days), epochTime.addSecs(seconds), Qt::UTC); }
QDateTime Dorade::getRayTime(int& ray) { int year = vptr->year; int jd = ryptr[ray].julian_day; QDate date = QDate(year,1,1); date = date.addDays(jd-1); int hour = ryptr[ray].hour; int min = ryptr[ray].min; int sec = ryptr[ray].sec; int msec = ryptr[ray].msec; QTime time = QTime(hour, min, sec, msec); return QDateTime(date, time, Qt::UTC); }
QVector<Event> EventPool::eventsByWeek( const QDate date ) { QDate firstOfRange = date; // @fixme: explicit week start firstOfRange = firstOfRange.addDays( 1 - firstOfRange.dayOfWeek() ); QDate lastOfRange = firstOfRange.addDays( 6 ); QVector<Event> events = m_eventMap.value( date.year() ); // load other years, if we overlap a year-boundary if( firstOfRange.year() < date.year() ) events.append( m_eventMap.value( firstOfRange.year() ) ); if( lastOfRange.year() > date.year() ) events.append( m_eventMap.value( lastOfRange.year() ) ); QVector<Event> eventsWeeks; for( const Event e : events ) { if( e.m_endDt.date() >= firstOfRange and e.m_startDt.date() <= lastOfRange ) eventsWeeks.append( e ); } return eventsWeeks; }
void NYBOT::buildGui () { setCaption(tr("NYBOT Quotes")); QLabel *label = new QLabel(tr("Date"), baseWidget); grid->addWidget(label, 0, 0); date = new QDateEdit(QDate::currentDate(), baseWidget); date->setAutoAdvance(TRUE); date->setOrder(QDateEdit::YMD); grid->addWidget(date, 0, 1); QDate dt = QDate::currentDate(); if (dt.dayOfWeek() == 6) dt = dt.addDays(-1); else { if (dt.dayOfWeek() == 7) dt = dt.addDays(-2); } date->setDate(dt); }
void ComingUpViewItemModel::updateEvents() { modelEventList->clear(); theData.clear(); QList<CalendarEvent*>& eventList = viewManager.GetEvents(); //int eventsLimitedTo = 3, comingUpEventCnt=0; int cntr = eventList.count(); QDate today = QDate::currentDate(); KDateTime daysLaterDate = KDateTime(today.addDays(7)); for ( int i=0;i<cntr;i++ ) { CalendarEvent* event = eventList.at(i); bool addEvent = false; //Bug#7244 Author: [email protected] //Fixed the issue with display of "coming up" "Later" event list if ( restrictEventCount == true ) { if ( today == event->StartDate().date() ) { addEvent = true; } } else { if(event->StartDate().date() > daysLaterDate.date()) { break; } else if ( event->StartDate().date() > today ) { addEvent = true; } } if ( addEvent ) { modelEventList->append(event); QString dateString; //Bug#7320 Author: [email protected] //This piece of code fixes the issue with display of event //If today: Display time followed by event //Else Display Date-time followed by event if(today == event->StartDate().date()) { dateString = event->StartDate().toString ( "hh:mm AP" ); } else { dateString = event->StartDate().toString ( "ddd dd hh:mm AP" ); } QString alarmsString("alarmOFF"); if ( event->Alarm() ) { alarmsString = "alarmON"; } theData.append( QStringList() << dateString << event->Description() << alarmsString ); } } }
bool RuleSet::parseEntry(RULE &ret, QString s, int year) { if(s.contains(QRegExp("^[0-9]+/[0-9]+$"))) { int d, m; sscanf(s.toAscii(), "%d/%d", &m, &d); ret.type = 1; ret.date.from = QDate(year, m, d); ret.date.until = QDate(year, m, d); return true; } if(s.contains(QRegExp("^[0-9]+\\.[0-9]+$"))) { int d, m; sscanf(s.toAscii(), "%d.%d", &d, &m); ret.type = 1; ret.date.from = QDate(year, m, d); ret.date.until = QDate(year, m, d); return true; } if(s.right(3) == "day") { int d = dayNameToInt(s.toAscii()); if(d != -1) { ret.type = 2; ret.weekday.from = d; ret.weekday.until = d; return true; } } if(s.left(6) == "easter") { QDate d = get_easter(year); int off; bool ok = true; QString val = s.mid(6, 1000); if(val.isEmpty()) off = 0; else off = val.toInt(&ok); if(ok) { d = d.addDays(off); ret.type = 1; ret.date.from = d; ret.date.until = d; return true; } } ret.type = 0; return false; }
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; } // Persist settings if (dateWidget->itemData(idx).toInt() != Range) { QSettings settings; settings.setValue("transactionDate", idx); } }
void HtmlExport::createEventList(QTextStream *ts) { int columns = 3; *ts << "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">" << endl; *ts << " <tr>" << endl; *ts << " <th class=\"sum\">" << i18nc("@title:column event start time", "Start Time") << "</th>" << endl; *ts << " <th>" << i18nc("@title:column event end time", "End Time") << "</th>" << endl; *ts << " <th>" << i18nc("@title:column event description", "Event") << "</th>" << endl; if (d->mSettings->eventLocation()) { *ts << " <th>" << i18nc("@title:column event locatin", "Location") << "</th>" << endl; ++columns; } if (d->mSettings->eventCategories()) { *ts << " <th>" << i18nc("@title:column event categories", "Categories") << "</th>" << endl; ++columns; } if (d->mSettings->eventAttendees()) { *ts << " <th>" << i18nc("@title:column event attendees", "Attendees") << "</th>" << endl; ++columns; } *ts << " </tr>" << endl; for (QDate dt = fromDate(); dt <= toDate(); dt = dt.addDays(1)) { qCDebug(KCALUTILS_LOG) << "Getting events for" << dt.toString(); Event::List events = d->mCalendar->events(dt, d->mCalendar->timeSpec(), EventSortStartDate, SortDirectionAscending); if (events.count()) { *ts << " <tr><td colspan=\"" << QString::number(columns) << "\" class=\"datehead\"><i>" << QLocale().toString(dt) << "</i></td></tr>" << endl; Event::List::ConstIterator it; for (it = events.constBegin(); it != events.constEnd(); ++it) { if (checkSecrecy(*it)) { createEvent(ts, *it, dt); } } } } *ts << "</table>" << endl; }
void ListWidget::paintEvent(QPaintEvent *) { int height = 1; for (QDate day = firstDay; day <= lastDay; day = day.addDays(1)) { QVector <Event*> events = manager->getEvents(day); if (events.size()) { height += 20 * (events.size() + 1); } } resize(this->width(), height); QPainter painter (this); QRect textRect(rect().left(), rect().top(), rect().width() - 1, 19); for (QDate day = firstDay; day <= lastDay; day = day.addDays(1)) { QVector <Event*> events = manager->getEvents(day); if (events.size()) { painter.setBrush(Qt::white); painter.setPen(Qt::black); painter.drawRect(textRect); painter.drawText(textRect, " Date: " + day.toString()); textRect.setTop(textRect.top() + 20); textRect.setHeight(19); for (auto event: events) { if (event->isRegular()) { painter.setBrush(QColor(Qt::blue).lighter()); } else { painter.setBrush(event->color()); } painter.drawRect(textRect); painter.drawText(textRect, Qt::AlignCenter, event->info() + " (" + event->begin().toString() + ")"); textRect.setTop(textRect.top() + 20); textRect.setHeight(19); } } } }
void RecurrenceWidget::set(bool recurring, int frequency, QString period, QDate startDate, QDate endDate, int max) { if (DEBUG) qDebug() << objectName() << "::set(" << recurring << ", " << frequency << ", " << period << ", " << startDate << ", " << endDate << ", " << max << ") entered"; // run from the beginning of the start date to the end of the end date QDateTime startDateTime(startDate); QDateTime endDateTime(endDate.addDays(1)); endDateTime = endDateTime.addMSecs(-1); set(recurring, frequency, period, startDateTime, endDateTime, max); }
QList<CPrealert> *CSinglePrealertEdit::setupNewPrealerts() { QList<CPrealert> *lPre = new QList<CPrealert>(); for(QDate i = ui->dteFrom->date(); i <= ui->dteTo->date(); i = i.addDays(1)) { CPrealert * lAlert = new CPrealert(); lAlert->setDate(i); lAlert->setPers(m_actPers); lPre->append(*lAlert); } return lPre; }
QString CrCalendar::generateEmptyLine() { QString str; QDate dayIterator; for(dayIterator = _dateFirst; dayIterator <= _dateLast; dayIterator = dayIterator.addDays(1)) if(dayIterator.dayOfWeek() == Qt::Saturday || dayIterator.dayOfWeek() == Qt::Sunday) { str += "<td class=\"" +Cell::getCssClassAsString(Cell::non_work_day)+ "\"></td>"; } else { str += "<td> </td>"; } return str; }
/*! Paints the week scale header. * \sa paintHeader() */ void DateTimeGrid::paintWeekScaleHeader( QPainter* painter, const QRectF& headerRect, const QRectF& exposedRect, qreal offset, QWidget* widget ) { QStyle* style = widget?widget->style():QApplication::style(); // Paint a section for each week QDateTime sdt = d->chartXtoDateTime( offset+exposedRect.left() ); sdt.setTime( QTime( 0, 0, 0, 0 ) ); // Go backwards until start of week while ( sdt.date().dayOfWeek() != d->weekStart ) sdt = sdt.addDays( -1 ); QDateTime dt = sdt; for ( qreal x = d->dateTimeToChartX( dt ); x < exposedRect.right()+offset; dt = dt.addDays( 7 ),x=d->dateTimeToChartX( dt ) ) { QStyleOptionHeader opt; opt.init( widget ); opt.rect = QRectF( x-offset, headerRect.top()+headerRect.height()/2., dayWidth()*7, headerRect.height()/2. ).toRect(); opt.text = QString::number( dt.date().weekNumber() ); opt.textAlignment = Qt::AlignCenter; // NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here style->drawControl( QStyle::CE_HeaderSection, &opt, painter, widget ); QStyleOptionHeader subopt = opt; subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget ); if ( subopt.rect.isValid() ) { style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget ); } } // Paint a section for each month dt = sdt; for ( qreal x2 = d->dateTimeToChartX( dt ); x2 < exposedRect.right()+offset; x2=d->dateTimeToChartX( dt ) ) { //qDebug()<<"paintWeekScaleHeader()"<<dt; QDate next = dt.date().addMonths( 1 ); next = next.addDays( 1 - next.day() ); QStyleOptionHeader opt; opt.init( widget ); opt.rect = QRectF( x2-offset, headerRect.top(), dayWidth()*dt.date().daysTo( next ), headerRect.height()/2. ).toRect(); opt.text = QDate::longMonthName( dt.date().month() ); opt.textAlignment = Qt::AlignCenter; // NOTE:CE_Header does not honor clipRegion(), so we do the CE_Header logic here style->drawControl( QStyle::CE_HeaderSection, &opt, painter, widget ); QStyleOptionHeader subopt = opt; subopt.rect = style->subElementRect( QStyle::SE_HeaderLabel, &opt, widget ); if ( subopt.rect.isValid() ) { style->drawControl( QStyle::CE_HeaderLabel, &subopt, painter, widget ); } dt.setDate( next ); } }
QDate KCalendarSystem::addDays( const QDate &date, int numDays ) const { // QDate only holds a uint and has no boundary checking in addDays(), so we need to check if ( isValid( date ) && (long) date.toJulianDay() + (long) numDays > 0 ) { // QDate adds straight to jd QDate temp = date.addDays( numDays ); if ( isValid( temp ) ) { return temp; } } //Is QDate's way of saying is invalid return QDate::fromJulianDay( 0 ); }
void KForecastView::loadBudgetView() { MyMoneyFile* file = MyMoneyFile::instance(); MyMoneyForecast forecast = KMyMoneyGlobalSettings::forecast(); //get the settings from current page and calculate this year based on last year QDate historyEndDate = QDate(QDate::currentDate().year() - 1, 12, 31); QDate historyStartDate = historyEndDate.addDays(-m_accountsCycle->value() * m_forecastCycles->value()); QDate forecastStartDate = QDate(QDate::currentDate().year(), 1, 1); QDate forecastEndDate = QDate::currentDate().addDays(m_forecastDays->value()); forecast.setHistoryMethod(m_historyMethod->checkedId()); MyMoneyBudget budget; forecast.createBudget(budget, historyStartDate, historyEndDate, forecastStartDate, forecastEndDate, false); m_budgetList->clear(); m_budgetList->setIconSize(QSize(22, 22)); m_budgetList->setSortingEnabled(true); m_budgetList->sortByColumn(0, Qt::AscendingOrder); //add columns QStringList headerLabels; headerLabels << i18n("Account"); { QDate forecastStartDate = forecast.forecastStartDate(); QDate forecastEndDate = forecast.forecastEndDate(); //add cycle interval columns QDate f_date = forecastStartDate; for (; f_date <= forecastEndDate; f_date = f_date.addMonths(1)) { headerLabels << QDate::longMonthName(f_date.month()); } } //add total column headerLabels << i18nc("Total balance", "Total"); //set the columns m_budgetList->setHeaderLabels(headerLabels); //add default rows addTotalRow(m_budgetList, forecast); addIncomeExpenseRows(forecast); //load income and expense budget accounts loadAccounts(forecast, file->income(), m_incomeItem, eBudget); loadAccounts(forecast, file->expense(), m_expenseItem, eBudget); adjustHeadersAndResizeToContents(m_budgetList); }
void KOListView::showDates(const QDate &start, const QDate &end) { clear(); QDate date = start; while(date <= end) { addIncidences(calendar()->incidences(date)); mSelectedDates.append(date); date = date.addDays(1); } emit incidenceSelected(0); }
RtdDenverEngine::DayType RtdDenverEngine::dayType(TodayTomorrow tt) const { QDate today = QDate::currentDate(); if (tt == Tomorrow) today = today.addDays(1); if (today.dayOfWeek() == Qt::Saturday) return Saturday; else if (today.dayOfWeek() == Qt::Sunday || isRtdHoliday(today)) return SundayHoliday; else return Weekday; }
void TransactionView::chooseDate(int idx) { if(!transactionProxyModel) return; QDate current = QDate::currentDate(); enableDateRangeWidget(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: enableDateRangeWidget(true); dateRangeChanged(); break; } updateTotalAmount(); }
bool CoreData::createDBFile(QString dbname) { if (QFile::exists(dbname)) { QFile::remove(dbname); } db.setDatabaseName(dbname); if (!db.open()) { QMessageBox::critical(0, QString::fromUtf8("出错了!"), QString::fromUtf8("无法打开数据库文件")); return false; } QSqlQuery query; query.exec("drop table people "); query.exec("create table people (id int primary key, name varchar(64), gender char(8), join_date date, status tinyint, comment text)"); qDebug() << db.lastError().type() << " + " << db.lastError().text(); query.exec("drop table date"); query.exec("create table date (id int primary key, date date)"); query.exec("pragma synchronous=0"); qDebug() << db.lastError().type() << " + " << db.lastError().text(); QDate date = QDate::currentDate(); date = date.addYears(-1); query.prepare("insert into date (id, date) values (?,?)"); int i = 0; QVariantList ids; QStringList dateStrings; for (i=0; i<3000; ++i) { ids<<i; date = date.addDays(1); dateStrings<<date.toString("yyyy-MM-dd"); } query.addBindValue(ids); query.addBindValue(dateStrings); if (!query.execBatch()) qDebug() << query.lastError(); query.exec("pragma synchronous=2"); qDebug()<<query.lastError(); query.exec("create table person_date (id int primary key, person_id integer, date_id integer, foreign key(person_id) references people(id), foreign key(date_id) references date(id))"); qDebug() << query.lastError(); personModel = new QSqlTableModel(0, db); setPersonModel(); signInModel = new SignInModel(0); setSignInModel(QDate::currentDate(), db); query.exec("create table contact (id int primary key, person_id integer, method varchar(64), value varchar(128), foreign key(person_id) references people(id))"); qDebug() << query.lastError(); return true; }
void TestCalendar::testHourSteps() { calendar->seekOneChild<Parameter<QTime>*>("initialTimeOfDay") -> setValue(QTime(12,0)); calendar->seekOneChild<Parameter<char>*>("timeUnit") -> setValue('h'); calendar->seekOneChild<Parameter<int>*>("timeStep") -> setValue(4); calendar->deepReset(); QDate initialDate = calendar->pullValue<QDate>("initialDate"); const int n = 8; for (int i = 0; i < n; ++i){ calendar->deepUpdate(); } //Expected: 12h + 8*4h = 44h = 1d 20h QCOMPARE(calendar->pullValue<QDate>("date"), initialDate.addDays(1)); QCOMPARE(calendar->pullValue<QTime>("timeOfDay"), QTime(20,0)); }
void TransactionWidget::arrowButtonClicked( int button ) { //if( state >= pageList.count() ) // return; QDate date = dateEdit->date(); switch( button ) { case 1: { date = date.addDays(-1); break; } case 2: { date = date.addDays(1); break; } } dateEdit->setDate( date ); loadTransactionsRequest(); }
// Does not check spill overs from previous day. This should have already been checked with isActive() void TriggerTimeRange::blockUntilActive(QTime startTime, QDateTime now, ExecutionState* state) { DataModelLogger* USERLOG = state->getLogger(); int secsToAlarm = now.time().secsTo(startTime); int alarmDayCount = 0; // If the alarm already passed today or is very close to now, push alarm for tomorrow QDate alarmDate = now.date(); if (secsToAlarm < 2) { alarmDate = alarmDate.addDays(1); secsToAlarm += ONE_DAY_IN_SEC; alarmDayCount++; } // Continuously loop over all the days to determine how long to sleep for. while (!isValueTrue(getParameter(alarmDate.toString("dddd").toStdString(), state))) { // Break out of infinite loop in case no recurring days were set if (alarmDayCount == 7) { USERLOG->error("No days are selected, aborting"); throw ExecutionAbortedException(); } alarmDate = alarmDate.addDays(1); secsToAlarm += ONE_DAY_IN_SEC; alarmDayCount++; } LOG->trace(SSTR("secsToAlarm: " << secsToAlarm)); int seconds = secsToAlarm % 60; int minutes = (secsToAlarm / 60) % 60; int hours = secsToAlarm / 3600; USERLOG->debug( SSTR( "Will go off in " << hours << ":" << std::setfill('0') << std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds)); if (state->getRuntimeResources()->sleepSafe(((unsigned long) secsToAlarm * 1000))) { LOG->trace("Forcefully woken up"); } return; }
void makeWhereClause(QString* whereClause, Database::SqlParameters* params) { qDebug(); QStringList whereStmts; if (filters.contains(EventsTableModel::LineIdentification)) { QString lineIdentificationPattern = QLatin1Char('%') % filters.value(EventsTableModel::LineIdentification).toString() % QLatin1Char('%'); whereStmts << "(PhoneNumbers.LineIdentification LIKE :lineIdentification)"; params->insert(":lineIdentification", lineIdentificationPattern); } if (filters.contains(EventsTableModel::TimeStampOn)) { whereStmts << "(Events.TimeStamp >= :timeStampAfter and" " Events.TimeStamp < :timeStampBefore)"; QDate dt = filters.value(EventsTableModel::TimeStampOn).toDate(); params->insert(":timeStampAfter", dt.toString(Qt::ISODate)); params->insert(":timeStampBefore", dt.addDays(1).toString(Qt::ISODate)); } if (filters.contains(EventsTableModel::TimeStampAfter)) { whereStmts << "(Events.TimeStamp >= :timeStampAfter)"; params->insert(":timeStampAfter", filters.value(EventsTableModel::TimeStampAfter).toString()); } if (filters.contains(EventsTableModel::TimeStampBefore)) { whereStmts << "(Events.TimeStamp < :timeStampBefore)"; params->insert(":timeStampBefore", filters.value(EventsTableModel::TimeStampBefore).toString()); } if (whereStmts.size() > 0) *whereClause = QLatin1String("WHERE\n") % whereStmts.join(QLatin1String(" and ")); }
enum SetResponse accountingPeriod::set(const ParameterList &pParams) { XDialog::set(pParams); QVariant param; bool valid; param = pParams.value("period_id", &valid); if (valid) { _periodid = param.toInt(); populate(); } param = pParams.value("mode", &valid); if (valid) { if (param.toString() == "new") { _mode = cNew; _name->setFocus(); q.exec("SELECT period_id " "FROM period " "WHERE (period_closed); "); if (q.first()) { _startDate->setEnabled(false); _year->setEnabled(false); } q.exec("SELECT (LAST(period_end) + 1) AS start_date " "FROM (SELECT period_end " " FROM period " " ORDER BY period_end) AS data; "); if (q.first()) { _startDate->setDate(q.value("start_date").toDate()); int pmonth = _startDate->date().month(); QDate pdate = _startDate->date(); while (pmonth == _startDate->date().month()) { _endDate->setDate(pdate); pdate = pdate.addDays(1); pmonth = pdate.month(); } sHandleNumber(); connect(_year, SIGNAL(newID(int)), this, SLOT(sHandleNumber())); } }
void HtmlExport::createEventList (QTextStream *ts) { int columns = 3; *ts << "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\">\n"; *ts << " <tr>\n"; *ts << " <th class=\"sum\">" << i18n("Start Time") << "</th>\n"; *ts << " <th>" << i18n("End Time") << "</th>\n"; *ts << " <th>" << i18n("Event") << "</th>\n"; if ( mSettings->eventLocation() ) { *ts << " <th>" << i18n("Location") << "</th>\n"; ++columns; } if ( mSettings->eventCategories() ) { *ts << " <th>" << i18n("Categories") << "</th>\n"; ++columns; } if ( mSettings->eventAttendees() ) { *ts << " <th>" << i18n("Attendees") << "</th>\n"; ++columns; } *ts << " </tr>\n"; for ( QDate dt = fromDate(); dt <= toDate(); dt = dt.addDays(1) ) { kdDebug(5850) << "Getting events for " << dt.toString() << endl; Event::List events = mCalendar->events(dt, EventSortStartDate, SortDirectionAscending ); if (events.count()) { Event::List::ConstIterator it; bool first = true; for( it = events.begin(); it != events.end(); ++it ) { if ( checkSecrecy( *it ) ) { if ( first ) { *ts << " <tr><td colspan=\"" << QString::number(columns) << "\" class=\"datehead\"><i>" << KGlobal::locale()->formatDate(dt) << "</i></td></tr>\n"; first = false; } createEvent( ts, *it, dt ); } } } } *ts << "</table>\n"; }
QDateTime KTimeZone::fromTime_t(time_t t) { static const int secondsADay = 86400; static const QDate epochDate(1970,1,1); static const QTime epochTime(0,0,0); int days = t / secondsADay; int secs; if (t >= 0) secs = t % secondsADay; else { secs = secondsADay - (-t % secondsADay); --days; } return QDateTime(epochDate.addDays(days), epochTime.addSecs(secs), Qt::UTC); }
void EventArchiver::run( Calendar* calendar, const QDate& limitDate, QWidget* widget, bool withGUI, bool errorIfNone ) { // We need to use rawEvents, otherwise events hidden by filters will not be archived. Incidence::List incidences; Event::List events; Todo::List todos; Journal::List journals; if ( KOPrefs::instance()->mArchiveEvents ) { events = calendar->rawEvents( QDate( 1769, 12, 1 ), // #29555, also advertised by the "limitDate not included" in the class docu limitDate.addDays( -1 ), true ); } if ( KOPrefs::instance()->mArchiveTodos ) { Todo::List t = calendar->rawTodos(); Todo::List::ConstIterator it; for( it = t.begin(); it != t.end(); ++it ) { if ( (*it) && ( (*it)->isCompleted() ) && ( (*it)->completed().date() < limitDate ) ) { todos.append( *it ); } } } incidences = Calendar::mergeIncidenceList( events, todos, journals ); kdDebug(5850) << "EventArchiver: archiving incidences before " << limitDate << " -> " << incidences.count() << " incidences found." << endl; if ( incidences.isEmpty() ) { if ( withGUI && errorIfNone ) KMessageBox::information( widget, i18n("There are no items before %1") .arg(KGlobal::locale()->formatDate(limitDate)), "ArchiverNoIncidences" ); return; } switch ( KOPrefs::instance()->mArchiveAction ) { case KOPrefs::actionDelete: deleteIncidences( calendar, limitDate, widget, incidences, withGUI ); break; case KOPrefs::actionArchive: archiveIncidences( calendar, limitDate, widget, incidences, withGUI ); break; } }
void DDatePicker::Private::fillWeeksCombo() { // every year can have a different number of weeks // it could be that we had 53,1..52 and now 1..53 which is the same number but different // so always fill with new values // We show all week numbers for all weeks between first day of year to last day of year // This of course can be a list like 53,1,2..52 const QDate thisDate = q->date(); const int thisYear = thisDate.year(); QDate day(thisDate.year(), 1, 1); const QDate lastDayOfYear = QDate(thisDate.year() + 1, 1, 1).addDays(-1); selectWeek->clear(); // Starting from the first day in the year, loop through the year a week at a time // adding an entry to the week combo for each week in the year for (; day.isValid() && day <= lastDayOfYear; day = day.addDays(7)) { // Get the ISO week number for the current day and what year that week is in // e.g. 1st day of this year may fall in week 53 of previous year int weekYear = thisYear; const int week = day.weekNumber(&weekYear); QString weekString = i18n("Week %1", QString::number(week)); // show that this is a week from a different year if (weekYear != thisYear) { weekString += QLatin1Char('*'); } // when the week is selected, go to the same weekday as the one // that is currently selected in the date table QDate targetDate = day.addDays(thisDate.dayOfWeek() - day.dayOfWeek()); selectWeek->addItem(weekString, targetDate); // make sure that the week of the lastDayOfYear is always inserted: in Chinese calendar // system, this is not always the case if (day < lastDayOfYear && day.daysTo(lastDayOfYear) < 7 && lastDayOfYear.weekNumber() != day.weekNumber()) { day = lastDayOfYear.addDays(-7); } } }
QString DateStringBuilder::getGroupedDate(const KDateTime &dateTime) { if (!dateTime.isValid() || dateTime.isNull()) { return QString(); } QDate currentDate = QDateTime::currentDateTime().date(); if (currentDate.weekNumber() == dateTime.date().weekNumber()) { //this week return getDayName(dateTime); } if (currentDate.addDays(-7).weekNumber() == dateTime.date().weekNumber()) { //last week return i18n("Last Week"); } if (currentDate.year() == dateTime.date().year()) { //this year return dateTime.toString("%B"); } return dateTime.toString("%B %Y"); }
void MyMoneyQifWriter::writeAccountEntry(QTextStream &s, const QString& accountId, const QDate& startDate, const QDate& endDate) { MyMoneyFile* file = MyMoneyFile::instance(); MyMoneyAccount account; account = file->account(accountId); MyMoneyTransactionFilter filter(accountId); filter.setDateFilter(startDate, endDate); QValueList<MyMoneyTransaction> list = file->transactionList(filter); QString openingBalanceTransactionId; s << "!Type:" << m_qifProfile.profileType() << endl; if(!startDate.isValid() || startDate <= account.openingDate()) { s << "D" << m_qifProfile.date(account.openingDate()) << endl; openingBalanceTransactionId = file->openingBalanceTransaction(account); MyMoneySplit split; if(!openingBalanceTransactionId.isEmpty()) { MyMoneyTransaction openingBalanceTransaction = file->transaction(openingBalanceTransactionId); split = openingBalanceTransaction.splitByAccount(account.id(), true /* match */); } s << "T" << m_qifProfile.value('T', split.value()) << endl; } else { s << "D" << m_qifProfile.date(startDate) << endl; s << "T" << m_qifProfile.value('T', file->balance(accountId, startDate.addDays(-1))) << endl; } s << "CX" << endl; s << "P" << m_qifProfile.openingBalanceText() << endl; s << "L"; if(m_qifProfile.accountDelimiter().length()) s << m_qifProfile.accountDelimiter()[0]; s << account.name(); if(m_qifProfile.accountDelimiter().length() > 1) s << m_qifProfile.accountDelimiter()[1]; s << endl; s << "^" << endl; QValueList<MyMoneyTransaction>::ConstIterator it; signalProgress(0, list.count()); int count = 0; for(it = list.begin(); it != list.end(); ++it) { // don't include the openingBalanceTransaction again if((*it).id() != openingBalanceTransactionId) writeTransactionEntry(s, *it, accountId); signalProgress(++count, 0); } }