int Time::getFullDays() const { return (utcStamp()/Time::DAY_SECONDS); }
void InputWindow::on_button_MakeiCalFile_released() { // format of the times: yyyyMMddTHHmmss if (FullCalendar.size() < 20) { QMessageBox process; process.setText("Be sure to process your data first."); process.setWindowTitle("Wait"); process.exec(); return; } else if (startingMonday.isNull()){ QMessageBox process; process.setText("Be sure to select a date first."); process.setWindowTitle("Wait"); process.exec(); return; } else { QVector<QDateTime> StartTimeOfItem; QVector<QString> SummaryOfItem; QDate tmpdatesetter; QTime tmptimesetter(0, 0, 0); QTime defaultTime(0, 0, 0); QString tmpLearnItemTitle; for (int i = 1; i <= 24; i++) { //go through 24 hours for (int DayOfWeek = 0; DayOfWeek < 7; DayOfWeek++) { //go through 7 days a week per hour block //for each day of the week at this time slot check if anything is scheduled // 0 = Monday here tmpLearnItemTitle = FullCalendar.section(',', (8 + ((i-1)*7) + DayOfWeek), (8 + ((i-1)*7) + DayOfWeek)); if (!tmpLearnItemTitle.contains("BUSY")) { tmpdatesetter = startingMonday.addDays(DayOfWeek); //startingMonday must be correct for this to work. switch (i) { //set time that item starts case 1: tmptimesetter = defaultTime; break; default: tmptimesetter = defaultTime; tmptimesetter = tmptimesetter.addSecs(60*60*(i-1)); } if (DayOfWeek == 6) { //to correct the sunday grabbing dates problem int removestart = tmpLearnItemTitle.lastIndexOf('\n'); tmpLearnItemTitle.remove(removestart, 5); } SummaryOfItem.push_back(tmpLearnItemTitle); QDateTime tmpStartTime; tmpStartTime.setDate(tmpdatesetter); tmpStartTime.setTime(tmptimesetter); StartTimeOfItem.push_back(tmpStartTime); } } } //This part creates the actual openable file for Outlook or iCalendar QString NewScheduleFileName = QFileDialog::getSaveFileName(this, tr("Save File"), QString(), tr("ics File (*.ics)")); QFile iCalFile(NewScheduleFileName); if (!iCalFile.open(QIODevice::WriteOnly)) { QMessageBox::critical(this, tr("Unfinished business"), tr(".ics file has not been saved.")); return; } QTextStream out(&iCalFile); //default header for ics file - testing currently out << "BEGIN:VCALENDAR\n" << "PRODID:-//Created-By-OverDrive-Personal-Learning-Calendar\n" << "VERSION:2.0\n" << "METHOD:PUBLISH\n"; //out << "X-MS-OLK-FORCEINSPECTOROPEN:TRUE\n"; //this is for single item files only QString timezone = "\"Eastern Standard Time\""; //Time Zone - Eastern Only for initial testing, user chosen later out << "BEGIN:VTIMEZONE\n" << "TZID:Eastern Standard Time\n" << "BEGIN:STANDARD\n" << "DTSTART:16011104T020000\n" << "RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=11\n" << "TZOFFSETFROM:-0400\n" << "TZOFFSETTO:-0500\n" << "END:STANDARD\n"; //Daylight Savings Time Specifications in Eastern time zone out << "BEGIN:DAYLIGHT\n" << "DTSTART:16010311T020000\n" << "RRULE:FREQ=YEARLY;BYDAY=2SU;BYMONTH=3\n" << "TZOFFSETFROM:-0500\n" << "TZOFFSETTO:-0400\n" << "END:DAYLIGHT\n" << "END:VTIMEZONE\n"; //The Events Part - Loop for each event to schedule //duration 1hr for now for (int i = 0, j = SummaryOfItem.size(); i < j; i++) { out << "BEGIN:VEVENT\n" << "CLASS:PUBLIC\n"; QDateTime utcStamp(QDateTime::currentDateTimeUtc()); out << "CREATED:" << utcStamp.toString("yyyyMMddTHHmmsszzzZ") << "\n" //<< "DESCRIPTION:" /* << optional description*/ << "\n" //optional //<< "DTEND;TZID=" /* << learn-item date-time end*/ << "\n" //optional (we use DURATION: instead) << "DTSTAMP:" << utcStamp.toString("yyyyMMddTHHmmsszzzZ") << "\n" << "DTSTART;TZID=" << timezone << ":" << StartTimeOfItem[i].toString("yyyyMMddTHHmmss") << "\n" << "DURATION:PT1H0M0S\n" << "LAST-MODIFIED:" << utcStamp.toString("yyyyMMddTHHmmsszzzZ") << "\n" << "PRIORITY:0\n" << "SEQUENCE:0\n" << "SUMMARY;LANGUAGE=en-us:" << SummaryOfItem[i] << "\n" << "TRANSP:TRANSPARENT\n"; out << "UID:" << utcStamp.toString("yyyyMMddTHHmmsszzzZ") << "@" << QHostInfo::localHostName() << "\n"; //Alert type and setup - must be part of VEVENT so make part of loop 10 min popup for now out << "BEGIN:VALARM\n" << "TRIGGER:-PT10M\n" << "ACTION:DISPLAY\n" << "END:VALARM\n" << "END:VEVENT\n"; } out << "END:VCALENDAR\n"; //finish out calendar file // qDebug() << "Wrote to " << NewScheduleFileName; iCalFile.close(); QMessageBox success; success.setText("Test File has been written to your chosen location."); success.setWindowTitle("Good To Go"); success.exec(); } }