Logo Search packages:      
Sourcecode: pcalendar version File versions  Download package

static int net::sf::linuxorg::pcal::engine::Engine::dateDiff ( java.util.Date  earlier,
java.util.Date  later 
) [inline, static]

the difference in days between 2 dates within the Gregorian calendar - after 1582

Parameters:
earlierthe start date
laterthe end date
Returns:
number of days

Definition at line 1400 of file Engine.java.

Referenced by checkForFutureOvulation(), getDayInfoEstimated(), getDayInfoRecorded(), getMensPeriodEndDate(), getMensPeriodOvulationDate(), getOvulationDayInfo(), getPeriodStartDate(), recalculate(), net::sf::linuxorg::pcal::MainWindow::refreshCalendar(), and net::sf::linuxorg::pcal::engine::EngineTest::testDateDiff().

                                                                                 {
            java.util.GregorianCalendar start = new
            java.util.GregorianCalendar();
            java.util.GregorianCalendar finish = new
            java.util.GregorianCalendar();
            if (later.compareTo( earlier ) > 0 ) { // this Date is after the Date argument
                  start.setTime(later);
                  finish.setTime(earlier);
            } else 
                  if (later.compareTo( earlier ) < 0 ) { // this Date is      before the Date argument
                        start.setTime(earlier);
                        finish.setTime(later);
                  } else {
                        return 0; // must be the same date
                  }
            int days = 1;
            //if dates in the same year
            if ( start.get(Calendar.YEAR) == finish.get(Calendar.YEAR) ) {
                  days = start.get(Calendar.DAY_OF_YEAR) -
                  finish.get(Calendar.DAY_OF_YEAR);
            } else {
                  days = start.get(Calendar.DAY_OF_YEAR); // number of days in the current year
                  while ( start.get(Calendar.YEAR) - 1 > finish.get(Calendar.YEAR)
                  ) {
                        start.add(Calendar.YEAR, -1); // keep counting back till they are the same year
                        days += 365;
                        if ( start.isLeapYear(start.get(Calendar.YEAR) ) ) {
                              days++;
                        }
                  }
                  start.add(Calendar.YEAR, -1); // get the days in the last year
                  days += 365 - finish.get(Calendar.DAY_OF_YEAR);
                  if ( start.isLeapYear(start.get(Calendar.YEAR) ) )
                        days++;
            }
            return days;
      }

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index