Add a XEP-0202 implementation.

Fixes #7.
This commit is contained in:
Emmanuel Gil Peyrot 2019-04-22 11:58:13 +02:00
commit 2d7bf32ad4
5 changed files with 138 additions and 0 deletions

View file

@ -15,6 +15,20 @@ use std::str::FromStr;
#[derive(Debug, Clone, PartialEq)]
pub struct DateTime(ChronoDateTime<FixedOffset>);
impl DateTime {
pub fn timezone(&self) -> FixedOffset {
self.0.timezone()
}
pub fn with_timezone(&self, tz: &FixedOffset) -> DateTime {
DateTime(self.0.with_timezone(tz))
}
pub fn format(&self, fmt: &str) -> String {
format!("{}", self.0.format(fmt))
}
}
impl FromStr for DateTime {
type Err = Error;
@ -41,6 +55,7 @@ mod tests {
use chrono::{Datelike, Timelike};
use std::error::Error as StdError;
// DateTimes size doesnt depend on the architecture.
#[test]
fn test_size() {
assert_size!(DateTime, 16);