Last active
May 4, 2017 16:31
-
-
Save ahcode0919/02d83bd43df17d450556a0cacf93a142 to your computer and use it in GitHub Desktop.
Collection of Date/Time helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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