Примерно так должно работать:
public boolean isNewDay( current:Date, past:Date ):Boolean
{
// check the days of the month first
if( current.date != past.date )
return true;
// check the months in case they came back on the same day of the next month
if( current.month != past.month )
return true;
// finally check the year, in case they came back on the same day the next year
if( current.fullYear != past.fullYear )
return true;
return false;
}
даже если вы приняли ответ, вот функция обновления:
public function getNumberOfDays( current:Date, past:Date ):int
{
// get the number of millis between the two dates
var millis:Number = current.time - past.time;
// a day in millis is 1000 (s) * 60 (m) * 60 (h) * 24 (day)
var day:Number = 1000 * 60 * 60 * 24;
// get the number of days
var numDays:int = int( millis / day );
// create midnight of the current day
if ( numDays == 0 )
{
// if our numDays is 0, check if the current date is after midnight and the
// previous date was before midnight the previous day, in which case, count
// it as another day
var midnight:Date = new Date( current.fullYear, current.month, current.date );
if ( current.time > midnight.time && past.time < midnight.time )
numDays++;
}
return numDays;
}
Работает со всеми тестами, которые я пробовал (от полуночи до 23,59,59 = 0 дней, от 23,59 до 00,05 = 1 день)