I have an interval that runs every 3 seconds to check for new data. If it finds new data it broadcasts a dataChange event and my item renderer is updated.
I need to test a comparison for when two times match exactly…for one time only. Meaning, the data comes back is a meeting. The meeting starts at 3pm. When the match is run, the meeting turns blue and users can enter.
I broadcast a dataChange event for when the compared times match but I don’t want to keep broadcasting it over and over, i.e.
private static const NOW_OFFSET_TIME:Number = 1000 * 60 * 15;
private function shouldShowNow(start:Date, end:Date):Boolean
{
var now:Date = new Date;
var stime:Number = start.time - NOW_OFFSET_TIME;
var etime:Number = end.time;
return ((now.time >= stime) && (now.time <= etime));
}
In the code above, the condition will always return true once
now.time >= stime
…and the dataChange event gets run over and over and over.
But my interval runs only 3 seconds so it won’t trap an exact match. Heck, I even switched my interval to every 500 ms and it won’t trap it.
What are my other options?
Thanks for any helpful input.
UPDATE: I could do this (but I’d have to run my interval every second):
private static const NOW_OFFSET_TIME:Number = 1000 * 60 * 15;
private function shouldShowNow(start:Date, end:Date):Boolean
{
var now:Date = new Date;
var match:Boolean;
if( now.hours == start.hours && now.minutes == ( start.minutes - 15 ) && now.seconds == start.seconds ){
match = true;
}else{
match = false;
}
return match;
}
And here is the handler for the interval in full:
/*
We want to compare the current upcomingCalendarList collection
against the collection returned; if they are different, update the UI.
*/
var meetingsData:ArrayCollection = new ArrayCollection();
meetingsData = getArrayCollectionFromXML( event.result.response.participantMeetingList.meeting );
var cachedColl:ArrayCollection = com.fmr.transporter.model.GeneralInfoModel.getInstance().upcomingMeetingList;
var returnedColl:ArrayCollection = meetingsData;
var updates:Boolean = false; // our flag to let us know if there are changes in the meeting list
if( returnedColl != null )
{
// Meetings have been added/removed
if( cachedColl.length != returnedColl.length ){
updates = true;
}
// Look for meeting updates
else
{
for( var i:int=0;i<cachedColl.length;i++ ){
var currMeeting:MeetingVO = cachedColl[i] as MeetingVO;
for( var j:int=0;j<returnedColl.length;j++ ){
var returnedMtg:ObjectProxy = returnedColl[j];
/*
We want to ensure we're comparing the same meeting (meetingID) for
any changes.
*/
if( currMeeting.meetingID == returnedMtg.meetingId )
{
var startTime_GMT:Date = converServerUTCTimeStampToLocalDate( returnedMtg.startTime );
var endTime_GMT:Date = converServerUTCTimeStampToLocalDate( returnedMtg.endTime );
if( ObjectUtil.dateCompare( currMeeting.startTime, startTime_GMT ) != 0 )
updates = true;
else if( ObjectUtil.dateCompare( currMeeting.endTime, endTime_GMT ) != 0 )
updates = true;
else if( currMeeting.meetingName != returnedMtg.meetingName )
updates = true;
else if( this.shouldShowNow( startTime_GMT, endTime_GMT ) )
updates = true;
}
}
}
}
// If there are no updates, leave the cached collections alone.
if( !updates ){
return;
}
}
It looks like it would be best for you to add a property to your MeetingVO class to track whether you’ve shown it already. something like
public var hasBeenShown:Boolean = falseThen, in you else if where you call shouldShowNow, update it to this:
Then in your shouldshowNow function, update it to this: