calendarui/commonutils/src/calendateutils.cpp
changeset 45 b6db4fd4947b
parent 18 c198609911f9
child 55 2c54b51f39c4
equal deleted inserted replaced
23:fd30d51f876b 45:b6db4fd4947b
   118 // ?classname::?member_function
   118 // ?classname::?member_function
   119 // ?implementation_description
   119 // ?implementation_description
   120 // (other items were commented in a header).
   120 // (other items were commented in a header).
   121 // -----------------------------------------------------------------------------
   121 // -----------------------------------------------------------------------------
   122 //
   122 //
   123  bool CalenDateUtils::isNullTime( QDateTime& time )
       
   124     {
       
   125     return( time.isNull() );
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // ?classname::?member_function
       
   130 // ?implementation_description
       
   131 // (other items were commented in a header).
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134  QDateTime CalenDateUtils::limitToValidTime( const QDateTime& time )
   123  QDateTime CalenDateUtils::limitToValidTime( const QDateTime& time )
   135     {    
   124     {    
   136     QDateTime valid = time;
   125     QDateTime valid = time;
   137     valid = valid > maxTime() ? maxTime() : valid;
   126     valid = valid > maxTime() ? maxTime() : valid;
   138     valid = valid < minTime() ? minTime() : valid;
   127     valid = valid < minTime() ? minTime() : valid;
   167 // (other items were commented in a header).
   156 // (other items were commented in a header).
   168 // -----------------------------------------------------------------------------
   157 // -----------------------------------------------------------------------------
   169 //
   158 //
   170  int CalenDateUtils::timeOfDay( const QDateTime& dateTime )
   159  int CalenDateUtils::timeOfDay( const QDateTime& dateTime )
   171     {    
   160     {    
   172     QDateTime midnight = CalenDateUtils::beginningOfDay( dateTime );
   161     QDateTime midnight = beginningOfDay( dateTime );
   173     int resultInSec = midnight.secsTo(dateTime);
   162     int resultInSec = midnight.secsTo(dateTime);
   174     
   163     
   175     return (resultInSec/60);
   164     return (resultInSec/60);
   176     }
   165     }
   177 
   166 
   199 // (other items were commented in a header).
   188 // (other items were commented in a header).
   200 // -----------------------------------------------------------------------------
   189 // -----------------------------------------------------------------------------
   201 //
   190 //
   202  QDateTime CalenDateUtils::now()
   191  QDateTime CalenDateUtils::now()
   203     {
   192     {
   204     TTime currentTime;
   193     return QDateTime::currentDateTime();
   205     currentTime.HomeTime();
       
   206     TDateTime curDateTime = currentTime.DateTime();
       
   207     QDateTime ret;
       
   208     ret.setDate(QDate(curDateTime.Year(), curDateTime.Month() + 1, curDateTime.Day() + 1));
       
   209     ret.setTime(QTime(curDateTime.Hour(), curDateTime.Minute(), curDateTime.Second(), curDateTime.MicroSecond()));
       
   210     // TODO: need to use QDateTime::currentDateTime() from QT4.6 onwards
       
   211     //return QDateTime::currentDateTime();
       
   212     return ret;
       
   213     }
   194     }
   214 
   195 
   215 // -----------------------------------------------------------------------------
   196 // -----------------------------------------------------------------------------
   216 // (other items were commented in a header).
   197 // (other items were commented in a header).
   217 // -----------------------------------------------------------------------------
   198 // -----------------------------------------------------------------------------
   244     dateTime.setTime(time); // DD:MM:YY @ 08:00 am
   225     dateTime.setTime(time); // DD:MM:YY @ 08:00 am
   245   
   226   
   246     return dateTime;
   227     return dateTime;
   247     }      
   228     }      
   248 
   229 
   249  // -----------------------------------------------------------------------------
       
   250  // (other items were commented in a header).
       
   251  // -----------------------------------------------------------------------------
       
   252  //
       
   253  QDateTime CalenDateUtils::pastOf(const QDateTime& dateTime, int numOfDays)
       
   254      {
       
   255      QDateTime result;
       
   256      int dayNumber = dateTime.date().day();
       
   257       int numOfDaysInMonth = dayNumber;
       
   258       int month = dateTime.date().month();
       
   259       int year = dateTime.date().year();
       
   260       int buff = numOfDays;
       
   261       QDate date(year, month, dayNumber);
       
   262       while(buff > numOfDaysInMonth)
       
   263           {
       
   264           if(month == 1) {
       
   265           // If January,
       
   266           month = 12; // December
       
   267           year--;
       
   268           }
       
   269           else {
       
   270           month--;
       
   271           }
       
   272           // Create the qdate with these details
       
   273           date.setDate(year, month, 1);
       
   274           // check to see if it goes beyond the next month also
       
   275           buff = buff - numOfDaysInMonth;
       
   276           numOfDaysInMonth = date.daysInMonth();
       
   277           }
       
   278       
       
   279       // Substract buff days from end of the month
       
   280       int day = numOfDaysInMonth - buff;
       
   281       date.setYMD(date.year(), date.month(), day);
       
   282       result.setDate(date);
       
   283       result.setTime(dateTime.time());
       
   284       return result;
       
   285      }
       
   286  
       
   287  // -----------------------------------------------------------------------------
   230  // -----------------------------------------------------------------------------
   288  // (other items were commented in a header).
   231  // (other items were commented in a header).
   289  // -----------------------------------------------------------------------------
   232  // -----------------------------------------------------------------------------
   290  //
   233  //
   291  QDateTime CalenDateUtils::futureOf(const QDateTime& dateTime, int numOfDays)
   234  QDateTime CalenDateUtils::futureOf(const QDateTime& dateTime, int numOfDays)