Skip to content

Instantly share code, notes, and snippets.

@sassembla
Created January 18, 2013 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sassembla/4564980 to your computer and use it in GitHub Desktop.
Save sassembla/4564980 to your computer and use it in GitHub Desktop.
TimeAssert
trait TimeAssert {
val SecUnit = 1000
def timeAssert(timestamp: String, message: String, delaySec: Int = 0) = {
val timestampDate = new SimpleDateFormat("MM/dd/yy HH:mm:ss").parse(timestamp)
val limit = timestampDate.getTime + delaySec * SecUnit
val currentDate = new Date
val currentDateTime = currentDate.getTime
val distance = (limit - currentDateTime)
assert(0 < distance, "TimeAssert BOMB:" + message + " /" + distance / SecUnit + " sec over")
println("TimeAssert passed:" + message + " /" + distance / SecUnit + " sec left")
}
}
@sassembla
Copy link
Author

usage:
timeAssert("01/18/13 23:55:36", "fix here, me.", 60)

will BOMB 01/18/13 23:56:36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment