bool Event::isMultiDay( const KDateTime::Spec &spec ) const { // First off, if spec's not valid, we can check for cache if ( ( !spec.isValid() ) && d->mMultiDayValid ) { return d->mMultiDay; } // Not in cache -> do it the hard way KDateTime start, end; if ( !spec.isValid() ) { start = dtStart(); end = dtEnd(); } else { start = dtStart().toTimeSpec( spec ); end = dtEnd().toTimeSpec( spec ); } // End date is non inclusive, so subtract 1 second... except if we // got the event from some braindead implementation which gave us // start == end one (those do happen) if ( start != end ) { end = end.addSecs( -1 ); } bool multi = ( start.date() != end.date() && start <= end ); // Update the cache if ( spec.isValid() ) { d->mMultiDayValid = true; d->mMultiDay = multi; } return multi; }
void Period::shiftTimes( const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec ) { if ( oldSpec.isValid() && newSpec.isValid() && oldSpec != newSpec ) { d->mStart = d->mStart.toTimeSpec( oldSpec ); d->mStart.setTimeSpec( newSpec ); d->mEnd = d->mEnd.toTimeSpec( oldSpec ); d->mEnd.setTimeSpec( newSpec ); } }
QString Stringify::formatTime( const KDateTime &dt, bool shortfmt, const KDateTime::Spec &spec ) { if ( spec.isValid() ) { QString timeZone; if ( spec.timeZone() != KSystemTimeZones::local() ) { timeZone = ' ' + spec.timeZone().name(); } return KGlobal::locale()->formatTime( dt.toTimeSpec( spec ).time(), !shortfmt ) + timeZone; } else { return KGlobal::locale()->formatTime( dt.time(), !shortfmt ); } }
QString Todo::dtStartTimeStr( bool shortfmt, bool first, const KDateTime::Spec &spec ) const { if ( spec.isValid() ) { QString timeZone; if ( spec.timeZone() != KSystemTimeZones::local() ) { timeZone = ' ' + spec.timeZone().name(); } return KGlobal::locale()->formatTime( dtStart( first ).toTimeSpec( spec ).time(), !shortfmt ) + timeZone; } else { return KGlobal::locale()->formatTime( dtStart( first ).time(), !shortfmt ); } }
QString Todo::dtDueDateStr( bool shortfmt, const KDateTime::Spec &spec ) const { if ( spec.isValid() ) { QString timeZone; if ( spec.timeZone() != KSystemTimeZones::local() ) { timeZone = ' ' + spec.timeZone().name(); } return KGlobal::locale()->formatDate( dtDue( !recurs() ).toTimeSpec( spec ).date(), ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone; } else { return KGlobal::locale()->formatDate( dtDue( !recurs() ).date(), ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ); } }
QString Todo::dtStartStr( bool shortfmt, const KDateTime::Spec &spec ) const { if ( allDay() ) { return IncidenceFormatter::dateToString( dtStart(), shortfmt, spec ); } if ( spec.isValid() ) { QString timeZone; if ( spec.timeZone() != KSystemTimeZones::local() ) { timeZone = ' ' + spec.timeZone().name(); } return KGlobal::locale()->formatDateTime( dtStart().toTimeSpec( spec ).dateTime(), ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone; } else { return KGlobal::locale()->formatDateTime( dtStart().dateTime(), ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ); } }
QString Stringify::formatDateTime( const KDateTime &dt, bool allDay, bool shortfmt, const KDateTime::Spec &spec ) { if ( allDay ) { return formatDate( dt, shortfmt, spec ); } if ( spec.isValid() ) { QString timeZone; if ( spec.timeZone() != KSystemTimeZones::local() ) { timeZone = ' ' + spec.timeZone().name(); } return KGlobal::locale()->formatDateTime( dt.toTimeSpec( spec ).dateTime(), ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ) + timeZone; } else { return KGlobal::locale()->formatDateTime( dt.dateTime(), ( shortfmt ? KLocale::ShortDate : KLocale::LongDate ) ); } }
void KoRdfCalendarEvent::fromKEvent(KCalCore::Event::Ptr event) { m_dtstart = event->dtStart(); m_dtend = event->dtEnd(); m_summary = event->summary(); m_location = event->location(); m_uid = event->uid(); Soprano::Node n = Soprano::LiteralValue(m_dtstart.dateTime()); KDateTime::Spec tz = toKTimeZone(n); KDateTime roundTrip = VEventDateTimeToKDateTime(n.toString(), tz); kDebug(30015) << "summary:" << m_summary; kDebug(30015) << "location:" << m_location; kDebug(30015) << "uid:" << m_uid; kDebug(30015) << "dtstart:" << m_dtstart; kDebug(30015) << "dtstart.offset:" << m_dtstart.timeZone().currentOffset(); kDebug(30015) << "dtstart.utc:" << m_dtstart.toUtc(); kDebug(30015) << " local.offset:" << KSystemTimeZones::local().currentOffset(); kDebug(30015) << "dtstart.roundTrip:" << roundTrip; kDebug(30015) << "dtend:" << m_dtend; kDebug(30015) << "dtstart.rdfnode:" << n; kDebug(30015) << "dtstart.roundTrip.offset:" << tz.timeZone().currentOffset(); }
static KDateTime VEventDateTimeToKDateTime(const QString &s, KDateTime::Spec &tz) { kDebug(30015) << "top... tz.offset:" << tz.timeZone().currentOffset(); if (s.endsWith('Z')) { tz = KSystemTimeZones::zone("UTC"); kDebug(30015) << "tz.offset:" << tz.timeZone().currentOffset(); kDebug(30015) << "new date string:" << s; } KDateTime ret = KDateTime::fromString(s, "yyyyMMddTHHmmss"); if (!ret.isValid()) { // "2003-01-08T13:00:00" kDebug(30015) << "parsing dateThh:mm format...from input:" << s; ret = KDateTime::fromString(s, KDateTime::ISODate); } // // Parsed as UTC, must now adjust for given timezone // if (ret.isValid() && tz.timeZone().currentOffset()) { ret.setTimeSpec(tz); } // // convert to local tz for ease of editing. // ret = ret.toLocalZone(); tz = KSystemTimeZones::local(); kDebug(30015) << "date string:" << s << "\n" << " is valid:" << ret.isValid() << "\n" << " parsed:" << ret.toString() << "\n" << " time.tz.offset:" << ret.timeZone().currentOffset() << " tz.offset:" << tz.timeZone().currentOffset(); return ret; }
QString dumpTime( const KDateTime &dt, const KDateTime::Spec &viewSpec ) { if ( !dt.isValid() ) { return QString(); } KDateTime vdt = viewSpec.isValid() ? dt.toTimeSpec( viewSpec ) : dt; QString format; #ifdef FLOAT_IS_DATE_ONLY if ( vdt.isDateOnly() ) { format = QLatin1String( "%Y-%m-%d" ); } else #endif format = QLatin1String( "%Y-%m-%dT%H:%M:%S" ); if ( vdt.isSecondOccurrence() ) { format += QLatin1String( " %Z" ); } if ( vdt.timeSpec() != KDateTime::ClockTime ) { format += QLatin1String( " %:Z" ); } return vdt.toString( format ); }
int main( int argc, char **argv ) { KAboutData aboutData( "testrecurrencenew", 0, ki18n( "Load recurrence rules with the new class and print out debug messages" ), "0.1" ); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineOptions options; options.add( "verbose", ki18n( "Verbose output" ) ); options.add( "+input", ki18n( "Name of input file" ) ); options.add( "[+output]", ki18n( "optional name of output file for the recurrence dates" ) ); KCmdLineArgs::addCmdLineOptions( options ); KComponentData componentData( &aboutData ); //QCoreApplication app( KCmdLineArgs::qtArgc(), KCmdLineArgs::qtArgv() ); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if ( args->count() < 1 ) { args->usage( "Wrong number of arguments." ); } QString input = args->arg( 0 ); kDebug() << "Input file:" << input; QTextStream *outstream; outstream = 0; QString fn( "" ); if ( args->count() > 1 ) { fn = args->arg( 1 ); kDebug() << "We have a file name given:" << fn; } QFile outfile( fn ); if ( !fn.isEmpty() && outfile.open( QIODevice::WriteOnly ) ) { kDebug() << "Opened output file!!!"; outstream = new QTextStream( &outfile ); } MemoryCalendar::Ptr cal( new MemoryCalendar( KDateTime::UTC ) ); KDateTime::Spec viewSpec; FileStorage store( cal, input ); if ( !store.load() ) return 1; QString tz = cal->nonKDECustomProperty( "X-LibKCal-Testsuite-OutTZ" ); if ( !tz.isEmpty() ) { viewSpec = KDateTime::Spec( KSystemTimeZones::zone( tz ) ); } Incidence::List inc = cal->incidences(); for ( Incidence::List::Iterator it = inc.begin(); it != inc.end(); ++it ) { Incidence::Ptr incidence = *it; kDebug() << "*+*+*+*+*+*+*+*+*+*"; kDebug() << " ->" << incidence->summary() << "<-"; incidence->recurrence()->dump(); KDateTime dt( incidence->recurrence()->endDateTime() ); int i = 0; if ( outstream ) { if ( !dt.isValid() ) { if ( viewSpec.isValid() ) { dt = KDateTime( QDate( 2011, 1, 1 ), QTime( 0, 0, 1 ), viewSpec ); } else { dt = KDateTime( QDate( 2011, 1, 1 ), QTime( 0, 0, 1 ) ); } } else { dt = dt.addYears( 2 ); } kDebug() << "-------------------------------------------"; kDebug() << " *~*~*~*~ Starting with date:" << dumpTime( dt, viewSpec ); // Output to file for testing purposes while ( dt.isValid() && i < 500 ) { ++i; dt = incidence->recurrence()->getPreviousDateTime( dt ); if ( dt.isValid() ) { (*outstream) << dumpTime( dt, viewSpec ) << endl; } } } else { if ( !dt.isValid() ) { dt = KDateTime( QDate( 2005, 7, 31 ), QTime( 23, 59, 59 ), KDateTime::Spec::UTC() ); } else { dt = dt.addYears( 2 ); } incidence->recurrence()->dump(); kDebug() << "-------------------------------------------"; kDebug() << " *~*~*~*~ Starting with date:" << dumpTime( dt, viewSpec ); // Output to konsole while ( dt.isValid() && i < 50 ) { ++i; kDebug() << "-------------------------------------------"; dt = incidence->recurrence()->getPreviousDateTime( dt ); if ( dt.isValid() ) { kDebug() << " *~*~*~*~ Previous date is:" << dumpTime( dt, viewSpec ); } } } } delete outstream; outfile.close(); return 0; }