~ubuntu-branches/ubuntu/raring/kdepimlibs/raring-proposed

« back to all changes in this revision

Viewing changes to kcalcore/icaltimezones.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-07-08 00:32:40 UTC
  • mto: (0.5.5 experimental) (1.1.93)
  • mto: This revision was merged to the branch mainline in revision 100.
  • Revision ID: package-import@ubuntu.com-20110708003240-no12z37io7q5nxwt
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
#include <uuid/uuid.h>
44
44
#endif
45
45
 
 
46
#if defined(Q_OS_WINCE)
 
47
#include <Winbase.h>
 
48
#endif
46
49
using namespace KCalCore;
47
50
 
48
51
// Minimum repetition counts for VTIMEZONE RRULEs
397
400
  d->setComponent( icalcomponent_new_clone( rhs.d->component() ) );
398
401
}
399
402
 
 
403
#ifdef Q_OS_WINCE
 
404
// Helper function to convert Windows reccurencies to a QDate
 
405
static QDate find_nth_weekday_in_month_of_year( int nth, int dayOfWeek, int month, int year ) {
 
406
    const QDate first( year, month, 1 );
 
407
    const int actualDayOfWeek = first.dayOfWeek();
 
408
    QDate candidate = first.addDays( ( nth - 1 ) * 7 + dayOfWeek - actualDayOfWeek );
 
409
    if ( nth == 5 )
 
410
        if ( candidate.month() != month )
 
411
            candidate = candidate.addDays( -7 );
 
412
    return candidate;
 
413
}
 
414
#endif // Q_OS_WINCE
 
415
 
400
416
ICalTimeZoneData::ICalTimeZoneData( const KTimeZoneData &rhs,
401
417
                                    const KTimeZone &tz, const QDate &earliest )
402
418
  : KTimeZoneData( rhs ),
464
480
    // Compile an ordered list of transitions so that we can know the phases
465
481
    // which occur before and after each transition.
466
482
    QList<KTimeZone::Transition> transits = transitions();
 
483
    if ( transits.isEmpty() ) {
 
484
      // If there is no way to compile a complete list of transitions
 
485
      // transitions() can return an empty list
 
486
      // In that case try get one transition to write a valid VTIMEZONE entry.
 
487
#ifdef Q_OS_WINCE
 
488
      TIME_ZONE_INFORMATION currentTimeZone;
 
489
      GetTimeZoneInformation(&currentTimeZone);
 
490
      if ( QString::fromWCharArray( currentTimeZone.StandardName ) != tz.name() ) {
 
491
        kDebug() << "VTIMEZONE entry will be invalid for: " << tz.name();
 
492
      } else {
 
493
        SYSTEMTIME std = currentTimeZone.StandardDate;
 
494
        SYSTEMTIME dlt = currentTimeZone.DaylightDate;
 
495
 
 
496
        // Create the according Phases
 
497
        KTimeZone::Phase standardPhase = KTimeZone::Phase( ( currentTimeZone.Bias +
 
498
                                                             currentTimeZone.StandardBias ) * -60,
 
499
                                                           QByteArray(), false );
 
500
        KTimeZone::Phase daylightPhase = KTimeZone::Phase( ( currentTimeZone.Bias +
 
501
                                                             currentTimeZone.DaylightBias ) * -60,
 
502
                                                           QByteArray(), true );
 
503
        // Generate the transitions from the minimal to the maximal year that the calendar
 
504
        // offers on WinCE
 
505
        for ( int i = 2000; i <= 2050; i++ ) {
 
506
          QDateTime standardTime = QDateTime(  find_nth_weekday_in_month_of_year( std.wDay,
 
507
                                                 std.wDayOfWeek ? std.wDayOfWeek : 7,
 
508
                                                 std.wMonth, i ) ,
 
509
                                               QTime( std.wHour, std.wMinute,
 
510
                                                 std.wSecond, std.wMilliseconds ) );
 
511
 
 
512
          QDateTime daylightTime = QDateTime(  find_nth_weekday_in_month_of_year( dlt.wDay,
 
513
                                                 dlt.wDayOfWeek ? dlt.wDayOfWeek : 7,
 
514
                                                 dlt.wMonth, i ) ,
 
515
                                               QTime( dlt.wHour, dlt.wMinute,
 
516
                                                 dlt.wSecond, dlt.wMilliseconds ) );
 
517
 
 
518
          transits << KTimeZone::Transition( standardTime, standardPhase )
 
519
                   << KTimeZone::Transition( daylightTime, daylightPhase );
 
520
        }
 
521
      }
 
522
#endif // Q_OS_WINCE
 
523
      if ( transits.isEmpty() ) {
 
524
        kDebug() << "No transition information available VTIMEZONE will be invalid.";
 
525
      }
 
526
    }
467
527
    if ( earliest.isValid() ) {
468
528
      // Remove all transitions earlier than those we are interested in
469
529
      for ( int i = 0, end = transits.count();  i < end;  ++i ) {