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 } ;
33use chrono_tz:: Tz ;
44
55#[ derive( Clone , Debug ) ]
@@ -10,16 +10,19 @@ pub struct TimeConfig {
1010
1111impl 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-
0 commit comments