times.rs 732 B

12345678910111213141516171819202122232425262728
  1. use datetime::TimeZone;
  2. use ansi_term::Style;
  3. use output::cell::TextCell;
  4. use output::time::TimeFormat;
  5. pub trait Render {
  6. fn render(self, style: Style,
  7. tz: &Option<TimeZone>,
  8. format: &TimeFormat) -> TextCell;
  9. }
  10. impl Render for std::time::Duration {
  11. fn render(self, style: Style,
  12. tz: &Option<TimeZone>,
  13. format: &TimeFormat) -> TextCell {
  14. if let Some(ref tz) = *tz {
  15. let datestamp = format.format_zoned(self, tz);
  16. TextCell::paint(style, datestamp)
  17. }
  18. else {
  19. let datestamp = format.format_local(self);
  20. TextCell::paint(style, datestamp)
  21. }
  22. }
  23. }