Results 1 to 1 of 1
- 05-12-2013, 03:37 AM #1Member
- Join Date
- Feb 2012
- Rep Power
Checking is parsed time has passed since last check
In my system, a trigger time is given, but units after a certain point are ignored when matching. Ex:
Trigger (mm-ss): 10-15
With this trigger, the time will be matched every year, month, day, and hour when the time is at 10 minutes and 15 seconds.
Since the match check occurs at an unknown interval, the system needs to check if the time would have matched since the last check() call. This is done like this:
1. Create new current date
2. Check if the trigger date is after the previous check, and before the current time
3. Update previous check date
All dates are parsed using SimpleDateFormat, which will give default values for undefined times. For example, (mm-ss): "10-15" will result in "Thu Jan 01 00:10:15 PST 197"
The problem occurs when a trigger has a unit of time that is close to 0. Here is what happens when the trigger *should* occur:
Trigger: Thu Jan 01 00:00:00 PST 1970
Previous: Thu Jan 01 00:00:58 PST 1970
Current: Thu Jan 01 00:00:03 PST 1970
As you can see, the previous time wraps around, causing it to come after the trigger, instead of before.
Here is the full code: https://gist.github.com/Sprakle/5561925
I've been stumped for a while, so any input is appreciated.
- By DGates in forum New To JavaReplies: 2Last Post: 01-26-2012, 02:07 AM
- By veronique in forum New To JavaReplies: 10Last Post: 04-27-2011, 06:36 AM
- By jojo in forum New To JavaReplies: 16Last Post: 04-20-2011, 04:35 PM
- By syntrax in forum New To JavaReplies: 1Last Post: 12-17-2009, 08:13 AM