Skip to content

Commit

Permalink
Add UNIX_EPOCH constants
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Sep 15, 2023
1 parent 1df8db3 commit 46ad2c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/datetime/mod.rs
Expand Up @@ -623,6 +623,9 @@ impl DateTime<Utc> {
pub fn from_timestamp(secs: i64, nsecs: u32) -> Option<Self> {
NaiveDateTime::from_timestamp_opt(secs, nsecs).as_ref().map(NaiveDateTime::and_utc)
}

/// The Unix Epoch, 1970-01-01 00:00:00 UTC.
pub const UNIX_EPOCH: Self = Self { datetime: NaiveDateTime::UNIX_EPOCH, offset: Utc };
}

impl Default for DateTime<Utc> {
Expand Down
7 changes: 6 additions & 1 deletion src/naive/datetime/mod.rs
Expand Up @@ -20,7 +20,7 @@ use crate::format::{parse, parse_and_remainder, ParseError, ParseResult, Parsed,
use crate::format::{Fixed, Item, Numeric, Pad};
use crate::naive::{Days, IsoWeek, NaiveDate, NaiveTime};
use crate::offset::Utc;
use crate::{DateTime, Datelike, LocalResult, Months, TimeZone, Timelike, Weekday};
use crate::{expect, DateTime, Datelike, LocalResult, Months, TimeZone, Timelike, Weekday};

#[cfg(feature = "rustc-serialize")]
pub(super) mod rustc_serialize;
Expand Down Expand Up @@ -967,8 +967,13 @@ impl NaiveDateTime {

/// The minimum possible `NaiveDateTime`.
pub const MIN: Self = Self { date: NaiveDate::MIN, time: NaiveTime::MIN };

/// The maximum possible `NaiveDateTime`.
pub const MAX: Self = Self { date: NaiveDate::MAX, time: NaiveTime::MAX };

/// The Unix Epoch, 1970-01-01 00:00:00.
pub const UNIX_EPOCH: Self =
expect!(NaiveDate::from_ymd_opt(1970, 1, 1), "").and_time(NaiveTime::MIN);
}

impl Datelike for NaiveDateTime {
Expand Down

0 comments on commit 46ad2c2

Please sign in to comment.