use crate::places::{PlaceOpeningHoursPeriod, PlaceSpecialDay, SecondaryHoursType};
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct PlaceOpeningHours {
#[serde(default)]
pub open_now: Option<bool>,
#[serde(default)]
pub periods: Vec<PlaceOpeningHoursPeriod>,
#[serde(default)]
pub special_days: Vec<PlaceSpecialDay>,
#[serde(default)]
pub secondary_hours_type: Option<SecondaryHoursType>,
#[serde(default)]
pub weekday_text: Vec<String>,
}
impl std::str::FromStr for PlaceOpeningHours {
type Err = serde_json::Error;
fn from_str(s: &str) -> Result<Self, serde_json::Error> {
let bytes = s.to_string().into_bytes();
serde_json::from_slice(&bytes)
} }
impl PlaceOpeningHours {
#[must_use]
pub fn special_days(&self) -> HashSet<NaiveDate> {
self.special_days
.iter()
.filter_map(|place_special_day| place_special_day.date)
.collect::<HashSet<NaiveDate>>()
} }