pub struct Context<L = NoLocation> {
pub holidays: ContextHolidays,
pub holidays_unknown: ContextHolidays,
pub locale: L,
pub approx_bound_interval_size: Option<TimeDelta>,
}Expand description
All the context attached to a parsed OpeningHours expression and that can alter its evaluation semantics.
Fields§
§holidays: ContextHolidaysA calendar use for evaluation of public and private holidays.
holidays_unknown: ContextHolidaysA calendar of holidays where it is unknown whether it applies to current location or not. Typicaly, this can include regional holidays in a countext where only the country is known.
locale: LSpecify locality of the place attached to the expression: from timezone to coordinates.
approx_bound_interval_size: Option<TimeDelta>As an approximation, consider that any interval bigger that this size is infinite. This can be enabled if you need better performance and you don’t care if a shop is open in more than a year.
Implementations§
Source§impl<L> Context<L>
impl<L> Context<L>
Sourcepub fn with_holidays(self, holidays: ContextHolidays) -> Self
pub fn with_holidays(self, holidays: ContextHolidays) -> Self
Attach a new holidays component to this context.
Sourcepub fn with_holidays_unknown(self, holidays_unknown: ContextHolidays) -> Self
pub fn with_holidays_unknown(self, holidays_unknown: ContextHolidays) -> Self
Attach a new unknown holidays component to this context.
Sourcepub fn with_locale<L2: Localize>(self, locale: L2) -> Context<L2>
pub fn with_locale<L2: Localize>(self, locale: L2) -> Context<L2>
Attach a new locale component to this context.
Sourcepub fn approx_bound_interval_size(self, max_size: TimeDelta) -> Self
pub fn approx_bound_interval_size(self, max_size: TimeDelta) -> Self
Enables appromiation of long intervals.
Source§impl Context<TzLocation<Tz>>
impl Context<TzLocation<Tz>>
Sourcepub fn from_coords(coords: Coordinates) -> Self
Available on crate features auto-country and auto-timezone only.
pub fn from_coords(coords: Coordinates) -> Self
auto-country and auto-timezone only.Create a context with given coordinates and try to infer a timezone and a local holiday calendar.
use opening_hours::Context;
use opening_hours::localization::{Coordinates, Country, TzLocation};
let coords = Coordinates::new(48.8535, 2.34839).unwrap();
assert_eq!(
Context::from_coords(coords),
Context::default()
.with_holidays(Country::FR.holidays())
.with_locale(TzLocation::from_coords(coords)),
);