|
- use structopt::StructOpt;
- use chrono::prelude::*;
-
- /// timezone converter
- ///
- /// examples:
- ///
- /// - tzconvert CET EST 2pm
- ///
- /// - tzconvert EST CET 1:30pm thu
- ///
- /// - tzconvert Africa/Timbuktu America/Jamaica 18:30 --date 2021-11-03
- ///
- #[derive(StructOpt, Debug)]
- #[structopt(author = env!("CARGO_PKG_AUTHORS"))]
- struct Opt {
- /// originating time zone
- #[structopt(value_name = "FROM TIMEZONE")]
- from: String,
- /// destination time zone
- #[structopt(value_name = "TO TIMEZONE")]
- to: String,
- /// time to convert (%H:%M or %I[:%M]%p)
- #[structopt(value_name = "TIME")]
- time: String,
-
- /// optional: specify day of week the time lies, relative to today.
- ///
- /// this will always result in a DATE greater than or equal to
- /// today (in FROM TIMEZONE).
- ///
- /// example: if today is Thursday, Aug. 26, passing DAY OF WEEK "Friday"/"fri"
- /// will result in a DATE of Friday, Aug. 27.
- #[structopt(value_name = "DAY OF WEEK")]
- day: Option<String>,
-
- /// optional: specify date the time lies. defaults to today.
- ///
- /// when DAY OF WEEK argument is also specified, DAY OF WEEK will be picked relative
- /// to DATE (i.e. the next occuring instance of, on or following DATE).
- #[structopt(long, short, value_name = "DATE")]
- date: Option<NaiveDate>,
- }
-
- fn main() {
- let Opt { from, to, time, date, day } = Opt::from_args();
- tzconvert::convert(&from, &to, &time, day, date);
- }
|