Skip to content

Instantly share code, notes, and snippets.

@greyaperez
Last active April 21, 2023 08:42

Revisions

  1. @timperez timperez revised this gist Mar 14, 2014. 1 changed file with 73 additions and 72 deletions.
    145 changes: 73 additions & 72 deletions isBusinessDay.java
    Original file line number Diff line number Diff line change
    @@ -1,72 +1,73 @@
    /**
    * Is Date A Business Day?
    * @param cal
    * @return boolean
    */
    public boolean isBusinessDay(Calendar cal){
    // check if weekend
    if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY){
    return false;
    }

    // check if New Year's Day
    if (cal.get(Calendar.MONTH) == Calendar.JANUARY
    && cal.get(Calendar.DAY_OF_MONTH) == 1) {
    return false;
    }

    // check if Christmas
    if (cal.get(Calendar.MONTH) == Calendar.DECEMBER
    && cal.get(Calendar.DAY_OF_MONTH) == 25) {
    return false;
    }

    // check if 4th of July
    if (cal.get(Calendar.MONTH) == Calendar.JULY
    && cal.get(Calendar.DAY_OF_MONTH) == 4) {
    return false;
    }

    // check Thanksgiving (4th Thursday of November)
    if (cal.get(Calendar.MONTH) == Calendar.NOVEMBER
    && cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 4
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY) {
    return false;
    }

    // check Memorial Day (last Monday of May)
    if (cal.get(Calendar.MONTH) == Calendar.MAY
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY
    && cal.get(Calendar.DAY_OF_MONTH) > (31 - 7) ) {
    return false;
    }

    // check Labor Day (1st Monday of September)
    if (cal.get(Calendar.MONTH) == Calendar.SEPTEMBER
    && cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 1
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
    return false;
    }

    // check President's Day (3rd Monday of February)
    if (cal.get(Calendar.MONTH) == Calendar.FEBRUARY
    && cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 3
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
    return true;
    }

    // check Veterans Day (November 11)
    if (cal.get(Calendar.MONTH) == Calendar.NOVEMBER
    && cal.get(Calendar.DAY_OF_MONTH) == 11) {
    return true;
    }

    // check MLK Day (3rd Monday of January)
    if (cal.get(Calendar.MONTH) == Calendar.JANUARY
    && cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 3
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
    return true;
    }
    // IF NOTHING ELSE, IT'S A BUSINESS DAY
    return true;
    }
    /**
    * Is Date A Business Day?
    * @param cal
    * @return boolean
    */
    public boolean isBusinessDay(Calendar cal){
    // check if weekend
    if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY){
    return false;
    }

    // check if New Year's Day
    if (cal.get(Calendar.MONTH) == Calendar.JANUARY
    && cal.get(Calendar.DAY_OF_MONTH) == 1) {
    return false;
    }

    // check if Christmas
    if (cal.get(Calendar.MONTH) == Calendar.DECEMBER
    && cal.get(Calendar.DAY_OF_MONTH) == 25) {
    return false;
    }

    // check if 4th of July
    if (cal.get(Calendar.MONTH) == Calendar.JULY
    && cal.get(Calendar.DAY_OF_MONTH) == 4) {
    return false;
    }

    // check Thanksgiving (4th Thursday of November)
    if (cal.get(Calendar.MONTH) == Calendar.NOVEMBER
    && cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 4
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY) {
    return false;
    }

    // check Memorial Day (last Monday of May)
    if (cal.get(Calendar.MONTH) == Calendar.MAY
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY
    && cal.get(Calendar.DAY_OF_MONTH) > (31 - 7) ) {
    return false;
    }

    // check Labor Day (1st Monday of September)
    if (cal.get(Calendar.MONTH) == Calendar.SEPTEMBER
    && cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 1
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
    return false;
    }

    // check President's Day (3rd Monday of February)
    if (cal.get(Calendar.MONTH) == Calendar.FEBRUARY
    && cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 3
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
    return true;
    }

    // check Veterans Day (November 11)
    if (cal.get(Calendar.MONTH) == Calendar.NOVEMBER
    && cal.get(Calendar.DAY_OF_MONTH) == 11) {
    return true;
    }

    // check MLK Day (3rd Monday of January)
    if (cal.get(Calendar.MONTH) == Calendar.JANUARY
    && cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 3
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
    return true;
    }

    // IF NOTHING ELSE, IT'S A BUSINESS DAY
    return true;
    }
  2. @timperez timperez revised this gist Mar 14, 2014. 1 changed file with 19 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions isBusinessDay.java
    Original file line number Diff line number Diff line change
    @@ -47,7 +47,26 @@ public boolean isBusinessDay(Calendar cal){
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
    return false;
    }

    // check President's Day (3rd Monday of February)
    if (cal.get(Calendar.MONTH) == Calendar.FEBRUARY
    && cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 3
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
    return true;
    }

    // check Veterans Day (November 11)
    if (cal.get(Calendar.MONTH) == Calendar.NOVEMBER
    && cal.get(Calendar.DAY_OF_MONTH) == 11) {
    return true;
    }

    // check MLK Day (3rd Monday of January)
    if (cal.get(Calendar.MONTH) == Calendar.JANUARY
    && cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 3
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
    return true;
    }
    // IF NOTHING ELSE, IT'S A BUSINESS DAY
    return true;
    }
  3. @timperez timperez created this gist Mar 14, 2014.
    53 changes: 53 additions & 0 deletions isBusinessDay.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    /**
    * Is Date A Business Day?
    * @param cal
    * @return boolean
    */
    public boolean isBusinessDay(Calendar cal){
    // check if weekend
    if(cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY){
    return false;
    }

    // check if New Year's Day
    if (cal.get(Calendar.MONTH) == Calendar.JANUARY
    && cal.get(Calendar.DAY_OF_MONTH) == 1) {
    return false;
    }

    // check if Christmas
    if (cal.get(Calendar.MONTH) == Calendar.DECEMBER
    && cal.get(Calendar.DAY_OF_MONTH) == 25) {
    return false;
    }

    // check if 4th of July
    if (cal.get(Calendar.MONTH) == Calendar.JULY
    && cal.get(Calendar.DAY_OF_MONTH) == 4) {
    return false;
    }

    // check Thanksgiving (4th Thursday of November)
    if (cal.get(Calendar.MONTH) == Calendar.NOVEMBER
    && cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 4
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY) {
    return false;
    }

    // check Memorial Day (last Monday of May)
    if (cal.get(Calendar.MONTH) == Calendar.MAY
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY
    && cal.get(Calendar.DAY_OF_MONTH) > (31 - 7) ) {
    return false;
    }

    // check Labor Day (1st Monday of September)
    if (cal.get(Calendar.MONTH) == Calendar.SEPTEMBER
    && cal.get(Calendar.DAY_OF_WEEK_IN_MONTH) == 1
    && cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY) {
    return false;
    }

    // IF NOTHING ELSE, IT'S A BUSINESS DAY
    return true;
    }