/** Set all weekdays in the month on which this rule is repeated. @leave KErrNotSupported If it is called on a repeat rule which is not monthly or yearly. @param aDays Array containing all days in the month that are to be set. Any days in the month not included in this array will not be set. For a yearly rule, only the first item in the array will be used. Any invalid data will be ignored. @publishedAll @released @capability None */ EXPORT_C void TCalRRule::SetByDay(const RArray<TDayOfMonth>& aDays) { __ASSERT_ALWAYS(iType == EMonthly || iType == EYearly, User::Leave(KErrNotSupported)); if (iType == EMonthly) { iBuffer = 0; TInt daysCount = aDays.Count(); for (TInt i = 0; i < daysCount; ++i) { TDayOfMonth dayOfMonth = aDays[i]; TDay weekDay = dayOfMonth.Day(); if (weekDay >= EMonday && weekDay <= ESunday) { TInt byteToSet = dayOfMonth.WeekInMonth(); // if this day and week are valid then set this bit if (byteToSet == -1 || (byteToSet >= 1 && byteToSet <= 4)) { if (byteToSet == -1) { byteToSet = 0; } // first 7 bits represent which weekdays are set on the last week of the month - (week = -1) // next 7 bits represent which weekdays are set on the 1st week of the month - (week = 1) // next 7 bits represent which weekdays are set on the 2nd week of the month - (week = 2) // next 7 bits represent which weekdays are set on the 3rd week of the month - (week = 3) // next 7 bits represent which weekdays are set on the 4th week of the month - (week = 4) TUint bitToSet = weekDay + 7 * byteToSet; SetNthBit(bitToSet); } } } SetNthBit(KMonthlyByWeek); } else if (iType == EYearly) { if (!GetNthBit(KYearlyByWeek)) { iBuffer = 0; SetNthBit(KYearlyByWeek); } if (aDays.Count() >= 1) { TDay theDay = aDays[0].Day(); TInt8 theWeek = aDays[0].WeekInMonth(); if (theDay >= EMonday && theDay <= ESunday && (theWeek == -1 || (theWeek >= 1 && theWeek <= 4)) ) { TUint8* bufferPtr = (TUint8*)&iBuffer; // convert the iBuffer store to three TUint8s // EMonday=0 so store it as 1, this allows us to tell if any days have been set bufferPtr[0] = (TUint8)theDay+1; bufferPtr[1] = (TUint8)theWeek; } } } }
long WINAPI DLLExport Expression3(LPRDATA rdPtr,long param1) { long p1 = CNC_GetFirstExpressionParameter(rdPtr, param1, TYPE_INT); long p2 = CNC_GetNextExpressionParameter(rdPtr, param1, TYPE_INT); return GetNthBit(p1,p2); }
/** Gets all dates of the month on which this rule is repeated. @param aMonthDays On return, this array contains all month dates that are to be set. This function will do nothing if this is not a monthly repeat rule. Note that 0 represents 1st of the month, 1 represents 2nd, etc. @publishedAll @released @capability None */ EXPORT_C void TCalRRule::GetByMonthDayL(RArray<TInt>& aMonthDays) const { if (iType == EMonthly) { aMonthDays.Reset(); if (!GetNthBit(KMonthlyByWeek)) { // check first 31 bits of iBuffer to see which dates have been set for (TInt i = 0; i <= 30; ++i) { if (GetNthBit(i)) { aMonthDays.AppendL(i); } } } } }
/** Gets all days in the month on which this rule is repeated. @param aDays On return this array contains all days in the month that are to be set. This function will do nothing if this is not a monthly or yearly repeat rule. @publishedAll @released @capability None */ EXPORT_C void TCalRRule::GetByDayL(RArray<TDayOfMonth>& aDays) const { if (iType == EMonthly) { aDays.Reset(); if (GetNthBit(KMonthlyByWeek)) { // if i == 35, then weekNum = 5 below which is too high for (TUint i = 0; i < 35; ++i) { if (GetNthBit(i)) { // This is the reverse of the algorithm in TCalRRule::SetByDay(const RArray<TDayOfMonth>& aDays) TDay day = static_cast<TDay>(i % 7); TInt weekNum = i / 7; if (weekNum == 0) { weekNum = -1; } TDayOfMonth dayOfMonth(day, weekNum); aDays.AppendL(dayOfMonth); } } } } else if (iType == EYearly) { aDays.Reset(); if (GetNthBit(KYearlyByWeek)) { TUint8* bufferPtr = (TUint8*)&iBuffer; // convert the iBuffer store to three TUint8s TDay theDay = TDay(bufferPtr[0]-1); // -1 because EMonday is stored as +1 TInt8 theWeek = TInt8(bufferPtr[1]); if (theDay >= EMonday && theDay <= ESunday) { TDayOfMonth dayOfMonth(theDay, theWeek); aDays.AppendL(dayOfMonth); } } } }
/** Gets the month of the year for this repeat rule. This function will do nothing if this is not a yearly repeat rule @param aMonths On return, the months on which to repeat. @publishedAll @released @capability None */ EXPORT_C void TCalRRule::GetByMonthL(RArray<TMonth>& aMonths) const { if (iType == EYearly) { aMonths.Reset(); if (GetNthBit(KYearlyByWeek)) { TUint8* bufferPtr = (TUint8*)&iBuffer; // convert the iBuffer store to three TUint8s TMonth theMonth = TMonth(bufferPtr[2]-1); // -1 because EJanuary stored as 1 if (theMonth >= EJanuary && theMonth <= EDecember) { aMonths.AppendL(theMonth); } } } }
/** Gets all weekdays on which this rule is repeated. @param aDays On return this array contains all weekdays that are to be set. This function will do nothing if this is not a weekly repeat rule. @publishedAll @released @capability None */ EXPORT_C void TCalRRule::GetByDayL(RArray<TDay>& aDays) const { if (iType == EWeekly) { aDays.Reset(); TDay day = EMonday; while(day <= ESunday) { if (GetNthBit(static_cast<TUint>(day))) { aDays.AppendL(day); } day = static_cast<TDay>((static_cast<TInt>(day) + 1)); } } }
/* Member function ibitstream::readBit * --------------------------------- * If bits remain in curByte, retrieve next and increment pos * Else if end of curByte (or some other read happened), then read next byte * and start reading from bit position 0 of that byte. * If read byte from file at EOF, return EOF. */ int ibitstream::readBit() { if (!is_open()) { error("Cannot read a bit from a stream that is not open."); } // if just finished bits from curByte or if data read from stream after last readBit() if (lastTell != tellg() || pos == NUM_BITS_IN_BYTE) { if ((curByte = get()) == EOF) { // read next single byte from file return EOF; } pos = 0; // start reading from first bit of new byte lastTell = tellg(); } int result = GetNthBit(pos, curByte); pos++; // advance bit position for next call to readBit return result; }
/** Sets the month of the year for this repeat rule. @leave KErrNotSupported If it is not on a yearly repeat rule @param aMonths Array of months on which to repeat. Only the first month in the array is used. @publishedAll @released @capability None */ EXPORT_C void TCalRRule::SetByMonth(const RArray<TMonth> aMonths) { __ASSERT_ALWAYS(iType == EYearly, User::Leave(KErrNotSupported)); if (aMonths.Count() >= 1) { TMonth month = aMonths[0]; if (month >= EJanuary && month <= EDecember) { if (!GetNthBit(KYearlyByWeek)) { iBuffer = 0; SetNthBit(KYearlyByWeek); } TUint8* bufferPtr = (TUint8*)&iBuffer; // convert the iBuffer store to three TUint8s // EJanuary=0 so store it as 1, this allows us to tell if any months have been set bufferPtr[2] = (TUint8)month+1; } } }