summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKartikaya Gupta <kats@seldon.staktrace.com>2016-10-02 15:57:14 -0400
committerKartikaya Gupta <kats@seldon.staktrace.com>2016-10-02 15:57:14 -0400
commite3c0114833d796d8ee2880292335363507ab2d1f (patch)
tree4f0e6abaf89cdb33b532f5bb57c2618e4f3009a2 /src
parent01515af53148386182fde97470ac3ad968e83b55 (diff)
Add dateparse documentation
Diffstat (limited to 'src')
-rw-r--r--src/dateparse.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/dateparse.rs b/src/dateparse.rs
index 1ce6e65..786fc1e 100644
--- a/src/dateparse.rs
+++ b/src/dateparse.rs
@@ -64,6 +64,15 @@ fn seconds_to_date(year: i64, month: i64, day: i64) -> i64 {
result + 86400 * (day - 1)
}
+/// Convert a date field from an email header into a UNIX epoch timestamp.
+/// This function handles the most common formatting of date fields found in
+/// email headers. It may fail to parse some of the more creative formattings.
+///
+/// # Examples
+/// ```
+/// use mailparse::dateparse;
+/// assert_eq!(dateparse("Sun, 02 Oct 2016 07:06:22 -0700 (PDT)").unwrap(), 1475417182);
+/// ```
pub fn dateparse(date: &str) -> Result<i64, &'static str> {
let mut result = 0;
let mut month = 0;