public class BusinessHours extends Object
The business hours are specified as a string which adheres to the format:
sub-period[, sub-period...]If the period is blank, then the business supposed to be always open.
scale {range [range ...]} [scale {range [range ...]}] Scale must
be one of three different scales (or their equivalent codes):
| Scale | Scale code | Valid range values |
|---|---|---|
| wday | wd | 1 (Monday) to 7 (Sunday) or mo, tu, we, th, fr, sa, su |
| hour | hr | 0-23 or 12am 1am-11am 12noon 12pm 1pm-11pm |
| minute | min | 0-59 |
v or v-v.
v-v, if the second value is larger
than the first value, the range wraps around.
v isn't a point in time. In the context of the hour scale, 9
specifies the time period from 9:00 am to 9:59. This is what most people
would call 9-10.
Note that whitespaces can be anywhere. Furthermore, when using letters to
specify week days, only the first two are significant and the case is not
important: Sunday or Sun are valid specifications
for su.
wd {Mon-Fri} hr {9am-4pm}
To specify business hours that go from Monday through Friday, 9am to 5pm on
Monday, Wednesday, and Friday, and 9am to 3pm on Tuesday and Thursday, use a
period such as:
wd {Mon Wed Fri} hr {9am-4pm}, wd{Tue Thu} hr {9am-2pm}
To specify business hours open every other half-hour, use something like:
minute { 0-29 }
To specify the morning, use:
hour { 12am-11am }
Remember, 11am is not 11:00am, but rather 11:00am - 11:59am.| Constructor and Description |
|---|
BusinessHours(String stringValue)
Build a new instance of BusinessHours from its string representation.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj)
Tells if these business hours are equals to the given ones.
|
Set<String> |
getClosingCrons()
Get a set of crons corresponding to each closing.
|
Set<String> |
getOpeningCrons()
Get a set of crons corresponding to each opening.
|
int |
hashCode()
Returns a hash code for this BusinessHours.
|
boolean |
isOpen(Temporal temporal)
Tells if the business is open at the given time.
|
long |
timeBeforeOpening(Temporal temporal,
ChronoUnit unit)
Get the time between the given temporal and the next business opening.
|
String |
toString()
Return a string representation of this BusinessHours instance.
|
public BusinessHours(String stringValue)
stringValue - the string representation of the business hours. See
the class level Javadoc for more info on valid formats.public boolean isOpen(Temporal temporal)
temporal - the time when we want to know if the business is open or
closed.public long timeBeforeOpening(Temporal temporal, ChronoUnit unit)
temporal - the temporal from which to compute the time before next
openingunit - the unit in which the result must be statedpublic Set<String> getOpeningCrons()
public Set<String> getClosingCrons()
public int hashCode()
public boolean equals(Object obj)
Business hours are equals if they are open at exactly the same instants (regardless of the string representation used to build them).
Copyright © 2017. All rights reserved.