EpisodeWidget: Fix Date states.
This commit is contained in:
parent
c856b88008
commit
1558ee2177
@ -198,54 +198,53 @@ pub struct Date<S> {
|
|||||||
state: S,
|
state: S,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Date<Usual> {
|
impl<S> Date<S> {
|
||||||
fn new(date: gtk::Label, epoch: i64) -> Self {
|
fn into_usual(self, epoch: i64) -> Date<Usual> {
|
||||||
let ts = Utc.timestamp(i64::from(epoch), 0);
|
let ts = Utc.timestamp(epoch, 0);
|
||||||
date.set_text(ts.format("%e %b").to_string().trim());
|
self.date.set_text(ts.format("%e %b").to_string().trim());
|
||||||
|
|
||||||
Date {
|
Date {
|
||||||
date,
|
date: self.date,
|
||||||
epoch,
|
epoch: self.epoch,
|
||||||
state: Usual {},
|
state: Usual {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl From<Date<Usual>> for Date<YearShown> {
|
fn into_year_shown(self, epoch: i64) -> Date<YearShown> {
|
||||||
fn from(f: Date<Usual>) -> Self {
|
let ts = Utc.timestamp(epoch, 0);
|
||||||
let ts = Utc.timestamp(f.epoch, 0);
|
self.date.set_text(ts.format("%e %b %Y").to_string().trim());
|
||||||
f.date.set_text(ts.format("%e %b %Y").to_string().trim());
|
|
||||||
|
|
||||||
Date {
|
Date {
|
||||||
date: f.date,
|
date: self.date,
|
||||||
epoch: f.epoch,
|
epoch: self.epoch,
|
||||||
state: YearShown {},
|
state: YearShown {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Date<YearShown>> for Date<Usual> {
|
impl Date<UnInitialized> {
|
||||||
fn from(f: Date<YearShown>) -> Self {
|
fn new(date: gtk::Label, epoch: i64) -> Self {
|
||||||
let ts = Utc.timestamp(f.epoch, 0);
|
let ts = Utc.timestamp(epoch, 0);
|
||||||
f.date.set_text(ts.format("%e %b").to_string().trim());
|
date.set_text(ts.format("%e %b %Y").to_string().trim());
|
||||||
|
|
||||||
Date {
|
Date {
|
||||||
date: f.date,
|
date,
|
||||||
epoch: f.epoch,
|
epoch,
|
||||||
state: Usual {},
|
state: UnInitialized {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum DateMachine {
|
pub enum DateMachine {
|
||||||
|
UnInitialized(Date<UnInitialized>),
|
||||||
Usual(Date<Usual>),
|
Usual(Date<Usual>),
|
||||||
WithYear(Date<YearShown>),
|
WithYear(Date<YearShown>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DateMachine {
|
impl DateMachine {
|
||||||
pub fn new(label: gtk::Label, epoch: i64) -> Self {
|
pub fn new(label: gtk::Label, epoch: i64) -> Self {
|
||||||
let m = DateMachine::Usual(Date::<Usual>::new(label, epoch));
|
let m = DateMachine::UnInitialized(Date::<UnInitialized>::new(label, epoch));
|
||||||
m.determine_state(epoch)
|
m.determine_state(epoch)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,13 +252,18 @@ impl DateMachine {
|
|||||||
use self::DateMachine::*;
|
use self::DateMachine::*;
|
||||||
|
|
||||||
let ts = Utc.timestamp(epoch, 0);
|
let ts = Utc.timestamp(epoch, 0);
|
||||||
let is_old = NOW.year() == ts.year();
|
let is_old = !(NOW.year() == ts.year());
|
||||||
|
|
||||||
match (self, is_old) {
|
match (self, is_old) {
|
||||||
(date @ Usual(_), false) => date,
|
// Into Usual
|
||||||
(date @ WithYear(_), true) => date,
|
(Usual(val), false) => Usual(val.into_usual(epoch)),
|
||||||
(Usual(val), true) => WithYear(val.into()),
|
(WithYear(val), false) => Usual(val.into_usual(epoch)),
|
||||||
(WithYear(val), false) => Usual(val.into()),
|
(UnInitialized(val), false) => Usual(val.into_usual(epoch)),
|
||||||
|
|
||||||
|
// Into Year Shown
|
||||||
|
(Usual(val), true) => WithYear(val.into_year_shown(epoch)),
|
||||||
|
(WithYear(val), true) => WithYear(val.into_year_shown(epoch)),
|
||||||
|
(UnInitialized(val), true) => WithYear(val.into_year_shown(epoch)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user