Skip to content

Commit d66a5d4

Browse files
committed
Get rid of chrono dependency in favor of time
1 parent 947479d commit d66a5d4

File tree

5 files changed

+81
-78
lines changed

5 files changed

+81
-78
lines changed

Cargo.lock

Lines changed: 60 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test = true
1313

1414
[dependencies]
1515
plist = "1.3"
16-
chrono = "0.4"
16+
time = { version = "0.3.9", features = ["formatting", "macros"] }
1717
memmem = "0.1"
1818
clap = { version = "3", features = ["derive"] }
1919
dirs = "4.0"

src/bin/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn list(
5656
writeln!(
5757
&mut stdout,
5858
"{}{}",
59-
profile.info.description(oneline),
59+
profile.info.description(oneline)?,
6060
separator
6161
)?;
6262
}
@@ -100,7 +100,7 @@ fn remove_profiles(profiles: &[mp::Profile]) -> Result {
100100
writeln!(
101101
&mut stdout,
102102
"{}{}",
103-
profile.info.description(false),
103+
profile.info.description(false)?,
104104
separator
105105
)?
106106
}

src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,9 @@ impl From<FromUtf8Error> for Error {
4141
Self::Own(e.to_string())
4242
}
4343
}
44+
45+
impl From<time::error::Format> for Error {
46+
fn from(e: time::error::Format) -> Self {
47+
Self::Own(e.to_string())
48+
}
49+
}

src/profile.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use crate::{Error, Result};
2-
use chrono::{DateTime, Utc};
32
use colored::Colorize;
43
use serde::Deserialize;
54
use std::fs::File;
65
use std::io::{self, Read};
76
use std::path::{Path, PathBuf};
87
use std::time::SystemTime;
8+
use time::macros::format_description;
9+
use time::OffsetDateTime;
910

1011
/// Represents a file with a provisioning profile info.
1112
#[derive(Debug, Clone)]
@@ -105,32 +106,32 @@ impl Info {
105106
}
106107

107108
/// Returns profile in a text form.
108-
pub fn description(&self, oneline: bool) -> String {
109+
pub fn description(&self, oneline: bool) -> Result<String> {
109110
if oneline {
110-
return format!(
111+
return Ok(format!(
111112
"{} {} {} {}",
112113
self.uuid.yellow(),
113-
DateTime::<Utc>::from(self.expiration_date)
114-
.format("%Y-%m-%d")
115-
.to_string()
114+
OffsetDateTime::from(self.expiration_date)
115+
.format(format_description!("[year]-[month]-[day]"))?
116116
.blue(),
117117
self.app_identifier.green(),
118118
self.name
119-
);
119+
));
120120
} else {
121+
let fmt_desc = format_description!("[year]-[month]-[day] [hour]:[minute]:[second] UTC");
121122
let dates = format!(
122123
"{} - {}",
123-
DateTime::<Utc>::from(self.creation_date),
124-
DateTime::<Utc>::from(self.expiration_date)
124+
OffsetDateTime::from(self.creation_date).format(fmt_desc)?,
125+
OffsetDateTime::from(self.expiration_date).format(fmt_desc)?,
125126
)
126127
.blue();
127-
return format!(
128+
return Ok(format!(
128129
"{}\n{}\n{}\n{}",
129130
self.uuid.yellow(),
130131
self.app_identifier.green(),
131132
self.name,
132133
dates
133-
);
134+
));
134135
}
135136
}
136137
}

0 commit comments

Comments
 (0)