mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
pr: migrate from chrono
crate to time
It seems that `chrono` is the reason of deadlock or UB in android CI. Also `chrono` had some security issues and wasn't maintained for two years until March 2022, so other unstabilities can happen. Plus `chrono` uses old `time` dependency.
This commit is contained in:
parent
0e0d121a1b
commit
999db68042
4 changed files with 39 additions and 23 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2620,11 +2620,11 @@ dependencies = [
|
||||||
name = "uu_pr"
|
name = "uu_pr"
|
||||||
version = "0.0.15"
|
version = "0.0.15"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
|
||||||
"clap",
|
"clap",
|
||||||
"itertools",
|
"itertools",
|
||||||
"quick-error",
|
"quick-error",
|
||||||
"regex",
|
"regex",
|
||||||
|
"time 0.3.14",
|
||||||
"uucore",
|
"uucore",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ path = "src/pr.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "3.2", features = ["wrap_help", "cargo"] }
|
clap = { version = "3.2", features = ["wrap_help", "cargo"] }
|
||||||
|
time = { version = "0.3", features = ["local-offset", "macros", "formatting"] }
|
||||||
uucore = { version=">=0.0.15", package="uucore", path="../../uucore", features=["entries"] }
|
uucore = { version=">=0.0.15", package="uucore", path="../../uucore", features=["entries"] }
|
||||||
chrono = { version="^0.4.19", default-features=false, features=["std", "alloc", "clock"]}
|
|
||||||
quick-error = "2.0.1"
|
quick-error = "2.0.1"
|
||||||
itertools = "0.10.0"
|
itertools = "0.10.0"
|
||||||
regex = "1.6"
|
regex = "1.6"
|
||||||
|
|
|
@ -9,8 +9,6 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate quick_error;
|
extern crate quick_error;
|
||||||
|
|
||||||
use chrono::offset::Local;
|
|
||||||
use chrono::DateTime;
|
|
||||||
use clap::{AppSettings, Arg, ArgMatches, Command};
|
use clap::{AppSettings, Arg, ArgMatches, Command};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use quick_error::ResultExt;
|
use quick_error::ResultExt;
|
||||||
|
@ -20,6 +18,8 @@ use std::fs::{metadata, File};
|
||||||
use std::io::{stdin, stdout, BufRead, BufReader, Lines, Read, Write};
|
use std::io::{stdin, stdout, BufRead, BufReader, Lines, Read, Write};
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::fs::FileTypeExt;
|
use std::os::unix::fs::FileTypeExt;
|
||||||
|
use time::macros::format_description;
|
||||||
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
use uucore::display::Quotable;
|
use uucore::display::Quotable;
|
||||||
use uucore::error::{set_exit_code, UResult};
|
use uucore::error::{set_exit_code, UResult};
|
||||||
|
@ -62,6 +62,8 @@ const DEFAULT_COLUMN_WIDTH: usize = 72;
|
||||||
const DEFAULT_COLUMN_WIDTH_WITH_S_OPTION: usize = 512;
|
const DEFAULT_COLUMN_WIDTH_WITH_S_OPTION: usize = 512;
|
||||||
const DEFAULT_COLUMN_SEPARATOR: &char = &TAB;
|
const DEFAULT_COLUMN_SEPARATOR: &char = &TAB;
|
||||||
const FF: u8 = 0x0C_u8;
|
const FF: u8 = 0x0C_u8;
|
||||||
|
const DATE_TIME_FORMAT: &[time::format_description::FormatItem] =
|
||||||
|
format_description!("[month repr:short] [day] [hour]:[minute] [year]");
|
||||||
|
|
||||||
mod options {
|
mod options {
|
||||||
pub const HEADER: &str = "header";
|
pub const HEADER: &str = "header";
|
||||||
|
@ -575,8 +577,10 @@ fn build_options(
|
||||||
let line_separator = "\n".to_string();
|
let line_separator = "\n".to_string();
|
||||||
|
|
||||||
let last_modified_time = if is_merge_mode || paths[0].eq(FILE_STDIN) {
|
let last_modified_time = if is_merge_mode || paths[0].eq(FILE_STDIN) {
|
||||||
let date_time = Local::now();
|
// let date_time = Local::now();
|
||||||
date_time.format("%b %d %H:%M %Y").to_string()
|
// date_time.format("%b %d %H:%M %Y").to_string()
|
||||||
|
let date_time = OffsetDateTime::now_local().unwrap();
|
||||||
|
date_time.format(&DATE_TIME_FORMAT).unwrap()
|
||||||
} else {
|
} else {
|
||||||
file_last_modified_time(paths.first().unwrap())
|
file_last_modified_time(paths.first().unwrap())
|
||||||
};
|
};
|
||||||
|
@ -1218,8 +1222,12 @@ fn file_last_modified_time(path: &str) -> String {
|
||||||
.map(|i| {
|
.map(|i| {
|
||||||
i.modified()
|
i.modified()
|
||||||
.map(|x| {
|
.map(|x| {
|
||||||
let date_time: DateTime<Local> = x.into();
|
let date_time: OffsetDateTime = x.into();
|
||||||
date_time.format("%b %d %H:%M %Y").to_string()
|
let offset = OffsetDateTime::now_local().unwrap().offset();
|
||||||
|
date_time
|
||||||
|
.to_offset(offset)
|
||||||
|
.format(&DATE_TIME_FORMAT)
|
||||||
|
.unwrap()
|
||||||
})
|
})
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
// spell-checker:ignore (ToDO) Sdivide
|
// spell-checker:ignore (ToDO) Sdivide
|
||||||
|
extern crate time;
|
||||||
|
|
||||||
use crate::common::util::*;
|
use crate::common::util::*;
|
||||||
use chrono::offset::Local;
|
|
||||||
use chrono::DateTime;
|
|
||||||
use chrono::Duration;
|
|
||||||
use std::fs::metadata;
|
use std::fs::metadata;
|
||||||
|
use time::macros::format_description;
|
||||||
|
use time::Duration;
|
||||||
|
use time::OffsetDateTime;
|
||||||
|
|
||||||
|
const DATE_TIME_FORMAT: &[time::format_description::FormatItem] =
|
||||||
|
format_description!("[month repr:short] [day] [hour]:[minute] [year]");
|
||||||
|
|
||||||
fn file_last_modified_time(ucmd: &UCommand, path: &str) -> String {
|
fn file_last_modified_time(ucmd: &UCommand, path: &str) -> String {
|
||||||
let tmp_dir_path = ucmd.get_full_fixture_path(path);
|
let tmp_dir_path = ucmd.get_full_fixture_path(path);
|
||||||
|
@ -13,28 +17,32 @@ fn file_last_modified_time(ucmd: &UCommand, path: &str) -> String {
|
||||||
.map(|i| {
|
.map(|i| {
|
||||||
i.modified()
|
i.modified()
|
||||||
.map(|x| {
|
.map(|x| {
|
||||||
let date_time: DateTime<Local> = x.into();
|
let date_time: OffsetDateTime = x.into();
|
||||||
date_time.format("%b %d %H:%M %Y").to_string()
|
let offset = OffsetDateTime::now_local().unwrap().offset();
|
||||||
|
date_time
|
||||||
|
.to_offset(offset)
|
||||||
|
.format(&DATE_TIME_FORMAT)
|
||||||
|
.unwrap()
|
||||||
})
|
})
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
})
|
})
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_minutes(from: DateTime<Local>, to: DateTime<Local>) -> Vec<String> {
|
fn all_minutes(from: OffsetDateTime, to: OffsetDateTime) -> Vec<String> {
|
||||||
let to = to + Duration::minutes(1);
|
let to = to + Duration::minutes(1);
|
||||||
const FORMAT: &str = "%b %d %H:%M %Y";
|
// const FORMAT: &str = "%b %d %H:%M %Y";
|
||||||
let mut vec = vec![];
|
let mut vec = vec![];
|
||||||
let mut current = from;
|
let mut current = from;
|
||||||
while current < to {
|
while current < to {
|
||||||
vec.push(current.format(FORMAT).to_string());
|
vec.push(current.format(&DATE_TIME_FORMAT).unwrap());
|
||||||
current += Duration::minutes(1);
|
current += Duration::minutes(1);
|
||||||
}
|
}
|
||||||
vec
|
vec
|
||||||
}
|
}
|
||||||
|
|
||||||
fn valid_last_modified_template_vars(from: DateTime<Local>) -> Vec<Vec<(String, String)>> {
|
fn valid_last_modified_template_vars(from: OffsetDateTime) -> Vec<Vec<(String, String)>> {
|
||||||
all_minutes(from, Local::now())
|
all_minutes(from, OffsetDateTime::now_local().unwrap())
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|time| vec![("{last_modified_time}".to_string(), time)])
|
.map(|time| vec![("{last_modified_time}".to_string(), time)])
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -250,7 +258,7 @@ fn test_with_suppress_error_option() {
|
||||||
fn test_with_stdin() {
|
fn test_with_stdin() {
|
||||||
let expected_file_path = "stdin.log.expected";
|
let expected_file_path = "stdin.log.expected";
|
||||||
let mut scenario = new_ucmd!();
|
let mut scenario = new_ucmd!();
|
||||||
let start = Local::now();
|
let start = OffsetDateTime::now_local().unwrap();
|
||||||
scenario
|
scenario
|
||||||
.pipe_in_fixture("stdin.log")
|
.pipe_in_fixture("stdin.log")
|
||||||
.args(&["--pages=1:2", "-n", "-"])
|
.args(&["--pages=1:2", "-n", "-"])
|
||||||
|
@ -313,7 +321,7 @@ fn test_with_mpr() {
|
||||||
let expected_test_file_path = "mpr.log.expected";
|
let expected_test_file_path = "mpr.log.expected";
|
||||||
let expected_test_file_path1 = "mpr1.log.expected";
|
let expected_test_file_path1 = "mpr1.log.expected";
|
||||||
let expected_test_file_path2 = "mpr2.log.expected";
|
let expected_test_file_path2 = "mpr2.log.expected";
|
||||||
let start = Local::now();
|
let start = OffsetDateTime::now_local().unwrap();
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["--pages=1:2", "-m", "-n", test_file_path, test_file_path1])
|
.args(&["--pages=1:2", "-m", "-n", test_file_path, test_file_path1])
|
||||||
.succeeds()
|
.succeeds()
|
||||||
|
@ -322,7 +330,7 @@ fn test_with_mpr() {
|
||||||
&valid_last_modified_template_vars(start),
|
&valid_last_modified_template_vars(start),
|
||||||
);
|
);
|
||||||
|
|
||||||
let start = Local::now();
|
let start = OffsetDateTime::now_local().unwrap();
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["--pages=2:4", "-m", "-n", test_file_path, test_file_path1])
|
.args(&["--pages=2:4", "-m", "-n", test_file_path, test_file_path1])
|
||||||
.succeeds()
|
.succeeds()
|
||||||
|
@ -331,7 +339,7 @@ fn test_with_mpr() {
|
||||||
&valid_last_modified_template_vars(start),
|
&valid_last_modified_template_vars(start),
|
||||||
);
|
);
|
||||||
|
|
||||||
let start = Local::now();
|
let start = OffsetDateTime::now_local().unwrap();
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&[
|
.args(&[
|
||||||
"--pages=1:2",
|
"--pages=1:2",
|
||||||
|
@ -439,7 +447,7 @@ fn test_with_join_lines_option() {
|
||||||
let test_file_2 = "test.log";
|
let test_file_2 = "test.log";
|
||||||
let expected_file_path = "joined.log.expected";
|
let expected_file_path = "joined.log.expected";
|
||||||
let mut scenario = new_ucmd!();
|
let mut scenario = new_ucmd!();
|
||||||
let start = Local::now();
|
let start = OffsetDateTime::now_local().unwrap();
|
||||||
scenario
|
scenario
|
||||||
.args(&["+1:2", "-J", "-m", test_file_1, test_file_2])
|
.args(&["+1:2", "-J", "-m", test_file_1, test_file_2])
|
||||||
.run()
|
.run()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue