From 4dbd00dca2a47461e6f33eb4842cf16e876dc158 Mon Sep 17 00:00:00 2001 From: Kang Seonghoon Date: Fri, 25 Jul 2014 18:12:51 +0900 Subject: [PATCH] added all missing docs. --- src/date.rs | 11 +++++++++++ src/datetime.rs | 24 ++++++++++++++++++++++++ src/duration.rs | 1 + src/lib.rs | 5 +++++ src/time.rs | 1 + 5 files changed, 42 insertions(+) diff --git a/src/date.rs b/src/date.rs index 7605911..4079e42 100644 --- a/src/date.rs +++ b/src/date.rs @@ -16,14 +16,24 @@ static MAX_YEAR: i32 = internals::MAX_YEAR as i32; static MIN_YEAR: i32 = internals::MIN_YEAR as i32; /// The day of week (DOW). +/// +/// The order of the days of week depends on the context. +/// One should prefer `*_from_monday` or `*_from_sunday` methods to get the correct result. #[deriving(PartialEq, Eq, FromPrimitive, Show)] pub enum Weekday { + /// Monday. Mon = 0, + /// Tuesday. Tue = 1, + /// Wednesday. Wed = 2, + /// Thursday. Thu = 3, + /// Friday. Fri = 4, + /// Saturday. Sat = 5, + /// Sunday. Sun = 6, } @@ -113,6 +123,7 @@ impl Weekday { } } +/// The common set of methods for date component. pub trait Datelike { /// Returns the year number. fn year(&self) -> i32; diff --git a/src/datetime.rs b/src/datetime.rs index 529ebff..5c23a44 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -11,6 +11,7 @@ use duration::Duration; use time::{Timelike, TimeZ}; use date::{Datelike, DateZ, Weekday}; +/// ISO 8601 combined date and time. #[deriving(PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct DateTimeZ { date: DateZ, @@ -18,11 +19,15 @@ pub struct DateTimeZ { } impl DateTimeZ { + /// Makes a new `DateTimeZ` from date and time components. #[inline] pub fn new(date: DateZ, time: TimeZ) -> DateTimeZ { DateTimeZ { date: date, time: time } } + /// Makes a new `DateTimeZ` from year, month, day, hour, minute and second. + /// + /// Fails on invalid arguments. #[inline] pub fn from_ymdhms(year: i32, month: u32, day: u32, hour: u32, min: u32, sec: u32) -> DateTimeZ { @@ -30,6 +35,9 @@ impl DateTimeZ { dt.expect("invalid or out-of-range date or time") } + /// Makes a new `DateTimeZ` from year, month, day, hour, minute and second. + /// + /// Returns `None` on invalid arguments. #[inline] pub fn from_ymdhms_opt(year: i32, month: u32, day: u32, hour: u32, min: u32, sec: u32) -> Option { @@ -39,6 +47,9 @@ impl DateTimeZ { } } + /// Makes a new `DateTimeZ` from year, day of year (DOY or "ordinal"), hour, minute and second. + /// + /// Fails on invalid arguments. #[inline] pub fn from_yohms(year: i32, ordinal: u32, hour: u32, min: u32, sec: u32) -> DateTimeZ { @@ -46,6 +57,9 @@ impl DateTimeZ { dt.expect("invalid or out-of-range date or time") } + /// Makes a new `DateTimeZ` from year, day of year (DOY or "ordinal"), hour, minute and second. + /// + /// Returns `None` on invalid arguments. #[inline] pub fn from_yohms_opt(year: i32, ordinal: u32, hour: u32, min: u32, sec: u32) -> Option { @@ -55,6 +69,10 @@ impl DateTimeZ { } } + /// Makes a new `DateTimeZ` from ISO week date (year and week number), day of the week (DOW), + /// hour, minute and second. + /// + /// Fails on invalid arguments. #[inline] pub fn from_isoywdhms(year: i32, week: u32, weekday: Weekday, hour: u32, min: u32, sec: u32) -> DateTimeZ { @@ -62,6 +80,10 @@ impl DateTimeZ { dt.expect("invalid or out-of-range date or time") } + /// Makes a new `DateTimeZ` from ISO week date (year and week number), day of the week (DOW), + /// hour, minute and second. + /// + /// Returns `None` on invalid arguments. #[inline] pub fn from_isoywdhms_opt(year: i32, week: u32, weekday: Weekday, hour: u32, min: u32, sec: u32) -> Option { @@ -71,11 +93,13 @@ impl DateTimeZ { } } + /// Retrieves a `Date` component. #[inline] pub fn date(&self) -> DateZ { self.date } + /// Retrieves a `Time` component. #[inline] pub fn time(&self) -> TimeZ { self.time diff --git a/src/duration.rs b/src/duration.rs index 241ed3f..c6fd298 100644 --- a/src/duration.rs +++ b/src/duration.rs @@ -48,6 +48,7 @@ impl Duration { } /// Makes a new `Duration` with given number of days, seconds and nanoseconds. + /// /// Returns `None` when the duration is out of bounds. pub fn new_opt(days: i32, secs: i32, nanos: i32) -> Option { let (secs_, nanos) = nanos.div_mod_floor(&NANOS_PER_SEC); diff --git a/src/lib.rs b/src/lib.rs index 995a6d7..b80745a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,10 +2,15 @@ // Copyright (c) 2014, Kang Seonghoon. // See README.md and LICENSE.txt for details. +/*! +Experimental date and time handling for Rust. +*/ + #![comment = "Date and time library for Rust"] #![license = "MIT"] #![feature(macro_rules)] +#![deny(missing_doc)] extern crate num; diff --git a/src/time.rs b/src/time.rs index 84b235d..6943899 100644 --- a/src/time.rs +++ b/src/time.rs @@ -10,6 +10,7 @@ use std::fmt; use num::Integer; use duration::Duration; +/// The common set of methods for time component. pub trait Timelike { /// Returns the hour number from 0 to 23. fn hour(&self) -> u32;