email/imum/Utils/Src/ImumMboxScheduler.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *		Alwaysonline email scheduler class.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 
       
    23 #include "ImumMboxScheduler.h"
       
    24 #include "ImumInSettingsData.h"
       
    25 #include "ImumInSettingsKeys.h"
       
    26 #include "ImumInternalApiImpl.h"
       
    27 #include "ImumUtilsLogging.h"
       
    28 
       
    29 // EXTERNAL DATA STRUCTURES
       
    30 // EXTERNAL FUNCTION PROTOTYPES
       
    31 // CONSTANTS
       
    32 const TInt KImumSecondsIn24Hours = 86400;
       
    33 const TInt KImumDaysInWeek = 7;
       
    34 
       
    35 // MACROS
       
    36 // LOCAL CONSTANTS AND MACROS
       
    37 // MODULE DATA STRUCTURES
       
    38 // LOCAL FUNCTION PROTOTYPES
       
    39 // FORWARD DECLARATIONS
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // ----------------------------------------------------------------------------
       
    44 // CImumMboxScheduler::CImumMboxScheduler()
       
    45 // ----------------------------------------------------------------------------
       
    46 //
       
    47 CImumMboxScheduler::CImumMboxScheduler( 
       
    48     CImumInternalApiImpl& aMailboxApi,
       
    49     const TMsvId aMailboxId ) 
       
    50     :
       
    51     iMailboxApi( aMailboxApi ),
       
    52     iDays( 0 ),
       
    53     iStartTime( 0 ),
       
    54     iStopTime( 0 ),
       
    55     iMailboxId( aMailboxId )
       
    56     {
       
    57     IMUM_CONTEXT( CImumMboxScheduler::CImumMboxScheduler, 0, KLogInApi );
       
    58     
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------------------------------
       
    62 // CImumMboxScheduler::~CImumMboxScheduler()
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 CImumMboxScheduler::~CImumMboxScheduler()
       
    66     {
       
    67     IMUM_CONTEXT( CImumMboxScheduler::~CImumMboxScheduler, 0, KLogInApi );
       
    68     
       
    69     }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // CImumMboxScheduler::ConstructL()
       
    73 // ----------------------------------------------------------------------------
       
    74 //
       
    75 void CImumMboxScheduler::ConstructL()
       
    76     {
       
    77     IMUM_CONTEXT( CImumMboxScheduler::ConstructL, 0, KLogInApi );
       
    78     
       
    79     // Load the data from the settings for further use
       
    80     TInt64 days;
       
    81     TMsvEntry mbox = iMailboxApi.MailboxUtilitiesL().GetMailboxEntryL( 
       
    82         iMailboxId, MImumInMailboxUtilities::ERequestReceiving );
       
    83     iMailboxApi.SettingsStorerL().LoadAlwaysOnlineSettingsL(
       
    84         mbox.iMtmData2, mbox.iMtm, days, iStartTime, iStopTime, iActive );
       
    85 
       
    86     // First check if all of the days are unchecked, which should not happen
       
    87     // at all, but just in case
       
    88     iDays = !days ? TImumDaSettings::EFlagSetAllDays : days;
       
    89     iActive = ( iActive != EMailAoOff ) ? 
       
    90         MImumInMailboxUtilities::EFlagTurnedOn : 0;
       
    91     }
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // CImumMboxScheduler::NewL()
       
    95 // ----------------------------------------------------------------------------
       
    96 //
       
    97 CImumMboxScheduler* CImumMboxScheduler::NewL( 
       
    98     CImumInternalApiImpl& aMailboxApi,
       
    99     const TMsvId aMailboxId )
       
   100     {
       
   101     IMUM_STATIC_CONTEXT( CImumMboxScheduler::NewL, 0, utils, KLogInApi );
       
   102     
       
   103     CImumMboxScheduler* self = NewLC( aMailboxApi, aMailboxId );
       
   104     CleanupStack::Pop( self );
       
   105 
       
   106     return self;
       
   107     }
       
   108 
       
   109 // ----------------------------------------------------------------------------
       
   110 // CImumMboxScheduler::NewLC()
       
   111 // ----------------------------------------------------------------------------
       
   112 //
       
   113 CImumMboxScheduler* CImumMboxScheduler::NewLC( 
       
   114     CImumInternalApiImpl& aMailboxApi,
       
   115     const TMsvId aMailboxId )
       
   116     {
       
   117     IMUM_STATIC_CONTEXT( CImumMboxScheduler::NewLC, 0, utils, KLogInApi );
       
   118     
       
   119     CImumMboxScheduler* self =
       
   120         new ( ELeave ) CImumMboxScheduler( aMailboxApi, aMailboxId );
       
   121     CleanupStack::PushL( self );
       
   122     self->ConstructL();
       
   123 
       
   124     return self;
       
   125     }
       
   126 
       
   127 /******************************************************************************
       
   128 
       
   129     Public scheduling functions
       
   130 
       
   131 ******************************************************************************/
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 // CImumMboxScheduler::AlwaysOnlineOn()
       
   135 // ----------------------------------------------------------------------------
       
   136 //
       
   137 TInt64 CImumMboxScheduler::QueryAlwaysOnlineStateL()
       
   138     {
       
   139     IMUM_CONTEXT( CImumMboxScheduler::QueryAlwaysOnlineStateL, 0, KLogInApi );
       
   140     
       
   141     TBool ok = EFalse;
       
   142     TInt64 flags = 0;
       
   143 
       
   144     if ( iActive )
       
   145         {
       
   146         // Get hometime
       
   147         TTime clock;
       
   148         TTimeIntervalSeconds homeTime;
       
   149         TTimeIntervalSeconds startTime;
       
   150         TTimeIntervalSeconds stopTime;
       
   151         PrepareScheduling( clock, homeTime, startTime, stopTime );
       
   152         
       
   153         flags = MImumInMailboxUtilities::EFlagTurnedOn;
       
   154 
       
   155         ok = AlwaysOnlineOn( clock, homeTime, startTime, stopTime );
       
   156         
       
   157         if ( ok )
       
   158             {
       
   159             flags |= MImumInMailboxUtilities::EFlagWaitingToConnect;
       
   160             }                       
       
   161         }
       
   162     
       
   163     return flags;
       
   164     }
       
   165 
       
   166 
       
   167 // ----------------------------------------------------------------------------
       
   168 // CImumMboxScheduler::SecondsToNextMark()
       
   169 // ----------------------------------------------------------------------------
       
   170 //
       
   171 TInt64 CImumMboxScheduler::SecondsToNextMark(
       
   172     TTimeIntervalSeconds& aSeconds )
       
   173     {
       
   174     IMUM_CONTEXT( CImumMboxScheduler::SecondsToNextMark, 0, KLogInApi );
       
   175     
       
   176     // Get hometime
       
   177     aSeconds = 0;   
       
   178     TTime clock;
       
   179     TTimeIntervalSeconds homeTime;
       
   180     TTimeIntervalSeconds startTime;
       
   181     TTimeIntervalSeconds stopTime;
       
   182     PrepareScheduling( clock, homeTime, startTime, stopTime );          
       
   183         
       
   184     // At first it needs to be checked, that either previous or current day
       
   185     // is selected.
       
   186     TValidConnectionDay validDay = GetValidConnectionDay( clock );
       
   187     TBool timeToConnect = ( validDay != ENoConnection );
       
   188     
       
   189     // Next step is to check, is it time for connection or disconnection
       
   190     if ( timeToConnect )
       
   191         {        
       
   192         timeToConnect = IsValidTimeToConnect( 
       
   193             validDay, homeTime, startTime, stopTime );
       
   194         }
       
   195         
       
   196     TInt connectStatus = !timeToConnect ? 
       
   197         MImumInMailboxUtilities::EFlagWaitingToConnect : 0;
       
   198 
       
   199     // Finally calculate the time to next mark       
       
   200     CalculateSecondsToNextMark(
       
   201         connectStatus, aSeconds, clock, homeTime, startTime, stopTime );      
       
   202             
       
   203     return connectStatus | iActive;
       
   204     }
       
   205 
       
   206 /******************************************************************************
       
   207 
       
   208     Private scheduling tools
       
   209 
       
   210 ******************************************************************************/
       
   211 
       
   212 // ----------------------------------------------------------------------------
       
   213 // CImumMboxScheduler::PrepareScheduling()
       
   214 // ----------------------------------------------------------------------------
       
   215 //
       
   216 void CImumMboxScheduler::PrepareScheduling(
       
   217     TTime& aClock,
       
   218     TTimeIntervalSeconds& aHome,
       
   219     TTimeIntervalSeconds& aStart,
       
   220     TTimeIntervalSeconds& aStop )
       
   221     {
       
   222     IMUM_CONTEXT( CImumMboxScheduler::PrepareScheduling, 0, KLogInApi );
       
   223     
       
   224     // Get the hometime and set the day flags    
       
   225     aClock.HomeTime();              
       
   226         
       
   227     // First, all the times has to be converted to seconds, to guarrantee
       
   228     // proper comparisions for the times
       
   229     Times2Seconds( aClock, aHome, aStart, aStop );
       
   230     
       
   231     // Start and stop times needs to be reordered so, that the
       
   232     // start time is before stop time in proportion to hometime
       
   233     OrganizeStartAndStopTimes( aHome, aStart, aStop );
       
   234     }
       
   235     
       
   236 // ----------------------------------------------------------------------------
       
   237 // CImumMboxScheduler::AlwaysOnlineOn()
       
   238 // ----------------------------------------------------------------------------
       
   239 //
       
   240 TBool CImumMboxScheduler::AlwaysOnlineOn(
       
   241     const TTime& aClock,
       
   242     TTimeIntervalSeconds& aHome,
       
   243     TTimeIntervalSeconds& aStart,
       
   244     TTimeIntervalSeconds& aStop )
       
   245     {
       
   246     IMUM_CONTEXT( CImumMboxScheduler::AlwaysOnlineOn, 0, KLogInApi );
       
   247     
       
   248     TValidConnectionDay validDay = GetValidConnectionDay( aClock );
       
   249     TBool result = EFalse;
       
   250     
       
   251     // Connecting can be ok, if either previous or current day are checked
       
   252     if ( validDay != ENoConnection )
       
   253         {
       
   254         
       
   255         result = IsValidTimeToConnect(
       
   256             validDay, aHome, aStart, aStop );
       
   257         }
       
   258 
       
   259     
       
   260     return result;    
       
   261     }
       
   262 
       
   263 // ----------------------------------------------------------------------------
       
   264 // CImumMboxScheduler::GetValidConnectionDay()
       
   265 //
       
   266 // The connection is allowed in following cases:
       
   267 // Day:     Mo Tu We Th Fr Sa Su
       
   268 // Checked: 0  0  0  1  1  0  0
       
   269 // Allowed: F  F  F  T  T  T  F
       
   270 // ----------------------------------------------------------------------------
       
   271 //
       
   272 CImumMboxScheduler::TValidConnectionDay 
       
   273     CImumMboxScheduler::GetValidConnectionDay(
       
   274         const TTime& aClock )
       
   275     {
       
   276     IMUM_CONTEXT( CImumMboxScheduler::TValidConnectionDay, 0, KLogInApi );
       
   277     
       
   278     // Get current and previous day and make sure it is selected
       
   279     TDay currentDay = aClock.DayNoInWeek();
       
   280     TDay previousDay = GetPrevDay( currentDay );
       
   281     TValidConnectionDay result;
       
   282     
       
   283     
       
   284     // Connection can be made anyday
       
   285     if ( iDays.Flag( currentDay ) && iDays.Flag( previousDay ) )
       
   286         {
       
   287         
       
   288         result = EConnectionAnyDay;        
       
   289         }
       
   290     // Connection can be established when start time is at current day
       
   291     else if ( iDays.Flag( currentDay ) )
       
   292         {
       
   293         
       
   294         result = EConnectionCurrentDay;
       
   295         }
       
   296     // Connection can be established, if the connection begins from
       
   297     // checked day
       
   298     else if ( iDays.Flag( previousDay ) )
       
   299         {
       
   300         
       
   301         result = EConnectionPreviousDayOnly;
       
   302         }
       
   303     // Connection is not allowed
       
   304     else
       
   305         {
       
   306         
       
   307         result = ENoConnection;
       
   308         } 
       
   309         
       
   310     return result;           
       
   311     }
       
   312 
       
   313 // ----------------------------------------------------------------------------
       
   314 // CImumMboxScheduler::GetNextDay()
       
   315 // ----------------------------------------------------------------------------
       
   316 //
       
   317 TDay CImumMboxScheduler::GetNextDay(
       
   318     const TDay aToday,
       
   319     const TInt aNth )
       
   320     {
       
   321     IMUM_CONTEXT( CImumMboxScheduler::GetNextDay, 0, KLogInApi );
       
   322     
       
   323     return static_cast<TDay>( ( aToday + aNth ) % KImumDaysInWeek );    
       
   324     }
       
   325 
       
   326 // ----------------------------------------------------------------------------
       
   327 // CImumMboxScheduler::GetPrevDay()
       
   328 // ----------------------------------------------------------------------------
       
   329 //
       
   330 TDay CImumMboxScheduler::GetPrevDay(
       
   331     const TDay aToday,
       
   332     const TInt aNth )
       
   333     {
       
   334     IMUM_CONTEXT( CImumMboxScheduler::GetPrevDay, 0, KLogInApi );
       
   335     
       
   336     TInt weekIncrease = ( ( aNth / KImumDaysInWeek ) + 1 ) * KImumDaysInWeek;
       
   337     return static_cast<TDay>( ( weekIncrease + aToday - aNth ) % KImumDaysInWeek );
       
   338     }
       
   339 
       
   340 // ----------------------------------------------------------------------------
       
   341 // CImumMboxScheduler::IsValidTimeToConnect()
       
   342 // ----------------------------------------------------------------------------
       
   343 //
       
   344 TBool CImumMboxScheduler::IsValidTimeToConnect(
       
   345     const TValidConnectionDay aValidDay,
       
   346     TTimeIntervalSeconds& aHome,
       
   347     TTimeIntervalSeconds& aStart,
       
   348     TTimeIntervalSeconds& aStop )
       
   349     {
       
   350     IMUM_CONTEXT( CImumMboxScheduler::IsValidTimeToConnect, 0, KLogInApi );
       
   351     
       
   352     TBool result = EFalse;
       
   353     
       
   354     // Combine the possible combinations.
       
   355     // Connection in current day is possible, only if the current day or 
       
   356     // all days are selected
       
   357     TBool currentDay = ( aValidDay == EConnectionCurrentDay ||
       
   358                          aValidDay == EConnectionAnyDay );
       
   359     // Connection can extended from previous day, only if previous day is
       
   360     // set or all days are set                         
       
   361     TBool previousDay = ( aValidDay == EConnectionPreviousDayOnly ||
       
   362                           aValidDay == EConnectionAnyDay );
       
   363                          
       
   364     // First it is needed to check that are the times even set
       
   365     // If the times are equal, the times can be considered to be valid for
       
   366     // all the day
       
   367     if ( currentDay && aStart == aStop )
       
   368         {
       
   369         result = ETrue;
       
   370         }
       
   371     // It's allowed to make the connection in following situations homeTime 
       
   372     // is between startTime and stopTime, and the connection is allowed
       
   373     // for the day. The connection is not allowed to be open during 
       
   374     // the last minute (aHome < aStop), but connection should be 
       
   375     // made at the start of the scheduling (aStart <= aHome).
       
   376     else if ( aStart <= aHome && aHome < aStop )
       
   377         {
       
   378         // If connection extends from previous day and only extended connection
       
   379         // is allowed
       
   380         if ( previousDay && aStart.Int() < 0 )
       
   381             {
       
   382             
       
   383             result = ETrue;
       
   384             }
       
   385         // If previous day is not checked and connection extends over day
       
   386         // make sure that the correct time is used
       
   387         else if ( currentDay && aStart.Int() >= 0 )
       
   388             {
       
   389             
       
   390             result = ETrue;
       
   391             }
       
   392         else
       
   393             {
       
   394             
       
   395             result = EFalse;
       
   396             }
       
   397         }
       
   398     // Neither of the statements were fulfilled, do not allow connection
       
   399     else
       
   400         {
       
   401         
       
   402         result = EFalse;
       
   403         }
       
   404 
       
   405     return result;    
       
   406     }
       
   407 
       
   408 // ----------------------------------------------------------------------------
       
   409 // CImumMboxScheduler::AdjustHomeTime()
       
   410 // ----------------------------------------------------------------------------
       
   411 //
       
   412 TDateTime CImumMboxScheduler::AdjustHomeTime(
       
   413     const TTime& aClock )
       
   414     {
       
   415     IMUM_CONTEXT( CImumMboxScheduler::AdjustHomeTime, 0, KLogInApi );
       
   416     
       
   417     // Zero time is the beginning of the day
       
   418     TTime zeroTime( 0 );
       
   419 
       
   420     TDateTime dtHome = aClock.DateTime();
       
   421     TDateTime dtZero = zeroTime.DateTime();
       
   422 
       
   423     dtZero.SetHour( dtHome.Hour() );
       
   424     dtZero.SetMinute( dtHome.Minute() );
       
   425     dtZero.SetSecond( dtHome.Second() );
       
   426     
       
   427     return dtZero;    
       
   428     }
       
   429 
       
   430 // ----------------------------------------------------------------------------
       
   431 // CImumMboxScheduler::Times2Seconds()
       
   432 //
       
   433 // This function converts home-, start- and stop times to secondes from the
       
   434 // beginning of the day
       
   435 // ----------------------------------------------------------------------------
       
   436 //
       
   437 void CImumMboxScheduler::Times2Seconds(
       
   438     const TTime& aClock,
       
   439     TTimeIntervalSeconds& aHome,
       
   440     TTimeIntervalSeconds& aStart,
       
   441     TTimeIntervalSeconds& aStop )
       
   442     {
       
   443     IMUM_CONTEXT( CImumMboxScheduler::Times2Seconds, 0, KLogInApi );
       
   444     
       
   445     
       
   446     TTime zeroTime( 0 );
       
   447     TTime adjustedHomeTime = AdjustHomeTime( aClock );
       
   448     TTime selectedTimeStart( iStartTime );
       
   449     TTime selectedTimeStop( iStopTime );
       
   450     adjustedHomeTime.SecondsFrom( zeroTime, aHome );
       
   451     selectedTimeStart.SecondsFrom( zeroTime, aStart );
       
   452     selectedTimeStop.SecondsFrom( zeroTime, aStop );
       
   453     
       
   454     }
       
   455 
       
   456 // ----------------------------------------------------------------------------
       
   457 // CImumMboxScheduler::OrganizeStartAndStopTimes()
       
   458 // ----------------------------------------------------------------------------
       
   459 //
       
   460 void CImumMboxScheduler::OrganizeStartAndStopTimes(
       
   461     TTimeIntervalSeconds& aHome,
       
   462     TTimeIntervalSeconds& aStart,
       
   463     TTimeIntervalSeconds& aStop )
       
   464     {
       
   465     IMUM_CONTEXT( CImumMboxScheduler::OrganizeStartAndStopTimes, 0, KLogInApi );
       
   466     
       
   467     // The start-, stop- and home times needs to be reordered so that the
       
   468     // start is always before stop, in other words, start time is smaller
       
   469     // than stop time.
       
   470     //
       
   471     // Following cases need to be considered:
       
   472     //     aStart < aStop  (OK) -       aStart > aStop (NOK)
       
   473     // aHome < aStart < aStop       ( aHome < aStop ) < aStart  (start-24h)
       
   474     // aStart < aHome < aStop       aStop < aHome < aStart  (end+24h)
       
   475     // aStart < aStop < aHome       aStop < aStart < aHome  (end+24h)
       
   476     if ( aStart > aStop )
       
   477         {       
       
   478         // If we're between the the start and stop times,
       
   479         // move this
       
   480         if ( aHome < aStop )
       
   481             {
       
   482             // Set starting time to previous day
       
   483             aStart = ( aStart.Int() - KImumSecondsIn24Hours );
       
   484             }
       
   485         else
       
   486             {           
       
   487             // Set ending time to next day
       
   488             aStop = ( aStop.Int() + KImumSecondsIn24Hours );
       
   489             }
       
   490         }
       
   491 
       
   492         
       
   493     }
       
   494 
       
   495 // ----------------------------------------------------------------------------
       
   496 // CImumMboxScheduler::CalculateSecondsToNextMark()
       
   497 // ----------------------------------------------------------------------------
       
   498 //
       
   499 void CImumMboxScheduler::CalculateSecondsToNextMark(
       
   500     TInt64 aConnectionStatus,
       
   501     TTimeIntervalSeconds& aSeconds,
       
   502     const TTime& aClock,
       
   503     const TTimeIntervalSeconds& aHome,
       
   504     const TTimeIntervalSeconds& aStart,
       
   505     const TTimeIntervalSeconds& aStop )
       
   506     {
       
   507     IMUM_CONTEXT( CImumMboxScheduler::CalculateSecondsToNextMark, 0, KLogInApi );
       
   508     
       
   509     // If all day is selected, next stop should be the midnight of the next
       
   510     // (un)scheduled day depending on should the connection be on or off
       
   511     if ( aStart == aStop )
       
   512         {
       
   513                 
       
   514         aSeconds = CalcSecsToNextScheduledDay(
       
   515             aClock, aHome, 
       
   516             aConnectionStatus == MImumInMailboxUtilities::EFlagWaitingToConnect );
       
   517         
       
   518         }
       
   519     // To calculate seconds, it needs to checked, should the connection be now
       
   520     // on or off. If between, the connection should be on and seconds should
       
   521     // be calculated to next disconnect time
       
   522     else if ( aConnectionStatus != MImumInMailboxUtilities::EFlagWaitingToConnect )
       
   523         {
       
   524         
       
   525         CalcSecsToMark( aSeconds, aClock, aHome, aStop, EFalse );
       
   526         
       
   527         }
       
   528     //
       
   529     else
       
   530         {
       
   531         
       
   532         CalcSecsToMark( aSeconds, aClock, aHome, aStart, ETrue );
       
   533 
       
   534         }
       
   535 
       
   536     }
       
   537 
       
   538 // ----------------------------------------------------------------------------
       
   539 // CImumMboxScheduler::CalcSecsToMark()
       
   540 // ----------------------------------------------------------------------------
       
   541 //
       
   542 void CImumMboxScheduler::CalcSecsToMark(
       
   543     TTimeIntervalSeconds& aSeconds,
       
   544     const TTime& aClock,
       
   545     const TTimeIntervalSeconds& aHome,
       
   546     const TTimeIntervalSeconds& aBonus,
       
   547     const TBool aScheduledDay )
       
   548     {
       
   549     IMUM_CONTEXT( CImumMboxScheduler::CalcSecsToMark, 0, KLogInApi );
       
   550       
       
   551     // If extending to next day, calculate seconds to next day
       
   552     if ( aHome > aBonus )
       
   553         {            
       
   554         aSeconds = CalcSecsToNextScheduledDay( aClock, aHome, aScheduledDay );
       
   555         aSeconds = aSeconds.Int() + aBonus.Int();
       
   556         }
       
   557     else
       
   558         {
       
   559         aSeconds = aBonus.Int() - aHome.Int();            
       
   560         }
       
   561     }
       
   562     
       
   563 // ----------------------------------------------------------------------------
       
   564 // CImumMboxScheduler::CalcSecsToNextScheduledDay()
       
   565 // ----------------------------------------------------------------------------
       
   566 //
       
   567 TTimeIntervalSeconds CImumMboxScheduler::CalcSecsToNextScheduledDay(
       
   568     const TTime& aClock,
       
   569     const TTimeIntervalSeconds& aHome,
       
   570     const TBool aScheduledDay )
       
   571     {
       
   572     IMUM_CONTEXT( CImumMboxScheduler::CalcSecsToNextScheduledDay, 0, KLogInApi );
       
   573     
       
   574     TTimeIntervalSeconds seconds = 0;
       
   575     TBool hit = EFalse;
       
   576     TDay today = aClock.DayNoInWeek();
       
   577     TDay dayAfter = GetNextDay( today );
       
   578     TInt dayCount = KErrNotFound;
       
   579     
       
   580     while ( dayAfter != today && !hit )
       
   581         {
       
   582         dayCount++;
       
   583         hit = ( iDays.Flag( dayAfter ) == aScheduledDay );
       
   584         dayAfter = GetNextDay( dayAfter );
       
   585         }
       
   586 
       
   587     
       
   588     seconds = KImumSecondsIn24Hours - aHome.Int() +
       
   589         dayCount * KImumSecondsIn24Hours;
       
   590 
       
   591     
       
   592     return seconds;       
       
   593     }
       
   594 
       
   595 // End of File
       
   596