11use iced:: alignment;
22use iced:: mouse;
3+ use iced:: time;
34use iced:: widget:: canvas:: { stroke, Cache , Geometry , LineCap , Path , Stroke } ;
45use iced:: widget:: { canvas, container} ;
56use iced:: {
@@ -18,13 +19,13 @@ pub fn main() -> iced::Result {
1819}
1920
2021struct Clock {
21- now : time :: OffsetDateTime ,
22+ now : chrono :: DateTime < chrono :: Local > ,
2223 clock : Cache ,
2324}
2425
2526#[ derive( Debug , Clone , Copy ) ]
2627enum Message {
27- Tick ( time :: OffsetDateTime ) ,
28+ Tick ( chrono :: DateTime < chrono :: Local > ) ,
2829}
2930
3031impl Clock {
@@ -54,25 +55,20 @@ impl Clock {
5455 }
5556
5657 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- } )
58+ time:: every ( time:: Duration :: from_millis ( 500 ) )
59+ . map ( |_| Message :: Tick ( chrono:: offset:: Local :: now ( ) ) )
6360 }
6461
6562 fn theme ( & self ) -> Theme {
66- Theme :: ALL [ ( self . now . unix_timestamp ( ) as usize / 10 ) % Theme :: ALL . len ( ) ]
63+ Theme :: ALL [ ( self . now . timestamp ( ) as usize / 10 ) % Theme :: ALL . len ( ) ]
6764 . clone ( )
6865 }
6966}
7067
7168impl Default for Clock {
7269 fn default ( ) -> Self {
7370 Self {
74- now : time:: OffsetDateTime :: now_local ( )
75- . unwrap_or_else ( |_| time:: OffsetDateTime :: now_utc ( ) ) ,
71+ now : chrono:: offset:: Local :: now ( ) ,
7672 clock : Cache :: default ( ) ,
7773 }
7874 }
@@ -89,6 +85,8 @@ impl<Message> canvas::Program<Message> for Clock {
8985 bounds : Rectangle ,
9086 _cursor : mouse:: Cursor ,
9187 ) -> Vec < Geometry > {
88+ use chrono:: Timelike ;
89+
9290 let clock = self . clock . draw ( renderer, bounds. size ( ) , |frame| {
9391 let palette = theme. extended_palette ( ) ;
9492
@@ -169,7 +167,7 @@ impl<Message> canvas::Program<Message> for Clock {
169167 }
170168}
171169
172- fn hand_rotation ( n : u8 , total : u8 ) -> Degrees {
170+ fn hand_rotation ( n : u32 , total : u32 ) -> Degrees {
173171 let turns = n as f32 / total as f32 ;
174172
175173 Degrees ( 360.0 * turns)
0 commit comments