Struct nt_time::FileTime

source ·
pub struct FileTime(_);
Expand description

FileTime is a type that represents the Windows NT system time.

This is a 64-bit unsigned integer value that represents the number of 100-nanosecond intervals that have elapsed since “1601-01-01 00:00:00 UTC”.

Implementations§

source§

impl FileTime

source

pub const NT_EPOCH: Self = _

The NT time epoch.

This is defined as “1601-01-01 00:00:00 UTC”.

Examples
assert_eq!(
    OffsetDateTime::try_from(FileTime::NT_EPOCH).unwrap(),
    PrimitiveDateTime::new(
        Date::from_calendar_date(1601, Month::January, 1).unwrap(),
        Time::MIDNIGHT
    )
    .assume_utc()
);
source

pub const UNIX_EPOCH: Self = _

The Unix epoch.

This is defined as “1970-01-01 00:00:00 UTC”.

Examples
assert_eq!(
    OffsetDateTime::try_from(FileTime::UNIX_EPOCH).unwrap(),
    OffsetDateTime::UNIX_EPOCH
);
source

pub const MAX: Self = _

The largest value that can be represented by the Windows NT system time.

This is “+60056-05-28 05:36:10.955161500 UTC”.

Examples
assert_eq!(
    OffsetDateTime::try_from(FileTime::MAX).unwrap(),
    PrimitiveDateTime::new(
        Date::from_calendar_date(60056, Month::May, 28).unwrap(),
        Time::from_hms_nano(5, 36, 10, 955_161_500).unwrap()
    )
    .assume_utc()
);
source

pub fn now() -> Self

Available on crate feature std only.

Returns the Windows NT system time corresponding to “now”.

Panics

Panics if “now” is out of range for the Windows NT system time.

Examples
let now = FileTime::now();
source

pub const fn new(time: u64) -> Self

Creates a new FileTime with the given Windows NT system time.

Examples
assert_eq!(FileTime::new(u64::MIN), FileTime::NT_EPOCH);
assert_eq!(FileTime::new(116_444_736_000_000_000), FileTime::UNIX_EPOCH);
assert_eq!(FileTime::new(u64::MAX), FileTime::MAX);
source

pub const fn as_u64(self) -> u64

Returns the contents of this FileTime as the underlying u64 value.

Examples
assert_eq!(FileTime::NT_EPOCH.as_u64(), u64::MIN);
assert_eq!(FileTime::UNIX_EPOCH.as_u64(), 116_444_736_000_000_000);
assert_eq!(FileTime::MAX.as_u64(), u64::MAX);
source

pub fn checked_add(self, rhs: Duration) -> Option<Self>

Computes self + rhs, returning None if overflow occurred.

Examples
assert_eq!(
    FileTime::NT_EPOCH.checked_add(Duration::from_nanos(1)),
    Some(FileTime::NT_EPOCH)
);
assert_eq!(
    FileTime::NT_EPOCH.checked_add(Duration::from_nanos(100)),
    Some(FileTime::new(1))
);

assert_eq!(FileTime::MAX.checked_add(Duration::from_nanos(100)), None);
source

pub fn checked_sub(self, rhs: Duration) -> Option<Self>

Computes self - rhs, returning None if the result would be negative or if overflow occurred.

Examples
assert_eq!(
    FileTime::MAX.checked_sub(Duration::from_nanos(1)),
    Some(FileTime::MAX)
);
assert_eq!(
    FileTime::MAX.checked_sub(Duration::from_nanos(100)),
    Some(FileTime::new(u64::MAX - 1))
);

assert_eq!(
    FileTime::NT_EPOCH.checked_sub(Duration::from_nanos(100)),
    None
);
source

pub fn saturating_add(self, rhs: Duration) -> Self

Computes self + rhs, returning FileTime::MAX if overflow occurred.

Examples
assert_eq!(
    FileTime::NT_EPOCH.saturating_add(Duration::from_nanos(1)),
    FileTime::NT_EPOCH
);
assert_eq!(
    FileTime::NT_EPOCH.saturating_add(Duration::from_nanos(100)),
    FileTime::new(1)
);

assert_eq!(
    FileTime::MAX.saturating_add(Duration::from_nanos(100)),
    FileTime::MAX
);
source

pub fn saturating_sub(self, rhs: Duration) -> Self

Computes self - rhs, returning FileTime::NT_EPOCH if the result would be negative or if overflow occurred.

Examples
assert_eq!(
    FileTime::MAX.saturating_sub(Duration::from_nanos(1)),
    FileTime::MAX
);
assert_eq!(
    FileTime::MAX.saturating_sub(Duration::from_nanos(100)),
    FileTime::new(u64::MAX - 1)
);

assert_eq!(
    FileTime::NT_EPOCH.saturating_sub(Duration::from_nanos(100)),
    FileTime::NT_EPOCH
);
source

pub const fn to_be_bytes(self) -> [u8; 8]

Returns the memory representation of this FileTime as a byte array in big-endian byte order.

Examples
assert_eq!(FileTime::NT_EPOCH.to_be_bytes(), [u8::MIN; 8]);
assert_eq!(
    FileTime::UNIX_EPOCH.to_be_bytes(),
    [0x01, 0x9d, 0xb1, 0xde, 0xd5, 0x3e, 0x80, 0x00]
);
assert_eq!(FileTime::MAX.to_be_bytes(), [u8::MAX; 8]);
source

pub const fn to_le_bytes(self) -> [u8; 8]

Returns the memory representation of this FileTime as a byte array in little-endian byte order.

Examples
assert_eq!(FileTime::NT_EPOCH.to_le_bytes(), [u8::MIN; 8]);
assert_eq!(
    FileTime::UNIX_EPOCH.to_le_bytes(),
    [0x00, 0x80, 0x3e, 0xd5, 0xde, 0xb1, 0x9d, 0x01]
);
assert_eq!(FileTime::MAX.to_le_bytes(), [u8::MAX; 8]);
source

pub const fn from_be_bytes(bytes: [u8; 8]) -> Self

Creates a native endian FileTime value from its representation as a byte array in big-endian.

Examples
assert_eq!(FileTime::from_be_bytes([u8::MIN; 8]), FileTime::NT_EPOCH);
assert_eq!(
    FileTime::from_be_bytes([0x01, 0x9d, 0xb1, 0xde, 0xd5, 0x3e, 0x80, 0x00]),
    FileTime::UNIX_EPOCH
);
assert_eq!(FileTime::from_be_bytes([u8::MAX; 8]), FileTime::MAX);
source

pub const fn from_le_bytes(bytes: [u8; 8]) -> Self

Creates a native endian FileTime value from its representation as a byte array in little-endian.

Examples
assert_eq!(FileTime::from_le_bytes([u8::MIN; 8]), FileTime::NT_EPOCH);
assert_eq!(
    FileTime::from_le_bytes([0x00, 0x80, 0x3e, 0xd5, 0xde, 0xb1, 0x9d, 0x01]),
    FileTime::UNIX_EPOCH
);
assert_eq!(FileTime::from_le_bytes([u8::MAX; 8]), FileTime::MAX);

Trait Implementations§

source§

impl Add<Duration> for FileTime

§

type Output = FileTime

The resulting type after applying the + operator.
source§

fn add(self, rhs: Duration) -> Self::Output

Performs the + operation. Read more
source§

impl Add<Duration> for FileTime

§

type Output = FileTime

The resulting type after applying the + operator.
source§

fn add(self, rhs: Duration) -> Self::Output

Performs the + operation. Read more
source§

impl AddAssign<Duration> for FileTime

source§

fn add_assign(&mut self, rhs: Duration)

Performs the += operation. Read more
source§

impl AddAssign<Duration> for FileTime

source§

fn add_assign(&mut self, rhs: Duration)

Performs the += operation. Read more
source§

impl Clone for FileTime

source§

fn clone(&self) -> FileTime

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for FileTime

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for FileTime

source§

fn default() -> Self

Returns the default value of “1601-01-01 00:00:00 UTC”.

Equivalent to FileTime::NT_EPOCH except that it is not callable in const contexts.

Examples
assert_eq!(FileTime::default(), FileTime::NT_EPOCH);
source§

impl Display for FileTime

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Shows the underlying u64 value of this FileTime.

Examples
assert_eq!(format!("{}", FileTime::NT_EPOCH), "0");
assert_eq!(format!("{}", FileTime::UNIX_EPOCH), "116444736000000000");
assert_eq!(format!("{}", FileTime::MAX), "18446744073709551615");
source§

impl From<FileTime> for DateTime<Utc>

Available on crate feature chrono only.
source§

fn from(time: FileTime) -> Self

Converts a FileTime to a DateTime<Utc>.

Examples
assert_eq!(
    DateTime::<Utc>::from(FileTime::NT_EPOCH),
    Utc.with_ymd_and_hms(1601, 1, 1, 0, 0, 0).unwrap()
);
assert_eq!(
    DateTime::<Utc>::from(FileTime::UNIX_EPOCH),
    Utc.timestamp_opt(0, 0).unwrap()
);
source§

impl From<FileTime> for SystemTime

Available on crate feature std only.
source§

fn from(time: FileTime) -> Self

Converts a FileTime to a SystemTime.

Panics

Panics if the resulting point in time cannot be represented by the underlying OS-specific time format.

Examples
assert_eq!(
    SystemTime::from(FileTime::NT_EPOCH),
    SystemTime::UNIX_EPOCH - Duration::from_secs(11_644_473_600)
);
assert_eq!(
    SystemTime::from(FileTime::UNIX_EPOCH),
    SystemTime::UNIX_EPOCH
);
source§

impl From<FileTime> for u64

source§

fn from(time: FileTime) -> Self

Converts a FileTime to the Windows NT system time.

Equivalent to FileTime::as_u64 except that it is not callable in const contexts.

Examples
assert_eq!(u64::from(FileTime::NT_EPOCH), u64::MIN);
assert_eq!(u64::from(FileTime::UNIX_EPOCH), 116_444_736_000_000_000);
assert_eq!(u64::from(FileTime::MAX), u64::MAX);
source§

impl From<u64> for FileTime

source§

fn from(time: u64) -> Self

Converts the Windows NT system time to a FileTime.

Equivalent to FileTime::new except that it is not callable in const contexts.

Examples
assert_eq!(FileTime::from(u64::MIN), FileTime::NT_EPOCH);
assert_eq!(
    FileTime::from(116_444_736_000_000_000),
    FileTime::UNIX_EPOCH
);
assert_eq!(FileTime::from(u64::MAX), FileTime::MAX);
source§

impl Hash for FileTime

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for FileTime

source§

fn cmp(&self, other: &FileTime) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<DateTime<Utc>> for FileTime

Available on crate feature chrono only.
source§

fn eq(&self, other: &DateTime<Utc>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<FileTime> for DateTime<Utc>

Available on crate feature chrono only.
source§

fn eq(&self, other: &FileTime) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<FileTime> for FileTime

source§

fn eq(&self, other: &FileTime) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<FileTime> for OffsetDateTime

source§

fn eq(&self, other: &FileTime) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<FileTime> for SystemTime

Available on crate feature std only.
source§

fn eq(&self, other: &FileTime) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<OffsetDateTime> for FileTime

source§

fn eq(&self, other: &OffsetDateTime) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<SystemTime> for FileTime

Available on crate feature std only.
source§

fn eq(&self, other: &SystemTime) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<DateTime<Utc>> for FileTime

Available on crate feature chrono only.
source§

fn partial_cmp(&self, other: &DateTime<Utc>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<FileTime> for DateTime<Utc>

Available on crate feature chrono only.
source§

fn partial_cmp(&self, other: &FileTime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<FileTime> for FileTime

source§

fn partial_cmp(&self, other: &FileTime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<FileTime> for OffsetDateTime

source§

fn partial_cmp(&self, other: &FileTime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<FileTime> for SystemTime

Available on crate feature std only.
source§

fn partial_cmp(&self, other: &FileTime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<OffsetDateTime> for FileTime

source§

fn partial_cmp(&self, other: &OffsetDateTime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<SystemTime> for FileTime

Available on crate feature std only.
source§

fn partial_cmp(&self, other: &SystemTime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub<DateTime<Utc>> for FileTime

Available on crate feature chrono only.
§

type Output = Duration

The resulting type after applying the - operator.
source§

fn sub(self, rhs: DateTime<Utc>) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<Duration> for FileTime

§

type Output = FileTime

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Duration) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<Duration> for FileTime

§

type Output = FileTime

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Duration) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<FileTime> for DateTime<Utc>

Available on crate feature chrono only.
§

type Output = Duration

The resulting type after applying the - operator.
source§

fn sub(self, rhs: FileTime) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<FileTime> for FileTime

§

type Output = Duration

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<FileTime> for OffsetDateTime

§

type Output = Duration

The resulting type after applying the - operator.
source§

fn sub(self, rhs: FileTime) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<FileTime> for SystemTime

Available on crate feature std only.
§

type Output = Duration

The resulting type after applying the - operator.
source§

fn sub(self, rhs: FileTime) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<OffsetDateTime> for FileTime

§

type Output = Duration

The resulting type after applying the - operator.
source§

fn sub(self, rhs: OffsetDateTime) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<SystemTime> for FileTime

Available on crate feature std only.
§

type Output = Duration

The resulting type after applying the - operator.
source§

fn sub(self, rhs: SystemTime) -> Self::Output

Performs the - operation. Read more
source§

impl SubAssign<Duration> for FileTime

source§

fn sub_assign(&mut self, rhs: Duration)

Performs the -= operation. Read more
source§

impl SubAssign<Duration> for FileTime

source§

fn sub_assign(&mut self, rhs: Duration)

Performs the -= operation. Read more
source§

impl TryFrom<DateTime<Utc>> for FileTime

Available on crate feature chrono only.
source§

fn try_from(dt: DateTime<Utc>) -> Result<Self, Self::Error>

Converts a DateTime<Utc> to a FileTime.

Errors

Returns Err if dt is out of range for the Windows NT system time.

Examples
assert_eq!(
    FileTime::try_from(Utc.with_ymd_and_hms(1601, 1, 1, 0, 0, 0).unwrap()).unwrap(),
    FileTime::NT_EPOCH
);
assert_eq!(
    FileTime::try_from(Utc.timestamp_opt(0, 0).unwrap()).unwrap(),
    FileTime::UNIX_EPOCH
);

assert!(FileTime::try_from(
    Utc.with_ymd_and_hms(1601, 1, 1, 0, 0, 0).unwrap() - Duration::nanoseconds(1)
)
.is_err());

assert!(FileTime::try_from(
    Utc.with_ymd_and_hms(60056, 5, 28, 5, 36, 10).unwrap()
        + Duration::nanoseconds(955_161_500)
        + Duration::nanoseconds(100)
)
.is_err());
§

type Error = FileTimeRangeError

The type returned in the event of a conversion error.
source§

impl TryFrom<FileTime> for OffsetDateTime

source§

fn try_from(time: FileTime) -> Result<Self, Self::Error>

Converts a FileTime to a OffsetDateTime.

Errors

Returns Err if time is out of range for OffsetDateTime.

Examples
assert_eq!(
    OffsetDateTime::try_from(FileTime::NT_EPOCH).unwrap(),
    PrimitiveDateTime::new(
        Date::from_calendar_date(1601, Month::January, 1).unwrap(),
        Time::MIDNIGHT
    )
    .assume_utc()
);
assert_eq!(
    OffsetDateTime::try_from(FileTime::UNIX_EPOCH).unwrap(),
    OffsetDateTime::UNIX_EPOCH
);

With the large-dates feature disabled, returns Err if the Windows NT system time represents after “9999-12-31 23:59:59.999999900 UTC”:

assert!(OffsetDateTime::try_from(FileTime::new(2_650_467_744_000_000_000)).is_err());

With the large-dates feature enabled, this always succeeds:

assert_eq!(
    OffsetDateTime::try_from(FileTime::new(2_650_467_744_000_000_000)).unwrap(),
    PrimitiveDateTime::new(
        Date::from_calendar_date(10000, Month::January, 1).unwrap(),
        Time::MIDNIGHT
    )
    .assume_utc()
);
assert_eq!(
    OffsetDateTime::try_from(FileTime::MAX).unwrap(),
    PrimitiveDateTime::new(
        Date::from_calendar_date(60056, Month::May, 28).unwrap(),
        Time::from_hms_nano(5, 36, 10, 955_161_500).unwrap()
    )
    .assume_utc()
);
§

type Error = OffsetDateTimeRangeError

The type returned in the event of a conversion error.
source§

impl TryFrom<OffsetDateTime> for FileTime

source§

fn try_from(dt: OffsetDateTime) -> Result<Self, Self::Error>

Converts a OffsetDateTime to a FileTime.

Errors

Returns Err if dt is out of range for the Windows NT system time.

Examples
assert_eq!(
    FileTime::try_from(
        PrimitiveDateTime::new(
            Date::from_calendar_date(1601, Month::January, 1).unwrap(),
            Time::MIDNIGHT
        )
        .assume_utc()
    )
    .unwrap(),
    FileTime::NT_EPOCH
);
assert_eq!(
    FileTime::try_from(OffsetDateTime::UNIX_EPOCH).unwrap(),
    FileTime::UNIX_EPOCH
);

assert!(FileTime::try_from(
    PrimitiveDateTime::new(
        Date::from_calendar_date(1601, Month::January, 1).unwrap(),
        Time::MIDNIGHT
    )
    .assume_utc()
        - Duration::NANOSECOND
)
.is_err());

With the large-dates feature enabled, returns Err if OffsetDateTime represents after “+60056-05-28 05:36:10.955161500 UTC”:

assert!(FileTime::try_from(
    PrimitiveDateTime::new(
        Date::from_calendar_date(60056, Month::May, 28).unwrap(),
        Time::from_hms_nano(5, 36, 10, 955_161_500).unwrap()
    )
    .assume_utc()
        + Duration::nanoseconds(100)
)
.is_err());
§

type Error = FileTimeRangeError

The type returned in the event of a conversion error.
source§

impl TryFrom<SystemTime> for FileTime

Available on crate feature std only.
source§

fn try_from(time: SystemTime) -> Result<Self, Self::Error>

Converts a SystemTime to a FileTime.

Errors

Returns Err if time is out of range for the Windows NT system time.

Examples
assert_eq!(
    FileTime::try_from(SystemTime::UNIX_EPOCH - Duration::from_secs(11_644_473_600)).unwrap(),
    FileTime::NT_EPOCH
);
assert_eq!(
    FileTime::try_from(SystemTime::UNIX_EPOCH).unwrap(),
    FileTime::UNIX_EPOCH
);

assert!(FileTime::try_from(
    SystemTime::UNIX_EPOCH - Duration::from_nanos(11_644_473_600_000_000_100)
)
.is_err());

assert!(FileTime::try_from(
    SystemTime::UNIX_EPOCH + Duration::new(1_833_029_933_770, 955_161_600)
)
.is_err());
§

type Error = FileTimeRangeError

The type returned in the event of a conversion error.
source§

impl Copy for FileTime

source§

impl Eq for FileTime

source§

impl StructuralEq for FileTime

source§

impl StructuralPartialEq for FileTime

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.