//Change to the next phase and update numShortBreaks, and optionally vibrate. DOES NOT WRITE STATE CHANGE TO STORAGE!
exports.nextPhase=function(vibrate){
a={
startTime:0,//When the timer was last started. Difference between this and now is how long timer has run continuously.
pausedTime:0,//When the timer was last paused. Used for expiration and displaying timer while paused.
elapsedTime:0,//How much time the timer had spent running before the current start time. Update on pause or user skipping stages.
phase:exports.PHASE_WORKING,//What phase the timer is currently in
numShortBreaks:0//Number of short breaks that have occured so far
}
letnow=(newDate()).getTime();
exports.state.startTime=now;//The timer is being reset, so say it starts now.
exports.state.pausedTime=now;//This prevents a paused timer from having the start time moved to the future and therefore having been run for negative time.
exports.state.elapsedTime=0;//Because we are resetting the timer, we no longer need to care about whether it was paused previously.
letoldPhase=exports.state.phase;//Cache the old phase because we need to remember it when counting the number of short breaks
exports.state.phase=exports.getNextPhase();
if(oldPhase==exports.PHASE_SHORT_BREAK){
//If we just left a short break, increase the number of short breaks
exports.state.numShortBreaks++;
}elseif(oldPhase==exports.PHASE_LONG_BREAK){
//If we just left a long break, set the number of short breaks to zero