Skip to content

Commit 43f0ee4

Browse files
committed
Fix deprecations
1 parent 0d8d4bd commit 43f0ee4

File tree

5 files changed

+41
-40
lines changed

5 files changed

+41
-40
lines changed

src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl App<'_> {
313313
None => terminal.hide_cursor()?,
314314
Some((x, y)) => {
315315
terminal.show_cursor()?;
316-
terminal.set_cursor(x, y)?;
316+
terminal.set_cursor_position((x, y))?;
317317
}
318318
}
319319
terminal.flush()?;

src/client/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
#![allow(dead_code)]
22

3-
use std::{fmt::Display};
3+
use std::fmt::Display;
44

55
use chrono::{DateTime, NaiveDateTime, Utc};
66
use hyper::{client::HttpConnector, Body, Client, Method, Request, Response};
7-
use hyper_rustls::{HttpsConnectorBuilder, HttpsConnector};
7+
use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder};
88
use serde::{de::DeserializeOwned, Deserialize, Serialize};
99
use serde_json::Value;
1010

11-
use crate::event::{logger::Logger};
11+
use crate::event::logger::Logger;
1212

1313
pub fn new_strava_client(config: StravaConfig, logger: Logger) -> StravaClient {
14-
let connector = HttpsConnectorBuilder::new().with_native_roots().https_only().enable_http1().build();
14+
let connector = HttpsConnectorBuilder::new()
15+
.with_native_roots()
16+
.https_only()
17+
.enable_http1()
18+
.build();
1519
let client = Client::builder().build(connector);
1620

1721
StravaClient {
@@ -57,7 +61,7 @@ pub struct Activity {
5761
pub location_city: Option<String>,
5862
pub athlete_count: i64,
5963
pub splits_metric: Option<Vec<Split>>,
60-
pub splits_standard: Option<Vec<Split>>
64+
pub splits_standard: Option<Vec<Split>>,
6165
}
6266

6367
#[derive(Serialize, Deserialize, Debug)]
@@ -102,11 +106,7 @@ impl StravaClient {
102106
let res: Response<Body> = self.client.request(req).await?;
103107

104108
if res.status() != 200 {
105-
let message = format!(
106-
"Got {} response for URL {}",
107-
res.status(),
108-
&url
109-
);
109+
let message = format!("Got {} response for URL {}", res.status(), &url);
110110
self.logger.error(message.clone()).await;
111111
return Err(anyhow::Error::msg(message));
112112
}
@@ -131,7 +131,7 @@ impl StravaClient {
131131
per_page,
132132
page,
133133
match after {
134-
Some(epoch) => epoch.timestamp().to_string(),
134+
Some(epoch) => epoch.and_utc().timestamp().to_string(),
135135
None => "".to_string(),
136136
}
137137
),

src/component/activity_list/chart.rs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
use chrono::NaiveDateTime;
1+
use chrono::DateTime;
22
use tui::{
3-
layout::Constraint, prelude::Buffer, style::{Color, Style}, symbols::Marker, text::{Line, Span}, widgets::{Axis, Block, Borders, Chart, Dataset, GraphType, Widget}
3+
layout::Constraint,
4+
prelude::Buffer,
5+
style::{Color, Style},
6+
symbols::Marker,
7+
text::{Line, Span},
8+
widgets::{Axis, Block, Borders, Chart, Dataset, GraphType, Widget},
49
};
510

611
use crate::{
@@ -10,14 +15,8 @@ use crate::{
1015
};
1116

1217
pub fn handle(_app: &mut App, _key: MappedKey) {}
13-
pub fn draw(
14-
app: &mut App,
15-
f: &mut Buffer,
16-
area: tui::layout::Rect,
17-
) {
18-
let activities = &app
19-
.activities()
20-
.sort(&SortBy::Date, &SortOrder::Asc);
18+
pub fn draw(app: &mut App, f: &mut Buffer, area: tui::layout::Rect) {
19+
let activities = &app.activities().sort(&SortBy::Date, &SortOrder::Asc);
2120
let times: Vec<i64> = activities.timestamps();
2221
let paces: Vec<i64> = activities.meter_per_hours();
2322
let tmax = times.iter().max();
@@ -38,7 +37,7 @@ pub fn draw(
3837
.to_vec()
3938
.iter()
4039
.map(|a| {
41-
let ts = a.start_date.unwrap().timestamp();
40+
let ts = a.start_date.unwrap().and_utc().timestamp();
4241
(ts as f64, a.meters_per_hour())
4342
})
4443
.collect();
@@ -47,8 +46,14 @@ pub fn draw(
4746
let activities = app.activities();
4847
if let Some(a) = activities.get(selected) {
4948
if let Some(a) = activities.find(a.id) {
50-
current.push((a.start_date.unwrap().timestamp() as f64, *pmin as f64));
51-
current.push((a.start_date.unwrap().timestamp() as f64, *pmax as f64));
49+
current.push((
50+
a.start_date.unwrap().and_utc().timestamp() as f64,
51+
*pmin as f64,
52+
));
53+
current.push((
54+
a.start_date.unwrap().and_utc().timestamp() as f64,
55+
*pmax as f64,
56+
));
5257
}
5358
}
5459
}
@@ -84,15 +89,12 @@ pub fn draw(
8489
.title(Span::styled("Date", Style::default().fg(Color::Red)))
8590
.style(Style::default().fg(Color::White))
8691
.bounds([*tmin.unwrap() as f64, *tmax.unwrap() as f64])
87-
.labels(
88-
xaxis
89-
.map(|p| {
90-
Line::from(match NaiveDateTime::from_timestamp_millis(p * 1000) {
91-
Some(t) => t.format("%Y-%m-%d").to_string(),
92-
None => "n/a".to_string(),
93-
})
94-
})
95-
),
92+
.labels(xaxis.map(|p| {
93+
Line::from(match DateTime::from_timestamp_millis(p * 1000) {
94+
Some(t) => t.format("%Y-%m-%d").to_string(),
95+
None => "n/a".to_string(),
96+
})
97+
})),
9698
)
9799
.y_axis(
98100
Axis::default()
@@ -102,10 +104,7 @@ pub fn draw(
102104
*pmin as f64,
103105
*pmax as f64 + (pdiff as f64 / activities.len() as f64),
104106
])
105-
.labels(
106-
yaxis
107-
.map(|p| Span::from(app.unit_formatter.pace(3600, p as f64)))
108-
),
107+
.labels(yaxis.map(|p| Span::from(app.unit_formatter.pace(3600, p as f64)))),
109108
);
110109
chart.render(area, f);
111110
}

src/store/activity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl Activities {
191191
pub fn timestamps(&self) -> Vec<i64> {
192192
self.activities
193193
.iter()
194-
.map(|a| a.start_date.unwrap().timestamp())
194+
.map(|a| a.start_date.unwrap().and_utc().timestamp())
195195
.collect()
196196
}
197197

src/sync/ingest_activities.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::str::FromStr;
2+
13
use chrono::{NaiveDateTime};
24
use sqlx::{SqlitePool};
35

@@ -61,7 +63,7 @@ INSERT INTO raw_activity (id, created_at, listed, synced) VALUES (?, ?, ?, false
6163
).bind(
6264
match NaiveDateTime::parse_from_str(s_activity["start_date"].as_str().unwrap(), "%Y-%m-%dT%H:%M:%SZ") {
6365
Ok(t) => t,
64-
Err(_err) => NaiveDateTime::from_timestamp_millis(0).unwrap(),
66+
Err(_err) => NaiveDateTime::from_str("0")?,
6567
}
6668
).bind(
6769
s_activity.to_string()

0 commit comments

Comments
 (0)