Switch from time to jiff
This commit is contained in:
parent
a6d5c9f671
commit
87b031101f
6 changed files with 51 additions and 12 deletions
|
|
@ -1,3 +1,4 @@
|
|||
use jiff::civil;
|
||||
use showbits_common::{
|
||||
Node, Tree, WidgetExt,
|
||||
color::{BLACK, WHITE},
|
||||
|
|
@ -7,20 +8,19 @@ use taffy::{
|
|||
AlignContent, AlignItems, Display, FlexDirection,
|
||||
style_helpers::{length, percent, repeat},
|
||||
};
|
||||
use time::Date;
|
||||
|
||||
use crate::printer::Printer;
|
||||
|
||||
use super::{Context, Drawing};
|
||||
|
||||
pub struct CalendarDrawing {
|
||||
pub year: i32,
|
||||
pub month: u8,
|
||||
pub year: i16,
|
||||
pub month: i8,
|
||||
}
|
||||
|
||||
impl Drawing for CalendarDrawing {
|
||||
fn draw(&self, printer: &mut Printer, ctx: &mut Context) -> anyhow::Result<()> {
|
||||
let mut date = Date::from_calendar_date(self.year, self.month.try_into()?, 1)?;
|
||||
let mut date = civil::Date::new(self.year, self.month, 1)?;
|
||||
|
||||
let mut tree = Tree::<Context>::new(WHITE);
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ impl Drawing for CalendarDrawing {
|
|||
grid = grid.and_child(text);
|
||||
}
|
||||
|
||||
let placeholders = date.weekday().number_days_from_monday();
|
||||
let placeholders = date.weekday().to_monday_zero_offset();
|
||||
for _ in 0..placeholders {
|
||||
let empty = Node::empty().register(&mut tree)?;
|
||||
grid = grid.and_child(empty);
|
||||
|
|
@ -68,7 +68,7 @@ impl Drawing for CalendarDrawing {
|
|||
|
||||
grid = grid.and_child(block);
|
||||
|
||||
let next_day = date.next_day().unwrap();
|
||||
let next_day = date.tomorrow()?;
|
||||
if date.month() != next_day.month() {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@ impl Drawing for EggDrawing {
|
|||
// Draw patterns onto egg
|
||||
let mut last_idx = None;
|
||||
let mut y = rng.random_range(-100_i64..0);
|
||||
while y < image.height().into() {
|
||||
let height: i64 = image.height().into();
|
||||
while y < height {
|
||||
let idx = loop {
|
||||
let idx = rng.random_range(0..patterns.len());
|
||||
if Some(idx) != last_idx {
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ pub async fn run(tx: mpsc::Sender<Command>, addr: String) -> anyhow::Result<()>
|
|||
|
||||
#[derive(Deserialize)]
|
||||
struct PostCalendarForm {
|
||||
year: i32,
|
||||
month: u8,
|
||||
year: i16,
|
||||
month: i8,
|
||||
}
|
||||
|
||||
async fn post_calendar(server: State<Server>, request: Form<PostCalendarForm>) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue