Skip to content

Commit 0636d5b

Browse files
committed
Formatting
1 parent f20296c commit 0636d5b

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

src/time_config.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use anyhow::{anyhow, Result};
2-
use chrono::{DateTime, Duration, Local, NaiveDate, Utc, TimeZone};
1+
use anyhow::{Result, anyhow};
2+
use chrono::{DateTime, Duration, Local, NaiveDate, TimeZone, Utc};
33
use chrono_tz::Tz;
44

55
#[derive(Clone, Debug)]
@@ -10,16 +10,19 @@ pub struct TimeConfig {
1010

1111
impl TimeConfig {
1212
pub fn new(timezone: Option<Tz>, day_start_minutes: u16) -> Self {
13-
Self { timezone, day_start_minutes }
13+
Self {
14+
timezone,
15+
day_start_minutes,
16+
}
1417
}
1518

1619
/// Build from optional CLI strings (timezone IANA name, day start as HH:MM)
1720
pub fn from_cli(timezone: &Option<String>, day_start_time: &Option<String>) -> Result<Self> {
1821
let tz = match timezone {
1922
Some(tz_str) if !tz_str.trim().is_empty() => {
20-
let parsed: Tz = tz_str
21-
.parse()
22-
.map_err(|_| anyhow!("Invalid timezone: {}. Example: Australia/Sydney", tz_str))?;
23+
let parsed: Tz = tz_str.parse().map_err(|_| {
24+
anyhow!("Invalid timezone: {}. Example: Australia/Sydney", tz_str)
25+
})?;
2326
Some(parsed)
2427
}
2528
_ => None,
@@ -36,7 +39,9 @@ impl TimeConfig {
3639
fn parse_day_start_minutes(s: &str) -> Result<u16> {
3740
let parts: Vec<&str> = s.split(':').collect();
3841
if parts.len() != 2 {
39-
return Err(anyhow!("Invalid --day-start-time format. Use HH:MM (e.g., 03:00)"));
42+
return Err(anyhow!(
43+
"Invalid --day-start-time format. Use HH:MM (e.g., 03:00)"
44+
));
4045
}
4146
let hours: u16 = parts[0]
4247
.parse()
@@ -69,7 +74,9 @@ impl TimeConfig {
6974

7075
/// Format a timestamp as YYYY-MM-DD under configured timezone/day-start.
7176
pub fn format_date(&self, timestamp: i64) -> String {
72-
self.date_for_timestamp(timestamp).format("%Y-%m-%d").to_string()
77+
self.date_for_timestamp(timestamp)
78+
.format("%Y-%m-%d")
79+
.to_string()
7380
}
7481

7582
/// Today's logical date under configured timezone/day-start.
@@ -81,10 +88,11 @@ impl TimeConfig {
8188
/// Format current time as YYYY-MM-DD HH:MM in configured timezone (no day-start adjustment).
8289
pub fn now_formatted(&self) -> String {
8390
match self.timezone {
84-
Some(tz) => Utc::now().with_timezone(&tz).format("%Y-%m-%d %H:%M").to_string(),
91+
Some(tz) => Utc::now()
92+
.with_timezone(&tz)
93+
.format("%Y-%m-%d %H:%M")
94+
.to_string(),
8595
None => Local::now().format("%Y-%m-%d %H:%M").to_string(),
8696
}
8797
}
8898
}
89-
90-

src/web_server.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use axum::Router;
33
use log::info;
44
use std::path::PathBuf;
55
use tower::ServiceBuilder;
6-
use tower_http::services::{ServeDir, ServeFile};
76
use tower_http::cors::CorsLayer;
7+
use tower_http::services::{ServeDir, ServeFile};
88

99
pub struct WebServer {
1010
site_dir: PathBuf,
@@ -15,25 +15,24 @@ impl WebServer {
1515
pub fn new(site_dir: PathBuf, port: u16) -> Self {
1616
Self { site_dir, port }
1717
}
18-
18+
1919
pub async fn run(self) -> Result<()> {
2020
// Create a 404 page service
2121
let not_found_service = ServeFile::new("templates/404.html");
22-
22+
2323
let app = Router::new()
24-
.fallback_service(ServeDir::new(&self.site_dir)
25-
.not_found_service(not_found_service))
26-
.layer(
27-
ServiceBuilder::new()
28-
.layer(CorsLayer::permissive())
29-
);
30-
24+
.fallback_service(ServeDir::new(&self.site_dir).not_found_service(not_found_service))
25+
.layer(ServiceBuilder::new().layer(CorsLayer::permissive()));
26+
3127
let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", self.port)).await?;
32-
33-
info!("Web server running on http://localhost:{}, binding to: 0.0.0.0", self.port);
34-
28+
29+
info!(
30+
"Web server running on http://localhost:{}, binding to: 0.0.0.0",
31+
self.port
32+
);
33+
3534
axum::serve(listener, app).await?;
36-
35+
3736
Ok(())
3837
}
39-
}
38+
}

0 commit comments

Comments
 (0)