added all missing docs.
This commit is contained in:
parent
2f35fbc0fd
commit
4dbd00dca2
11
src/date.rs
11
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;
|
static MIN_YEAR: i32 = internals::MIN_YEAR as i32;
|
||||||
|
|
||||||
/// The day of week (DOW).
|
/// 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)]
|
#[deriving(PartialEq, Eq, FromPrimitive, Show)]
|
||||||
pub enum Weekday {
|
pub enum Weekday {
|
||||||
|
/// Monday.
|
||||||
Mon = 0,
|
Mon = 0,
|
||||||
|
/// Tuesday.
|
||||||
Tue = 1,
|
Tue = 1,
|
||||||
|
/// Wednesday.
|
||||||
Wed = 2,
|
Wed = 2,
|
||||||
|
/// Thursday.
|
||||||
Thu = 3,
|
Thu = 3,
|
||||||
|
/// Friday.
|
||||||
Fri = 4,
|
Fri = 4,
|
||||||
|
/// Saturday.
|
||||||
Sat = 5,
|
Sat = 5,
|
||||||
|
/// Sunday.
|
||||||
Sun = 6,
|
Sun = 6,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +123,7 @@ impl Weekday {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The common set of methods for date component.
|
||||||
pub trait Datelike {
|
pub trait Datelike {
|
||||||
/// Returns the year number.
|
/// Returns the year number.
|
||||||
fn year(&self) -> i32;
|
fn year(&self) -> i32;
|
||||||
|
|
|
@ -11,6 +11,7 @@ use duration::Duration;
|
||||||
use time::{Timelike, TimeZ};
|
use time::{Timelike, TimeZ};
|
||||||
use date::{Datelike, DateZ, Weekday};
|
use date::{Datelike, DateZ, Weekday};
|
||||||
|
|
||||||
|
/// ISO 8601 combined date and time.
|
||||||
#[deriving(PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[deriving(PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct DateTimeZ {
|
pub struct DateTimeZ {
|
||||||
date: DateZ,
|
date: DateZ,
|
||||||
|
@ -18,11 +19,15 @@ pub struct DateTimeZ {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DateTimeZ {
|
impl DateTimeZ {
|
||||||
|
/// Makes a new `DateTimeZ` from date and time components.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(date: DateZ, time: TimeZ) -> DateTimeZ {
|
pub fn new(date: DateZ, time: TimeZ) -> DateTimeZ {
|
||||||
DateTimeZ { date: date, time: time }
|
DateTimeZ { date: date, time: time }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Makes a new `DateTimeZ` from year, month, day, hour, minute and second.
|
||||||
|
///
|
||||||
|
/// Fails on invalid arguments.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_ymdhms(year: i32, month: u32, day: u32,
|
pub fn from_ymdhms(year: i32, month: u32, day: u32,
|
||||||
hour: u32, min: u32, sec: u32) -> DateTimeZ {
|
hour: u32, min: u32, sec: u32) -> DateTimeZ {
|
||||||
|
@ -30,6 +35,9 @@ impl DateTimeZ {
|
||||||
dt.expect("invalid or out-of-range date or time")
|
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]
|
#[inline]
|
||||||
pub fn from_ymdhms_opt(year: i32, month: u32, day: u32,
|
pub fn from_ymdhms_opt(year: i32, month: u32, day: u32,
|
||||||
hour: u32, min: u32, sec: u32) -> Option<DateTimeZ> {
|
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]
|
#[inline]
|
||||||
pub fn from_yohms(year: i32, ordinal: u32,
|
pub fn from_yohms(year: i32, ordinal: u32,
|
||||||
hour: u32, min: u32, sec: u32) -> DateTimeZ {
|
hour: u32, min: u32, sec: u32) -> DateTimeZ {
|
||||||
|
@ -46,6 +57,9 @@ impl DateTimeZ {
|
||||||
dt.expect("invalid or out-of-range date or time")
|
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]
|
#[inline]
|
||||||
pub fn from_yohms_opt(year: i32, ordinal: u32,
|
pub fn from_yohms_opt(year: i32, ordinal: u32,
|
||||||
hour: u32, min: u32, sec: u32) -> Option<DateTimeZ> {
|
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]
|
#[inline]
|
||||||
pub fn from_isoywdhms(year: i32, week: u32, weekday: Weekday,
|
pub fn from_isoywdhms(year: i32, week: u32, weekday: Weekday,
|
||||||
hour: u32, min: u32, sec: u32) -> DateTimeZ {
|
hour: u32, min: u32, sec: u32) -> DateTimeZ {
|
||||||
|
@ -62,6 +80,10 @@ impl DateTimeZ {
|
||||||
dt.expect("invalid or out-of-range date or time")
|
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]
|
#[inline]
|
||||||
pub fn from_isoywdhms_opt(year: i32, week: u32, weekday: Weekday,
|
pub fn from_isoywdhms_opt(year: i32, week: u32, weekday: Weekday,
|
||||||
hour: u32, min: u32, sec: u32) -> Option<DateTimeZ> {
|
hour: u32, min: u32, sec: u32) -> Option<DateTimeZ> {
|
||||||
|
@ -71,11 +93,13 @@ impl DateTimeZ {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieves a `Date` component.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn date(&self) -> DateZ {
|
pub fn date(&self) -> DateZ {
|
||||||
self.date
|
self.date
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Retrieves a `Time` component.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn time(&self) -> TimeZ {
|
pub fn time(&self) -> TimeZ {
|
||||||
self.time
|
self.time
|
||||||
|
|
|
@ -48,6 +48,7 @@ impl Duration {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Makes a new `Duration` with given number of days, seconds and nanoseconds.
|
/// Makes a new `Duration` with given number of days, seconds and nanoseconds.
|
||||||
|
///
|
||||||
/// Returns `None` when the duration is out of bounds.
|
/// Returns `None` when the duration is out of bounds.
|
||||||
pub fn new_opt(days: i32, secs: i32, nanos: i32) -> Option<Duration> {
|
pub fn new_opt(days: i32, secs: i32, nanos: i32) -> Option<Duration> {
|
||||||
let (secs_, nanos) = nanos.div_mod_floor(&NANOS_PER_SEC);
|
let (secs_, nanos) = nanos.div_mod_floor(&NANOS_PER_SEC);
|
||||||
|
|
|
@ -2,10 +2,15 @@
|
||||||
// Copyright (c) 2014, Kang Seonghoon.
|
// Copyright (c) 2014, Kang Seonghoon.
|
||||||
// See README.md and LICENSE.txt for details.
|
// See README.md and LICENSE.txt for details.
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Experimental date and time handling for Rust.
|
||||||
|
*/
|
||||||
|
|
||||||
#![comment = "Date and time library for Rust"]
|
#![comment = "Date and time library for Rust"]
|
||||||
#![license = "MIT"]
|
#![license = "MIT"]
|
||||||
|
|
||||||
#![feature(macro_rules)]
|
#![feature(macro_rules)]
|
||||||
|
#![deny(missing_doc)]
|
||||||
|
|
||||||
extern crate num;
|
extern crate num;
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ use std::fmt;
|
||||||
use num::Integer;
|
use num::Integer;
|
||||||
use duration::Duration;
|
use duration::Duration;
|
||||||
|
|
||||||
|
/// The common set of methods for time component.
|
||||||
pub trait Timelike {
|
pub trait Timelike {
|
||||||
/// Returns the hour number from 0 to 23.
|
/// Returns the hour number from 0 to 23.
|
||||||
fn hour(&self) -> u32;
|
fn hour(&self) -> u32;
|
||||||
|
|
Loading…
Reference in New Issue