summaryrefslogtreecommitdiffstats
path: root/examples/clock/src/main.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector0193@gmail.com>2022-01-14 13:50:30 +0700
committerLibravatar GitHub <noreply@github.com>2022-01-14 13:50:30 +0700
commitb7bc169120d3447ead238e974007027a5152d341 (patch)
treec0c3f56883c7df0f05acdc602b21c7a0f100cc56 /examples/clock/src/main.rs
parent15a13a76b4b0534d08afc0328b90267048e41b9d (diff)
parent34adeaa0810b3f36e47c2b63b0a09401a3cb878b (diff)
downloadiced-b7bc169120d3447ead238e974007027a5152d341.tar.gz
iced-b7bc169120d3447ead238e974007027a5152d341.tar.bz2
iced-b7bc169120d3447ead238e974007027a5152d341.zip
Merge pull request #1195 from iced-rs/fix/vulnerabilities
Fix `cargo-audit` vulnerabilities
Diffstat (limited to 'examples/clock/src/main.rs')
-rw-r--r--examples/clock/src/main.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs
index b317ac00..de9e879a 100644
--- a/examples/clock/src/main.rs
+++ b/examples/clock/src/main.rs
@@ -1,7 +1,7 @@
use iced::{
canvas::{self, Cache, Canvas, Cursor, Geometry, LineCap, Path, Stroke},
- executor, time, Application, Color, Command, Container, Element, Length,
- Point, Rectangle, Settings, Subscription, Vector,
+ executor, Application, Color, Command, Container, Element, Length, Point,
+ Rectangle, Settings, Subscription, Vector,
};
pub fn main() -> iced::Result {
@@ -12,13 +12,13 @@ pub fn main() -> iced::Result {
}
struct Clock {
- now: chrono::DateTime<chrono::Local>,
+ now: time::OffsetDateTime,
clock: Cache,
}
#[derive(Debug, Clone, Copy)]
enum Message {
- Tick(chrono::DateTime<chrono::Local>),
+ Tick(time::OffsetDateTime),
}
impl Application for Clock {
@@ -29,7 +29,8 @@ impl Application for Clock {
fn new(_flags: ()) -> (Self, Command<Message>) {
(
Clock {
- now: chrono::Local::now(),
+ now: time::OffsetDateTime::now_local()
+ .unwrap_or_else(|_| time::OffsetDateTime::now_utc()),
clock: Default::default(),
},
Command::none(),
@@ -56,8 +57,12 @@ impl Application for Clock {
}
fn subscription(&self) -> Subscription<Message> {
- time::every(std::time::Duration::from_millis(500))
- .map(|_| Message::Tick(chrono::Local::now()))
+ iced::time::every(std::time::Duration::from_millis(500)).map(|_| {
+ Message::Tick(
+ time::OffsetDateTime::now_local()
+ .unwrap_or_else(|_| time::OffsetDateTime::now_utc()),
+ )
+ })
}
fn view(&mut self) -> Element<Message> {
@@ -77,8 +82,6 @@ impl Application for Clock {
impl canvas::Program<Message> for Clock {
fn draw(&self, bounds: Rectangle, _cursor: Cursor) -> Vec<Geometry> {
- use chrono::Timelike;
-
let clock = self.clock.draw(bounds.size(), |frame| {
let center = frame.center();
let radius = frame.width().min(frame.height()) / 2.0;
@@ -126,7 +129,7 @@ impl canvas::Program<Message> for Clock {
}
}
-fn hand_rotation(n: u32, total: u32) -> f32 {
+fn hand_rotation(n: u8, total: u8) -> f32 {
let turns = n as f32 / total as f32;
2.0 * std::f32::consts::PI * turns