I have a series of ranges with start dates and end dates. I want to check to see if a date is within that range.
Date.before() and Date.after() seem to be a little a
Java 8NOTE: All, but one, Date's constructors are deprecated. Most of the Date's methods are deprecated. REF: Date: Deprecated Methods. All, but Date::from(Instant), static methods are deprecated.
So, since java 8 consider using Instant (immutable, thread-safe, leap-seconds aware) type rather than Date. REF: Instant
static final LocalTime MARKETS_OPEN = LocalTime.of(07, 00);
static final LocalTime MARKETS_CLOSE = LocalTime.of(20, 00);
// Instant utcTime = testDate.toInstant();
var bigAppleTime = ZonedDateTime.ofInstant(utcTime, ZoneId.of("America/New_York"));
return !bigAppleTime.toLocalTime().isBefore(MARKETS_OPEN)
&& !bigAppleTime.toLocalTime().isAfter(MARKETS_CLOSE);
return bigAppleTime.toLocalTime().isAfter(MARKETS_OPEN)
&& bigAppleTime.toLocalTime().isBefore(MARKETS_CLOSE);