479
Cargo.lock
generated
479
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -22,7 +22,7 @@ sqlite-bundled = ["libsqlite3-sys/bundled"]
|
||||
|
||||
[dependencies]
|
||||
sn0int-common = { version="0.10.0", path="sn0int-common" }
|
||||
sn0int-std = { version="0.17.1", path="sn0int-std" }
|
||||
sn0int-std = { version="=0.17.1", path="sn0int-std" }
|
||||
rustyline = "6.0"
|
||||
log = "0.4"
|
||||
env_logger = "0.7"
|
||||
@@ -82,7 +82,7 @@ syscallz = "0.12"
|
||||
nix = "0.17"
|
||||
|
||||
[target.'cfg(target_os="openbsd")'.dependencies]
|
||||
pledge = "0.3.1"
|
||||
pledge = "0.4"
|
||||
unveil = "0.2.0"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -517,6 +517,13 @@ Log an info to the terminal.
|
||||
|
||||
info('ohai')
|
||||
|
||||
intval
|
||||
------
|
||||
|
||||
Parse a number from a string.
|
||||
|
||||
x = strval('1234')
|
||||
|
||||
json_decode
|
||||
-----------
|
||||
|
||||
@@ -1093,6 +1100,13 @@ Parse a date into a unix timestamp, see `strftime rules`_.
|
||||
|
||||
.. _strftime rules: https://docs.rs/chrono/0.4.6/chrono/format/strftime/index.html
|
||||
|
||||
strval
|
||||
------
|
||||
|
||||
Convert a number into a string.
|
||||
|
||||
x = strval(1234)
|
||||
|
||||
time_unix
|
||||
---------
|
||||
|
||||
|
||||
@@ -32,9 +32,8 @@ url = "2.0"
|
||||
tungstenite = { version = "0.10.1", default-features = false }
|
||||
kuchiki = "0.8.0"
|
||||
maxminddb = "0.13"
|
||||
# x509-parser 0.6.1 is broken
|
||||
x509-parser = "0.5.1"
|
||||
der-parser = "2.0"
|
||||
x509-parser = "0.6.2"
|
||||
der-parser = "3.0"
|
||||
publicsuffix = { version="1.5", default-features=false }
|
||||
xml-rs = "0.8"
|
||||
geo = "0.12"
|
||||
|
||||
@@ -4,6 +4,7 @@ use crate::cmd::Cmd;
|
||||
use crate::shell::Shell;
|
||||
use crate::models::*;
|
||||
use chrono::{Utc, NaiveDateTime, NaiveTime, Duration};
|
||||
use regex::Regex;
|
||||
use std::convert::TryFrom;
|
||||
use std::io;
|
||||
use std::str::FromStr;
|
||||
@@ -15,17 +16,36 @@ pub struct TimeSpec {
|
||||
datetime: NaiveDateTime,
|
||||
}
|
||||
|
||||
impl FromStr for TimeSpec {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self> {
|
||||
let now = Utc::now().naive_utc();
|
||||
impl TimeSpec {
|
||||
fn resolve(s: &str, now: NaiveDateTime) -> Result<Self> {
|
||||
let today = NaiveDateTime::new(now.date(), NaiveTime::from_hms(0, 0, 0));
|
||||
|
||||
let datetime = match s {
|
||||
"today" => today,
|
||||
"yesterday" => today - Duration::days(1),
|
||||
// x {second,minute,hour,day,week,month,year}s? ago
|
||||
s if s.ends_with(" ago") => {
|
||||
let re = Regex::new(r"(\d+) ?(s|seconds?|m|min|minutes?|h|hours?|d|days?|w|weeks?|months?|y|years?) ago").unwrap();
|
||||
|
||||
let caps = re.captures(s)
|
||||
.ok_or_else(|| format_err!("Couldn't parse TimeSpec"))?;
|
||||
|
||||
let n = caps.get(1).unwrap().as_str()
|
||||
.parse::<i64>()
|
||||
.context("Failed to parse number in timespec")?;
|
||||
let unit = caps.get(2).unwrap();
|
||||
|
||||
let duration = match unit.as_str() {
|
||||
"s" | "second" | "seconds" => Duration::seconds(n),
|
||||
"m" | "min" | "minute" | "minutes" => Duration::minutes(n),
|
||||
"h" | "hour" | "hours" => Duration::hours(n),
|
||||
"d" | "day" | "days" => Duration::days(n),
|
||||
"w" | "week" | "weeks" => Duration::days(n * 7),
|
||||
"month" | "months" => Duration::days(n * 31),
|
||||
"y" | "year" | "years" => Duration::days(n * 365),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
now - duration
|
||||
},
|
||||
s => NaiveDateTime::from_str(s)?,
|
||||
};
|
||||
|
||||
@@ -35,6 +55,15 @@ impl FromStr for TimeSpec {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for TimeSpec {
|
||||
type Err = Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self> {
|
||||
let now = Utc::now().naive_utc();
|
||||
Self::resolve(s, now)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(global_settings = &[AppSettings::ColoredHelp])]
|
||||
pub struct Args {
|
||||
@@ -86,3 +115,63 @@ impl Cmd for Args {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn datetime() -> NaiveDateTime {
|
||||
let date = chrono::NaiveDate::from_ymd(2020, 3, 14);
|
||||
let time = chrono::NaiveTime::from_hms(16, 20, 23);
|
||||
NaiveDateTime::new(date, time)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_today() {
|
||||
let x = TimeSpec::resolve("today", datetime()).unwrap();
|
||||
assert_eq!(x.datetime, NaiveDateTime::from_str("2020-03-14T00:00:00").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_yesterday() {
|
||||
let x = TimeSpec::resolve("yesterday", datetime()).unwrap();
|
||||
assert_eq!(x.datetime, NaiveDateTime::from_str("2020-03-13T00:00:00").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_20_min_ago() {
|
||||
let x = TimeSpec::resolve("20min ago", datetime()).unwrap();
|
||||
assert_eq!(x.datetime, NaiveDateTime::from_str("2020-03-14T16:00:23").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_3_days_ago() {
|
||||
let x = TimeSpec::resolve("3 days ago", datetime()).unwrap();
|
||||
assert_eq!(x.datetime, NaiveDateTime::from_str("2020-03-11T16:20:23").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_1_week_ago() {
|
||||
let x = TimeSpec::resolve("1w ago", datetime()).unwrap();
|
||||
assert_eq!(x.datetime, NaiveDateTime::from_str("2020-03-07T16:20:23").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_3_months_ago() {
|
||||
let x = TimeSpec::resolve("3 months ago", datetime()).unwrap();
|
||||
assert_eq!(x.datetime, NaiveDateTime::from_str("2019-12-12T16:20:23").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_1_year_ago() {
|
||||
let x = TimeSpec::resolve("1 year ago", datetime()).unwrap();
|
||||
assert_eq!(x.datetime, NaiveDateTime::from_str("2019-03-15T16:20:23").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_exact_time() {
|
||||
let x = TimeSpec::resolve("2020-03-14T16:20:23", datetime()).unwrap();
|
||||
assert_eq!(x.datetime, NaiveDateTime::from_str("2020-03-14T16:20:23").unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use caps::{self, CapSet};
|
||||
use nix;
|
||||
|
||||
#[cfg(target_os = "openbsd")]
|
||||
use pledge::{pledge, Promise, ToPromiseString};
|
||||
use pledge::pledge;
|
||||
#[cfg(target_os = "openbsd")]
|
||||
use unveil::unveil;
|
||||
|
||||
@@ -72,7 +72,7 @@ pub fn init_openbsd() -> Result<()> {
|
||||
unveil("", "")
|
||||
.map_err(|_| format_err!("Failed to call unveil"))?;
|
||||
|
||||
pledge![Stdio, RPath, Dns, Inet]?;
|
||||
pledge![Stdio Rpath Dns Inet,]?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ use std::path::PathBuf;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use std::thread;
|
||||
|
||||
// 1 week
|
||||
const UPDATE_INTERVAL: u64 = 3600 * 24 * 7;
|
||||
// 1 day
|
||||
const UPDATE_INTERVAL: u64 = 3600 * 24;
|
||||
|
||||
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user