Exemple #1
0
void Recurrence::setStartDateTime( const KDateTime &start )
{
  if ( d->mRecurReadOnly ) {
    return;
  }
  d->mStartDateTime = start;
  setAllDay( start.isDateOnly() );   // set all RRULEs and EXRULEs

  int i, end;
  for ( i = 0, end = d->mRRules.count();  i < end;  ++i ) {
    d->mRRules[i]->setStartDt( start );
  }
  for ( i = 0, end = d->mExRules.count();  i < end;  ++i ) {
    d->mExRules[i]->setStartDt( start );
  }
  updated();
}
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 );
}
Exemple #3
0
    Incidence::Ptr pasteIncidence( const Incidence::Ptr &incidence,
                                   KDateTime newDateTime,
                                   const QFlags<PasteFlag> &pasteOptions )
    {
      Incidence::Ptr inc( incidence );

      if ( inc ) {
        inc = Incidence::Ptr( inc->clone() );
        inc->recreate();
      }

      if ( inc && newDateTime.isValid() ) {
        if ( inc->type() == Incidence::TypeEvent ) {
          Event::Ptr event = inc.staticCast<Event>();
          if ( pasteOptions & FlagPasteAtOriginalTime ) {
            // Set date and preserve time and timezone stuff
            const QDate date = newDateTime.date();
            newDateTime = event->dtStart();
            newDateTime.setDate( date );
          }

          // in seconds
          const int durationInSeconds = event->dtStart().secsTo( event->dtEnd() );
          const int durationInDays = event->dtStart().daysTo( event->dtEnd() );

          event->setDtStart( newDateTime );

          if ( newDateTime.isDateOnly() ) {
            event->setDtEnd( newDateTime.addDays( durationInDays ) );
          } else {
            event->setDtEnd( newDateTime.addSecs( durationInSeconds ) );
          }

        } else if ( inc->type() == Incidence::TypeTodo ) {
          Todo::Ptr aTodo = inc.staticCast<Todo>();
          const bool pasteAtDtStart = ( pasteOptions & FlagTodosPasteAtDtStart );
          if ( pasteOptions & FlagPasteAtOriginalTime ) {
            // Set date and preserve time and timezone stuff
            const QDate date = newDateTime.date();
            newDateTime = pasteAtDtStart ? aTodo->dtStart() : aTodo->dtDue();
            newDateTime.setDate( date );
          }
          if ( pasteAtDtStart ) {
            aTodo->setDtStart( newDateTime );
          } else {
            aTodo->setDtDue( newDateTime );
          }

        } else if ( inc->type() == Incidence::TypeJournal ) {
          if ( pasteOptions & FlagPasteAtOriginalTime ) {
            // Set date and preserve time and timezone stuff
            const QDate date = newDateTime.date();
            newDateTime = inc->dtStart();
            newDateTime.setDate( date );
          }
          inc->setDtStart( newDateTime );
        } else {
          kDebug() << "Trying to paste unknown incidence of type" << int( inc->type() );
        }
      }

      return inc;
    }