define elapsedDays(time) ( time / SECS_PER_DAY) // this is number of days since Jan 1 1970
define elapsedSecsToday(time) (time % SECS_PER_DAY) // the number of seconds since last midnight
// The following macros are used in calculating alarms and assume the clock is set to a date later than Jan 1 1971
// Always set the correct time before settting alarms
define previousMidnight(time) (( time / SECS_PER_DAY) * SECS_PER_DAY) // time at the start of the given day
define nextMidnight(time) ( previousMidnight(time) + SECS_PER_DAY ) // time at the end of the given day
define elapsedSecsThisWeek(time) (elapsedSecsToday(time) + ((dayOfWeek(time)-1) * SECS_PER_DAY) ) // note that week starts on day 1
define previousSunday(time) (time - elapsedSecsThisWeek(time)) // time at the start of the week for the given time
define nextSunday(time) ( previousSunday(time)+SECS_PER_WEEK) // time at the end of the week for the given time
This macros need in parentheses around time:
/ Useful Macros for getting elapsed time /
define numberOfSeconds(time) (time % SECS_PER_MIN)
define numberOfMinutes(time) ((time / SECS_PER_MIN) % SECS_PER_MIN)
define numberOfHours(time) (( time% SECS_PER_DAY) / SECS_PER_HOUR)
define dayOfWeek(time) ((( time / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday
define elapsedDays(time) ( time / SECS_PER_DAY) // this is number of days since Jan 1 1970
define elapsedSecsToday(time) (time % SECS_PER_DAY) // the number of seconds since last midnight
// The following macros are used in calculating alarms and assume the clock is set to a date later than Jan 1 1971 // Always set the correct time before settting alarms
define previousMidnight(time) (( time / SECS_PER_DAY) * SECS_PER_DAY) // time at the start of the given day
define nextMidnight(time) ( previousMidnight(time) + SECS_PER_DAY ) // time at the end of the given day
define elapsedSecsThisWeek(time) (elapsedSecsToday(time) + ((dayOfWeek(time)-1) * SECS_PER_DAY) ) // note that week starts on day 1
define previousSunday(time) (time - elapsedSecsThisWeek(time)) // time at the start of the week for the given time
define nextSunday(time) ( previousSunday(time)+SECS_PER_WEEK) // time at the end of the week for the given time