From 8ceac0236c555979a9172c69c1a9e895d7487d6f Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sat, 17 Dec 2016 15:50:27 +0100 Subject: replace all with subdirectory rust/ --- src/message.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/message.rs (limited to 'src/message.rs') diff --git a/src/message.rs b/src/message.rs new file mode 100644 index 0000000..0af1a13 --- /dev/null +++ b/src/message.rs @@ -0,0 +1,22 @@ +///! Formats the message to be sent to the user +use time::{at_utc, Timespec, strftime}; + + +pub fn format_message(token: String, valid_from: i64, valid_until: i64) -> String { + return format!("Token: {}. Valid from {} until {}", + token, + strftime("%F %X", &at_utc(Timespec::new(valid_from, 0))).unwrap(), + strftime("%F %X", &at_utc(Timespec::new(valid_until, 0))).unwrap()); +} + + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test1() { + assert_eq!(format_message("7A-74-F4".to_string(), 0, 1481831953), + "Token: 7A-74-F4. Valid from 1970-01-01 00:00:00 until 2016-12-15 19:59:13"); + } +} \ No newline at end of file -- cgit v1.2.1