Created
September 30, 2018 23:08
-
-
Save skorgu/32b65d7f3866775fc3fe05550e34d41e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate chrono; | |
extern crate structopt; | |
extern crate time; | |
#[macro_use] | |
extern crate structopt_derive; | |
use chrono::prelude::*; | |
use time::Duration; | |
use structopt::StructOpt; | |
use std::io::Write; | |
#[derive(StructOpt, Debug)] | |
#[structopt(name = "dateseq", about = "Generate a list of timestamps like seq.")] | |
struct Opt { | |
/// A flag, true if used in the command line. | |
#[structopt(short = "d", long = "debug", help = "Activate debug mode")] | |
debug: bool, | |
#[structopt(short = "f", long = "format", help = "strftime format string", default_value = "%+")] | |
format: String, | |
#[structopt(short = "i", long = "increment", help = "seconds to increment by", default_value = "86400")] | |
increment: i64, | |
/// Needed parameter, the first on the command line. | |
#[structopt(help = "Begin time")] | |
begin: DateTime<Local>, | |
/// Needed parameter, the first on the command line. | |
#[structopt(help = "End time")] | |
end: DateTime<Local>, | |
} | |
fn main() { | |
let mut stderr = std::io::stderr(); | |
let opt = Opt::from_args(); | |
if opt.debug { | |
writeln!(&mut stderr, "{:?}", opt).unwrap(); | |
} | |
let mut i = opt.begin.clone(); | |
let dur = Duration::seconds(opt.increment); | |
while i < opt.end { | |
i = i + dur; | |
let printme = i.format(opt.format.as_str()).to_string(); | |
println!("{}", printme); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment