Skip to content

Commit

Permalink
Fix feature issues
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Sep 11, 2022
1 parent 4ed9a6e commit f3625b5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use alloc::string::{String, ToString};
#[cfg(any(feature = "alloc", feature = "std", test))]
use core::borrow::Borrow;
use core::cmp::Ordering;
#[cfg(feature = "clock")]
use core::convert::TryFrom;
use core::ops::{Add, AddAssign, Sub, SubAssign};
use core::{fmt, hash, str};
Expand Down
16 changes: 7 additions & 9 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use core::fmt;
#[cfg(windows)]
use std::io;

/// Internal representation of the chrono error.
#[derive(Debug)]
Expand All @@ -12,10 +10,10 @@ pub(crate) enum ChronoErrorKind {
AmbiguousDate,
#[cfg(unix)]
MissingDate,
#[cfg(windows)]
#[cfg(all(windows, feature = "clock"))]
SystemTimeBeforeEpoch,
#[cfg(windows)]
SystemError(io::Error),
#[cfg(all(windows, feature = "clock"))]
SystemError(std::io::Error),
}

/// The error raised for an invalid date time.
Expand All @@ -42,9 +40,9 @@ impl fmt::Display for ChronoError {
ChronoErrorKind::AmbiguousDate => write!(f, "tried to operate over ambiguous date"),
#[cfg(unix)]
ChronoErrorKind::MissingDate => write!(f, "missing date"),
#[cfg(windows)]
#[cfg(all(windows, feature = "clock"))]
ChronoErrorKind::SystemTimeBeforeEpoch => write!(f, "system time before Unix epoch"),
#[cfg(windows)]
#[cfg(all(windows, feature = "clock"))]
ChronoErrorKind::SystemError(error) => write!(f, "system error: {error}"),
}
}
Expand All @@ -61,7 +59,7 @@ impl From<ChronoErrorKind> for ChronoError {
impl std::error::Error for ChronoError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match &self.kind {
#[cfg(windows)]
#[cfg(all(windows, feature = "clock"))]
ChronoErrorKind::SystemError(error) => Some(error),
_ => None,
}
Expand All @@ -80,7 +78,7 @@ impl PartialEq for ChronoError {
impl PartialEq for ChronoErrorKind {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
#[cfg(windows)]
#[cfg(all(windows, feature = "clock"))]
(Self::SystemError(l0), Self::SystemError(r0)) => l0.kind() == r0.kind(),
_ => core::mem::discriminant(self) == core::mem::discriminant(other),
}
Expand Down
1 change: 1 addition & 0 deletions src/naive/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ impl NaiveDate {
}

/// Makes a new `NaiveDateTime` with the time set to midnight.
#[cfg(feature = "clock")]
pub(crate) fn and_midnight(&self) -> NaiveDateTime {
self.and_time(NaiveTime::midnight())
}
Expand Down
3 changes: 2 additions & 1 deletion src/offset/utc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ use rkyv::{Archive, Deserialize, Serialize};

use super::{FixedOffset, FixedTimeZone, Offset, TimeZone};
use crate::naive::{NaiveDate, NaiveDateTime};
use crate::{ChronoError, LocalResult};
#[cfg(feature = "clock")]
use crate::{ChronoError, Date, DateTime, LocalResult};
use crate::{Date, DateTime};

/// The UTC time zone. This is the most efficient time zone when you don't need the local time.
/// It is also used as an offset (which is also a dummy type).
Expand Down

0 comments on commit f3625b5

Please sign in to comment.