Created
November 12, 2012 17:37
-
-
Save kevinpet/4060738 to your computer and use it in GitHub Desktop.
Extract from Market showing holidays
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
@Singleton | |
public class Market { | |
final static Set<LocalDate> HOLIDAYS = ImmutableSet.of( | |
// ... | |
new LocalDate(2012, 1, 2), // New Years | |
new LocalDate(2012, 1, 16), // MLK | |
new LocalDate(2012, 2, 20), // Washington's Birthday | |
new LocalDate(2012, 4, 6), // Good Friday | |
new LocalDate(2012, 5, 28), // Memorial Day | |
new LocalDate(2012, 7, 4), // Independence Day | |
new LocalDate(2012, 9, 3), // Labor Day | |
new LocalDate(2012, 11, 22), // Thanksgiving | |
new LocalDate(2012, 12, 25) // Christmas | |
); | |
private final static Set<LocalDate> EARLY_CLOSE_DATES = ImmutableSet.of( | |
// 2012 | |
new LocalDate(2012, 7, 3), // Day Before Independence Day | |
new LocalDate(2012, 11, 23), // Day After Thanksgiving | |
new LocalDate(2012, 12, 24) // Christmas Eve | |
); | |
/** | |
* Returns whether the market is open at {@code t}. | |
*/ | |
public boolean isOpen(DateTime t) { | |
t = t.toDateTime(ET); | |
// closed weekends and holidays | |
if (SATURDAY <= t.getDayOfWeek() || isHoliday(t)) { | |
return false; | |
} | |
return !(t.isBefore(openingTime(t)) || t.isAfter(closingTime(t))); | |
} | |
// ... other varieties of is/was the market open / when will the market open | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment