2022-01-14 22:42:18 +00:00
|
|
|
use std::{
|
|
|
|
convert::{TryFrom, TryInto},
|
|
|
|
fmt::Debug,
|
2022-08-02 10:45:37 +00:00
|
|
|
ops::{Deref, DerefMut},
|
2022-01-14 22:42:18 +00:00
|
|
|
};
|
2021-12-07 22:22:24 +00:00
|
|
|
|
2022-08-02 10:45:37 +00:00
|
|
|
use crate::{
|
|
|
|
restriction::Restrictions,
|
2022-08-02 12:21:07 +00:00
|
|
|
util::{impl_deref_wrapped, impl_try_from_repeated},
|
2022-08-02 10:45:37 +00:00
|
|
|
};
|
2021-12-07 22:22:24 +00:00
|
|
|
|
2021-12-16 21:42:37 +00:00
|
|
|
use librespot_core::date::Date;
|
2021-12-07 22:22:24 +00:00
|
|
|
|
2021-12-26 20:18:42 +00:00
|
|
|
use librespot_protocol as protocol;
|
2021-12-07 22:22:24 +00:00
|
|
|
use protocol::metadata::SalePeriod as SalePeriodMessage;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct SalePeriod {
|
|
|
|
pub restrictions: Restrictions,
|
|
|
|
pub start: Date,
|
|
|
|
pub end: Date,
|
|
|
|
}
|
|
|
|
|
2022-07-31 22:44:43 +00:00
|
|
|
#[derive(Debug, Clone, Default)]
|
2021-12-07 22:22:24 +00:00
|
|
|
pub struct SalePeriods(pub Vec<SalePeriod>);
|
|
|
|
|
2022-08-02 10:45:37 +00:00
|
|
|
impl_deref_wrapped!(SalePeriods, Vec<SalePeriod>);
|
2021-12-07 22:22:24 +00:00
|
|
|
|
2022-01-14 22:28:09 +00:00
|
|
|
impl TryFrom<&SalePeriodMessage> for SalePeriod {
|
|
|
|
type Error = librespot_core::Error;
|
|
|
|
fn try_from(sale_period: &SalePeriodMessage) -> Result<Self, Self::Error> {
|
|
|
|
Ok(Self {
|
2021-12-07 22:22:24 +00:00
|
|
|
restrictions: sale_period.get_restriction().into(),
|
2022-01-14 22:28:09 +00:00
|
|
|
start: sale_period.get_start().try_into()?,
|
|
|
|
end: sale_period.get_end().try_into()?,
|
|
|
|
})
|
2021-12-07 22:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-02 12:21:07 +00:00
|
|
|
impl_try_from_repeated!(SalePeriodMessage, SalePeriods);
|