@@ -7,6 +7,9 @@ use iced::{
77 Theme , Vector ,
88} ;
99
10+ use chrono as time;
11+ use time:: Timelike ;
12+
1013pub fn main ( ) -> iced:: Result {
1114 tracing_subscriber:: fmt:: init ( ) ;
1215
@@ -18,13 +21,13 @@ pub fn main() -> iced::Result {
1821}
1922
2023struct Clock {
21- now : time:: OffsetDateTime ,
24+ now : time:: DateTime < time :: Local > ,
2225 clock : Cache ,
2326}
2427
2528#[ derive( Debug , Clone , Copy ) ]
2629enum Message {
27- Tick ( time:: OffsetDateTime ) ,
30+ Tick ( time:: DateTime < time :: Local > ) ,
2831}
2932
3033impl Clock {
@@ -54,25 +57,20 @@ impl Clock {
5457 }
5558
5659 fn subscription ( & self ) -> Subscription < Message > {
57- iced:: time:: every ( std:: time:: Duration :: from_millis ( 500 ) ) . map ( |_| {
58- Message :: Tick (
59- time:: OffsetDateTime :: now_local ( )
60- . unwrap_or_else ( |_| time:: OffsetDateTime :: now_utc ( ) ) ,
61- )
62- } )
60+ iced:: time:: every ( std:: time:: Duration :: from_millis ( 500 ) )
61+ . map ( |_| Message :: Tick ( time:: offset:: Local :: now ( ) ) )
6362 }
6463
6564 fn theme ( & self ) -> Theme {
66- Theme :: ALL [ ( self . now . unix_timestamp ( ) as usize / 10 ) % Theme :: ALL . len ( ) ]
65+ Theme :: ALL [ ( self . now . timestamp ( ) as usize / 10 ) % Theme :: ALL . len ( ) ]
6766 . clone ( )
6867 }
6968}
7069
7170impl Default for Clock {
7271 fn default ( ) -> Self {
7372 Self {
74- now : time:: OffsetDateTime :: now_local ( )
75- . unwrap_or_else ( |_| time:: OffsetDateTime :: now_utc ( ) ) ,
73+ now : time:: offset:: Local :: now ( ) ,
7674 clock : Cache :: default ( ) ,
7775 }
7876 }
@@ -127,17 +125,17 @@ impl<Message> canvas::Program<Message> for Clock {
127125 frame. translate ( Vector :: new ( center. x , center. y ) ) ;
128126
129127 frame. with_save ( |frame| {
130- frame. rotate ( hand_rotation ( self . now . hour ( ) , 12 ) ) ;
128+ frame. rotate ( hand_rotation ( self . now . hour ( ) as u8 , 12 ) ) ;
131129 frame. stroke ( & short_hand, wide_stroke ( ) ) ;
132130 } ) ;
133131
134132 frame. with_save ( |frame| {
135- frame. rotate ( hand_rotation ( self . now . minute ( ) , 60 ) ) ;
133+ frame. rotate ( hand_rotation ( self . now . minute ( ) as u8 , 60 ) ) ;
136134 frame. stroke ( & long_hand, wide_stroke ( ) ) ;
137135 } ) ;
138136
139137 frame. with_save ( |frame| {
140- let rotation = hand_rotation ( self . now . second ( ) , 60 ) ;
138+ let rotation = hand_rotation ( self . now . second ( ) as u8 , 60 ) ;
141139
142140 frame. rotate ( rotation) ;
143141 frame. stroke ( & long_hand, thin_stroke ( ) ) ;
0 commit comments