Skip to content

Instantly share code, notes, and snippets.

@ahcode0919
Last active May 4, 2017 16:31
Show Gist options
  • Save ahcode0919/02d83bd43df17d450556a0cacf93a142 to your computer and use it in GitHub Desktop.
Save ahcode0919/02d83bd43df17d450556a0cacf93a142 to your computer and use it in GitHub Desktop.
Collection of Date/Time helpers
static boolean isBetween(String start, String end) {
def sdf = new SimpleDateFormat("HH:mm")
def startCalendar = Calendar.getInstance()
startCalendar.setTime(sdf.parse(start))
def endCalendar = Calendar.getInstance()
endCalendar.setTime(sdf.parse(end))
def currentCalendar = Calendar.getInstance()
currentCalendar.setTime(sdf.parse(sdf.format(new Date())))
return currentCalendar.after(startCalendar) && currentCalendar.before(endCalendar)
}
static boolean isWeekday() {
int dayOfTheWeek = Calendar.getInstance().get(Calendar.DAY_OF_WEEK)
return dayOfTheWeek != Calendar.SATURDAY && dayOfTheWeek != Calendar.SUNDAY
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment