added all missing docs.

This commit is contained in:
Kang Seonghoon 2014-07-25 18:12:51 +09:00
parent 2f35fbc0fd
commit 4dbd00dca2
5 changed files with 42 additions and 0 deletions

View File

@ -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;

View File

@ -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<DateTimeZ> {
@ -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<DateTimeZ> {
@ -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<DateTimeZ> {
@ -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

View File

@ -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<Duration> {
let (secs_, nanos) = nanos.div_mod_floor(&NANOS_PER_SEC);

View File

@ -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;

View File

@ -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;