397
400
d->setComponent( icalcomponent_new_clone( rhs.d->component() ) );
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 );
410
if ( candidate.month() != month )
411
candidate = candidate.addDays( -7 );
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.
488
TIME_ZONE_INFORMATION currentTimeZone;
489
GetTimeZoneInformation(¤tTimeZone);
490
if ( QString::fromWCharArray( currentTimeZone.StandardName ) != tz.name() ) {
491
kDebug() << "VTIMEZONE entry will be invalid for: " << tz.name();
493
SYSTEMTIME std = currentTimeZone.StandardDate;
494
SYSTEMTIME dlt = currentTimeZone.DaylightDate;
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
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,
509
QTime( std.wHour, std.wMinute,
510
std.wSecond, std.wMilliseconds ) );
512
QDateTime daylightTime = QDateTime( find_nth_weekday_in_month_of_year( dlt.wDay,
513
dlt.wDayOfWeek ? dlt.wDayOfWeek : 7,
515
QTime( dlt.wHour, dlt.wMinute,
516
dlt.wSecond, dlt.wMilliseconds ) );
518
transits << KTimeZone::Transition( standardTime, standardPhase )
519
<< KTimeZone::Transition( daylightTime, daylightPhase );
523
if ( transits.isEmpty() ) {
524
kDebug() << "No transition information available VTIMEZONE will be invalid.";
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 ) {