Switch from time to jiff
This commit is contained in:
parent
a6d5c9f671
commit
87b031101f
6 changed files with 51 additions and 12 deletions
40
Cargo.lock
generated
40
Cargo.lock
generated
|
|
@ -1400,6 +1400,35 @@ version = "1.0.14"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
|
||||
|
||||
[[package]]
|
||||
name = "jiff"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3590fea8e9e22d449600c9bbd481a8163bef223e4ff938e5f55899f8cf1adb93"
|
||||
dependencies = [
|
||||
"jiff-tzdb-platform",
|
||||
"log",
|
||||
"portable-atomic",
|
||||
"portable-atomic-util",
|
||||
"serde",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jiff-tzdb"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf2cec2f5d266af45a071ece48b1fb89f3b00b2421ac3a5fe10285a6caaa60d3"
|
||||
|
||||
[[package]]
|
||||
name = "jiff-tzdb-platform"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a63c62e404e7b92979d2792352d885a7f8f83fd1d0d31eea582d77b2ceca697e"
|
||||
dependencies = [
|
||||
"jiff-tzdb",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jobserver"
|
||||
version = "0.1.32"
|
||||
|
|
@ -1891,6 +1920,15 @@ version = "1.10.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic-util"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507"
|
||||
dependencies = [
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "postcard"
|
||||
version = "1.1.1"
|
||||
|
|
@ -2468,6 +2506,7 @@ dependencies = [
|
|||
"clap",
|
||||
"escpos",
|
||||
"image",
|
||||
"jiff",
|
||||
"mime_guess",
|
||||
"palette",
|
||||
"rand 0.9.0",
|
||||
|
|
@ -2476,7 +2515,6 @@ dependencies = [
|
|||
"showbits-assets",
|
||||
"showbits-common",
|
||||
"taffy",
|
||||
"time",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ clap = { version = "4.5.30", features = ["derive", "deprecated"] }
|
|||
cosmic-text = "0.12.1"
|
||||
escpos = "0.15.0"
|
||||
image = "0.25.5"
|
||||
jiff = "0.2.1"
|
||||
mark.git = "https://github.com/Garmelon/mark.git"
|
||||
mime_guess = "2.0.5"
|
||||
palette = "0.7.6"
|
||||
|
|
@ -22,7 +23,6 @@ rust-embed = "8.5.0"
|
|||
serde = { version = "1.0.218", features = ["derive"] }
|
||||
showbits-assets.path = "./showbits-assets"
|
||||
showbits-common.path = "./showbits-common"
|
||||
time = "0.3.37"
|
||||
tokio = "1.43.0"
|
||||
typst = "0.13.0"
|
||||
typst-assets = { version = "0.13.0", features = ["fonts"] }
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ axum = { workspace = true, features = ["multipart"] }
|
|||
clap = { workspace = true }
|
||||
escpos = { workspace = true }
|
||||
image = { workspace = true }
|
||||
jiff = { workspace = true }
|
||||
mime_guess = { workspace = true }
|
||||
palette = { workspace = true }
|
||||
rand = { workspace = true }
|
||||
|
|
@ -17,7 +18,6 @@ serde = { workspace = true }
|
|||
showbits-assets = { workspace = true }
|
||||
showbits-common = { workspace = true }
|
||||
taffy = { workspace = true }
|
||||
time = { workspace = true }
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
|
||||
[lints]
|
||||
|
|
|
|||
|
|
@ -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