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.

43 lines
1.2KB

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