pub struct Timestamp(/* private fields */);Expand description
Represents a date and time with microsecond resolution.
Timestamps carry no timezone information; callers must use a consistent time
basis. See Self::new for construction.
Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn new(
date: Date,
hour: u32,
minute: u32,
second: u32,
microsecond: u32,
) -> Result<Self>
pub fn new( date: Date, hour: u32, minute: u32, second: u32, microsecond: u32, ) -> Result<Self>
Creates an instant on a supported date without leap-second support.
§Errors
Returns Error::InvalidInput unless hour is 0..=23, minute and second
are 0..=59, and microsecond is 0..=999_999.
§Examples
use kiyosi::{Date, Timestamp};
let time = Timestamp::new(Date::new(2025, 1, 1)?, 12, 0, 0, 0)?;
assert_eq!(time.micros_since_midnight(), 43_200_000_000);Sourcepub fn add_days(self, days: i64) -> Result<Self>
pub fn add_days(self, days: i64) -> Result<Self>
Returns a timestamp shifted by calendar days, preserving its clock time.
Negative shifts move backward; microseconds are preserved.
§Errors
Returns Error::InvalidInput if the resulting date is outside the
supported years -32767 through 32767.
§Examples
use kiyosi::{Date, Timestamp};
let time = Timestamp::new(Date::new(2025, 12, 31)?, 15, 0, 0, 123_456)?;
let tomorrow = time.add_days(1)?;
assert_eq!(tomorrow.date(), Date::new(2026, 1, 1)?);
assert_eq!(tomorrow.micros_since_midnight(), time.micros_since_midnight());Sourcepub fn date(self) -> Date
pub fn date(self) -> Date
Returns the date containing this instant, including dates before the common era.
See Self::new for construction. This uses calendar-day boundaries,
rather than truncating negative timestamps toward zero.
Sourcepub fn micros_since_midnight(self) -> u64
pub fn micros_since_midnight(self) -> u64
Returns microseconds since midnight on Self::date.
Sourcepub fn time_of_day(self) -> TimeOfDay
pub fn time_of_day(self) -> TimeOfDay
Returns the clock time without its date; see TimeOfDay::new.
Sourcepub fn years_until(self, end: Self) -> f64
pub fn years_until(self, end: Self) -> f64
Returns the signed Actual/365 Fixed year fraction from this instant to end.
Includes elapsed microseconds and counts every day as 1/365 of a year,
including leap days. Earlier endpoints return negative fractions; equal
endpoints return zero. The result rounds to f64 precision.
Both timestamps must use the same caller-selected time basis.
§Examples
use kiyosi::{Date, Timestamp};
let start = Timestamp::new(Date::new(2025, 1, 1)?, 15, 0, 0, 123_456)?;
let end = start.add_days(365)?;
assert_eq!(start.years_until(end), 1.0);
assert_eq!(end.years_until(start), -1.0);Sourcepub fn add_micros(self, micros: i64) -> Result<Self>
pub fn add_micros(self, micros: i64) -> Result<Self>
Shifts this timestamp by a signed number of microseconds.
Crosses calendar-day boundaries while preserving microsecond precision. Negative shifts move backward; zero retains the timestamp.
§Errors
Returns Error::InvalidInput if arithmetic overflows or the result is
outside the supported years -32767 through 32767.
§Examples
use kiyosi::{Date, Timestamp};
let at = Timestamp::new(Date::new(2025, 12, 31)?, 23, 58, 0, 123_456)?;
let later = at.add_micros(5 * 60 * 1_000_000)?;
assert_eq!(later, Timestamp::new(Date::new(2026, 1, 1)?, 0, 3, 0, 123_456)?);
assert_eq!(later.add_micros(-5 * 60 * 1_000_000)?, at);Trait Implementations§
impl Copy for Timestamp
impl Eq for Timestamp
Source§impl Ord for Timestamp
impl Ord for Timestamp
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations§
impl Freeze for Timestamp
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnsafeUnpin for Timestamp
impl UnwindSafe for Timestamp
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more