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.

main.rs 841B

2 years ago
123456789101112131415161718192021222324252627282930313233
  1. use structopt::StructOpt;
  2. use chrono::prelude::*;
  3. /// timezone converter
  4. ///
  5. /// Examples:
  6. ///
  7. /// - tzconvert CET EST 2pm
  8. ///
  9. /// - tzconvert Africa/Timbuktu America/Jamaica 18:30 --date 2021-11-03
  10. ///
  11. #[derive(StructOpt, Debug)]
  12. #[structopt(author = env!("CARGO_PKG_AUTHORS"))]
  13. struct Opt {
  14. /// originating time zone
  15. #[structopt(value_name = "FROM TIMEZONE")]
  16. from: String,
  17. /// destination time zone
  18. #[structopt(value_name = "TO TIMEZONE")]
  19. to: String,
  20. /// time to convert (HH:MM or HH[:MM]am/HH[:MM]pm)
  21. #[structopt(value_name = "TIME")]
  22. time: String,
  23. /// specify the date on which the time lies; defaults to today
  24. #[structopt(long, short)]
  25. date: Option<NaiveDate>,
  26. }
  27. fn main() {
  28. let Opt { from, to, time, date } = Opt::from_args();
  29. tzconvert::convert(&from, &to, &time, date);
  30. }