Skip to content

Instantly share code, notes, and snippets.

@kevinpet
Created November 12, 2012 17:37
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 kevinpet/4060738 to your computer and use it in GitHub Desktop.
Save kevinpet/4060738 to your computer and use it in GitHub Desktop.
Extract from Market showing holidays
@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