Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ chain-ser = { git = "https://github.com/input-output-hk/chain-libs.git", branch
chain-storage = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-time = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chain-impl-mockchain = { git = "https://github.com/input-output-hk/chain-libs.git", branch = "master" }
chrono = "0.4"
time = { version = "0.3", features = ["formatting", "parsing", "macros"] }
itertools = "0.10"
jcli = { git = "https://github.com/input-output-hk/jormungandr.git", branch = "master" }
jormungandr-lib = { git = "https://github.com/input-output-hk/jormungandr.git", branch = "master" }
Expand Down
18 changes: 11 additions & 7 deletions src/bin/cli/logs/sentry/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use jcli_lib::utils::io::open_file_write;

use std::path::PathBuf;

use chrono::{DateTime, FixedOffset};
use std::str::FromStr;
use structopt::StructOpt;
use time::OffsetDateTime;
use url::Url;

const DATE_TIME_TAG: &str = "dateCreated";
Expand All @@ -19,11 +19,11 @@ pub enum Mode {
#[derive(StructOpt)]
pub struct DateFilter {
// Optional [From, To] date range, start
#[structopt(long, parse(try_from_str = DateTime::parse_from_rfc3339))]
from: Option<DateTime<FixedOffset>>,
#[structopt(long, parse(try_from_str = parse_datetime_from_rfc3339))]
from: Option<OffsetDateTime>,
// Optional [From, To] date range, end
#[structopt(long, parse( try_from_str = DateTime::parse_from_rfc3339))]
to: Option<DateTime<FixedOffset>>,
#[structopt(long, parse( try_from_str = parse_datetime_from_rfc3339))]
to: Option<OffsetDateTime>,
}

#[derive(StructOpt)]
Expand Down Expand Up @@ -165,12 +165,16 @@ fn dump_logs_to_json(logs: &[RawLog], out: PathBuf) -> Result<(), Error> {
Ok(())
}

fn date_time_from_raw_log(l: &RawLog) -> DateTime<FixedOffset> {
DateTime::parse_from_rfc3339(
fn date_time_from_raw_log(l: &RawLog) -> OffsetDateTime {
parse_datetime_from_rfc3339(
l.get(DATE_TIME_TAG)
.expect("A dateCreated entry should be present in sentry logs")
.as_str()
.expect("dateCreated should be a str"),
)
.expect("A rfc3339 compatible DateTime str")
}

fn parse_datetime_from_rfc3339(datetime: &str) -> Result<OffsetDateTime, time::error::Parse> {
OffsetDateTime::parse(datetime, &time::format_description::well_known::Rfc3339)
}
10 changes: 5 additions & 5 deletions src/bin/cli/notifications/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use catalyst_toolbox::notifications::{
};
use jcli_lib::utils::io;

use chrono::{DateTime, FixedOffset};
use reqwest::Url;
use structopt::StructOpt;
use time::OffsetDateTime;

use std::io::Read;
use std::path::PathBuf;
Expand All @@ -39,8 +39,8 @@ pub struct Args {
application: String,

/// Date and time to send notification of format "Y-m-d H:M"
#[structopt(long, parse(try_from_str=parse_date_time))]
send_date: Option<DateTime<FixedOffset>>,
#[structopt(long, parse(try_from_str=parse_datetime))]
send_date: Option<OffsetDateTime>,

/// Ignore user timezones when sending a message
#[structopt(long)]
Expand Down Expand Up @@ -144,6 +144,6 @@ impl Content {
}
}

fn parse_date_time(dt: &str) -> chrono::ParseResult<DateTime<FixedOffset>> {
DateTime::parse_from_str(dt, DATETIME_FMT)
fn parse_datetime(dt: &str) -> Result<OffsetDateTime, time::error::Parse> {
OffsetDateTime::parse(dt, &DATETIME_FMT)
}
15 changes: 6 additions & 9 deletions src/notifications/requests/create_message.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use chrono::DateTime;
use serde::{Deserialize, Serialize};

use std::collections::HashMap;
use std::fmt::Display;
use time::{format_description::FormatItem, macros::format_description, OffsetDateTime};

use thiserror::Error;

pub const DATETIME_FMT: &str = "%Y-%m-%d %H:%M";
pub const DATETIME_FMT: &[FormatItem] = format_description!("[year]-[month]-[day] [hour]:[minute]");

#[allow(clippy::large_enum_variant)]
#[derive(Debug, Error)]
Expand Down Expand Up @@ -80,12 +79,10 @@ impl ContentSettingsBuilder {
Self::default()
}

pub fn with_send_date<Tz>(mut self, datetime: DateTime<Tz>) -> Self
where
Tz: chrono::TimeZone,
Tz::Offset: Display,
{
self.send_date = datetime.format("%Y-%m-%d %H:%M").to_string();
pub fn with_send_date(mut self, datetime: OffsetDateTime) -> Self {
self.send_date = datetime
.format(&DATETIME_FMT)
.expect("could not format date");
self
}

Expand Down