You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4KB

  1. use structopt::StructOpt;
  2. use chrono::prelude::*;
  3. /// timezone converter
  4. ///
  5. /// examples:
  6. ///
  7. /// - tzconvert CET EST 2pm
  8. ///
  9. /// - tzconvert EST CET 1:30pm thu
  10. ///
  11. /// - tzconvert Africa/Timbuktu America/Jamaica 18:30 --date 2021-11-03
  12. ///
  13. #[derive(StructOpt, Debug)]
  14. #[structopt(author = env!("CARGO_PKG_AUTHORS"))]
  15. struct Opt {
  16. /// originating time zone
  17. #[structopt(value_name = "FROM TIMEZONE")]
  18. from: String,
  19. /// destination time zone
  20. #[structopt(value_name = "TO TIMEZONE")]
  21. to: String,
  22. /// time to convert (%H:%M or %I[:%M]%p)
  23. #[structopt(value_name = "TIME")]
  24. time: String,
  25. /// optional: specify day of week the time lies, relative to today.
  26. ///
  27. /// this will always result in a DATE greater than or equal to
  28. /// today (in FROM TIMEZONE).
  29. ///
  30. /// example: if today is Thursday, Aug. 26, passing DAY OF WEEK "Friday"/"fri"
  31. /// will result in a DATE of Friday, Aug. 27.
  32. #[structopt(value_name = "DAY OF WEEK")]
  33. day: Option<String>,
  34. /// optional: specify date the time lies. defaults to today.
  35. ///
  36. /// when DAY OF WEEK argument is also specified, DAY OF WEEK will be picked relative
  37. /// to DATE (i.e. the next occuring instance of, on or following DATE).
  38. #[structopt(long, short, value_name = "DATE")]
  39. date: Option<NaiveDate>,
  40. }
  41. fn main() {
  42. let Opt { from, to, time, date, day } = Opt::from_args();
  43. tzconvert::convert(&from, &to, &time, day, date);
  44. }