Skip to content

Commit a9534fd

Browse files
committed
cleanup(build): fix deprecated NaiveDateTime uses
1 parent 8026b8d commit a9534fd

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

git-branchless-lib/src/git/object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl<'repo> Commit<'repo> {
222222
/// its OID, author, commit time, and message.
223223
#[instrument]
224224
pub fn friendly_preview(&self) -> Result<StyledString> {
225-
let commit_time = self.get_time().to_naive_date_time();
225+
let commit_time = self.get_time().to_date_time();
226226
let preview = StyledStringBuilder::from_lines(vec![
227227
StyledStringBuilder::new()
228228
.append_styled(

git-branchless-lib/src/git/repo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::time::{Duration, SystemTime};
1919
use std::{io, time};
2020

2121
use bstr::ByteVec;
22-
use chrono::NaiveDateTime;
22+
use chrono::{DateTime, Utc};
2323
use cursive::theme::BaseColor;
2424
use cursive::utils::markup::StyledString;
2525
use git2::DiffOptions;
@@ -1737,8 +1737,8 @@ impl Time {
17371737
)))
17381738
}
17391739

1740-
/// Calculate the associated [`NaiveDateTime`].
1741-
pub fn to_naive_date_time(&self) -> Option<NaiveDateTime> {
1742-
NaiveDateTime::from_timestamp_opt(self.inner.seconds(), 0)
1740+
/// Calculate the associated [`DateTime`].
1741+
pub fn to_date_time(&self) -> Option<DateTime<Utc>> {
1742+
DateTime::from_timestamp(self.inner.seconds(), 0)
17431743
}
17441744
}

git-branchless-revset/src/pattern.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Debug;
22
use std::sync::{Arc, Mutex};
33

4-
use chrono::{Local, NaiveDateTime};
4+
use chrono::{DateTime, Local};
55
use chrono_english::{parse_date_string, parse_duration, DateError, Dialect, Interval};
66
use chronoutil::RelativeDuration;
77
use eden_dag::nameset::hints::{Flags, Hints};
@@ -22,8 +22,8 @@ pub(super) enum Pattern {
2222
Substring(String),
2323
Glob(glob::Pattern),
2424
Regex(regex::Regex),
25-
Before(NaiveDateTime),
26-
After(NaiveDateTime),
25+
Before(DateTime<Local>),
26+
After(DateTime<Local>),
2727
}
2828

2929
#[derive(Debug, Error)]
@@ -64,11 +64,11 @@ impl Pattern {
6464
Pattern::Exact(_) | Pattern::Substring(_) | Pattern::Glob(_) | Pattern::Regex(_) => {
6565
false
6666
}
67-
Pattern::Before(date) => match time.to_naive_date_time() {
67+
Pattern::Before(date) => match time.to_date_time() {
6868
Some(time) => &time <= date,
6969
None => false,
7070
},
71-
Pattern::After(date) => match time.to_naive_date_time() {
71+
Pattern::After(date) => match time.to_date_time() {
7272
Some(time) => &time >= date,
7373
None => false,
7474
},
@@ -94,17 +94,17 @@ impl Pattern {
9494
return Ok(Pattern::Regex(pattern));
9595
}
9696

97-
fn parse_date(pattern: &str) -> Result<NaiveDateTime, PatternError> {
97+
fn parse_date(pattern: &str) -> Result<DateTime<Local>, PatternError> {
9898
if let Ok(date) = parse_date_string(pattern, Local::now(), Dialect::Us) {
99-
return Ok(date.naive_local());
99+
return Ok(date.with_timezone(&Local));
100100
}
101101
if let Ok(interval) = parse_duration(pattern) {
102102
let delta = match interval {
103103
Interval::Seconds(seconds) => RelativeDuration::seconds(seconds.into()),
104104
Interval::Days(days) => RelativeDuration::days(days.into()),
105105
Interval::Months(months) => RelativeDuration::months(months),
106106
};
107-
let date = Local::now().naive_local() + delta;
107+
let date = Local::now() + delta;
108108
return Ok(date);
109109
}
110110
Err(PatternError::ConstructMatcher(eyre::eyre!(

0 commit comments

Comments
 (0)