Struct nt_time::FileTime

source ·
pub struct FileTime(/* private fields */);
Expand description

FileTime is a type that represents a Windows file 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”, and is used as timestamps such as NTFS and 7z.

This represents the same value as the FILETIME structure of the Win32 API, which represents a 64-bit unsigned integer value. Note that the maximum value of the FILETIME structure that can be input to the FileTimeToSystemTime function of the Win32 API is limited to “+30828-09-14 02:48:05.477580700 UTC”, which is equivalent to i64::MAX.

Implementations§

source§

impl FileTime

source

pub const NT_TIME_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_TIME_EPOCH).unwrap(),
    datetime!(1601-01-01 00:00 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 file time.

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

§Examples
assert_eq!(
    OffsetDateTime::try_from(FileTime::MAX).unwrap(),
    datetime!(+60056-05-28 05:36:10.955_161_500 UTC)
);
source

pub fn now() -> Self

Available on crate feature std only.

Returns the file time corresponding to “now”.

§Panics

Panics if “now” is out of range for the file time.

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

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

Creates a new FileTime with the given file time.

§Examples
assert_eq!(FileTime::new(u64::MIN), FileTime::NT_TIME_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 to_raw(self) -> u64

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

§Examples
assert_eq!(FileTime::NT_TIME_EPOCH.to_raw(), u64::MIN);
assert_eq!(FileTime::UNIX_EPOCH.to_raw(), 116_444_736_000_000_000);
assert_eq!(FileTime::MAX.to_raw(), u64::MAX);
source

pub const fn as_u64(self) -> u64

👎Deprecated since 0.5.0: use FileTime::to_raw instead

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

§Examples
assert_eq!(FileTime::NT_TIME_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 to_unix_time(self) -> i64

Returns Unix time which represents the same date and time as this FileTime.

§Examples
assert_eq!(FileTime::NT_TIME_EPOCH.to_unix_time(), -11_644_473_600);
assert_eq!(FileTime::UNIX_EPOCH.to_unix_time(), i64::default());
assert_eq!(FileTime::MAX.to_unix_time(), 1_833_029_933_770);
source

pub fn to_unix_time_nanos(self) -> i128

Returns Unix time in nanoseconds which represents the same date and time as this FileTime.

§Examples
assert_eq!(
    FileTime::NT_TIME_EPOCH.to_unix_time_nanos(),
    -11_644_473_600_000_000_000
);
assert_eq!(FileTime::UNIX_EPOCH.to_unix_time_nanos(), i128::default());
assert_eq!(
    FileTime::MAX.to_unix_time_nanos(),
    1_833_029_933_770_955_161_500
);
source

pub fn from_unix_time(timestamp: i64) -> Result<Self, FileTimeRangeError>

Creates a FileTime with the given Unix time.

§Errors

Returns Err if time is out of range for the file time.

§Examples
assert_eq!(
    FileTime::from_unix_time(-11_644_473_600).unwrap(),
    FileTime::NT_TIME_EPOCH
);
assert_eq!(
    FileTime::from_unix_time(i64::default()).unwrap(),
    FileTime::UNIX_EPOCH
);
assert_eq!(
    FileTime::from_unix_time(1_833_029_933_770).unwrap(),
    FileTime::MAX - Duration::from_nanos(955_161_500)
);

// Before `1601-01-01 00:00:00 UTC`.
assert!(FileTime::from_unix_time(-11_644_473_601).is_err());
// After `+60056-05-28 05:36:10.955161500 UTC`.
assert!(FileTime::from_unix_time(1_833_029_933_771).is_err());
source

pub fn from_unix_time_nanos(timestamp: i128) -> Result<Self, FileTimeRangeError>

Creates a FileTime with the given Unix time in nanoseconds.

§Errors

Returns Err if time is out of range for the file time.

§Examples
assert_eq!(
    FileTime::from_unix_time_nanos(-11_644_473_600_000_000_000).unwrap(),
    FileTime::NT_TIME_EPOCH
);
assert_eq!(
    FileTime::from_unix_time_nanos(i128::default()).unwrap(),
    FileTime::UNIX_EPOCH
);
assert_eq!(
    FileTime::from_unix_time_nanos(1_833_029_933_770_955_161_500).unwrap(),
    FileTime::MAX
);

// Before `1601-01-01 00:00:00 UTC`.
assert!(FileTime::from_unix_time_nanos(-11_644_473_600_000_000_100).is_err());
// After `+60056-05-28 05:36:10.955161500 UTC`.
assert!(FileTime::from_unix_time_nanos(1_833_029_933_770_955_161_501).is_err());
source

pub fn to_dos_date_time( self, offset: Option<UtcOffset> ) -> Result<(u16, u16, u8, Option<UtcOffset>), DosDateTimeRangeError>

Returns MS-DOS date and time which represents the same date and time as this FileTime. This date and time is used as the timestamp such as FAT, exFAT or ZIP file format.

This method returns a (date, time, resolution, offset) tuple.

date and time represents the local date and time. This date and time has no notion of time zone. The resolution of MS-DOS date and time is 2 seconds, but additional finer resolution (10 ms units) can be provided. resolution represents this additional finer resolution.

When the offset parameter is Some, converts date and time from UTC to the local date and time with the provided UTC offset and returns it with the UTC offset. When the offset parameter is None or is not a multiple of 15 minute intervals, consider UTC to be the local date and time and returns None as the UTC offset.

§Errors

Returns Err if the resulting date and time is out of range for MS-DOS date and time.

§Panics

Panics if offset is not in the range “UTC-16:00” to “UTC+15:45”.1

§Examples
// `1980-01-01 00:00:00 UTC`.
assert_eq!(
    FileTime::new(119_600_064_000_000_000)
        .to_dos_date_time(None)
        .unwrap(),
    (0x0021, u16::MIN, u8::MIN, None)
);
// `2107-12-31 23:59:59 UTC`.
assert_eq!(
    FileTime::new(159_992_927_990_000_000)
        .to_dos_date_time(None)
        .unwrap(),
    (0xff9f, 0xbf7d, 100, None)
);

// Before `1980-01-01 00:00:00 UTC`.
assert!(FileTime::new(119_600_063_990_000_000)
    .to_dos_date_time(None)
    .is_err());
// After `2107-12-31 23:59:59.990000000 UTC`.
assert!(FileTime::new(159_992_928_000_000_000)
    .to_dos_date_time(None)
    .is_err());

// From `2002-11-27 03:25:00 UTC` to `2002-11-26 19:25:00 -08:00`.
assert_eq!(
    FileTime::new(126_828_411_000_000_000)
        .to_dos_date_time(Some(offset!(-08:00)))
        .unwrap(),
    (0x2d7a, 0x9b20, u8::MIN, Some(offset!(-08:00)))
);

When the UTC offset is not a multiple of 15 minute intervals, consider UTC to be the local date and time:

// `2002-11-27 03:25:00 UTC`.
assert_eq!(
    FileTime::new(126_828_411_000_000_000)
        .to_dos_date_time(Some(offset!(-08:01)))
        .unwrap(),
    (0x2d7b, 0x1b20, u8::MIN, None)
);
// `2002-11-27 03:25:00 UTC`.
assert_eq!(
    FileTime::new(126_828_411_000_000_000)
        .to_dos_date_time(Some(offset!(-08:14)))
        .unwrap(),
    (0x2d7b, 0x1b20, u8::MIN, None)
);

// From `2002-11-27 03:25:00 UTC` to `2002-11-26 19:10:00 -08:15`.
assert_eq!(
    FileTime::new(126_828_411_000_000_000)
        .to_dos_date_time(Some(offset!(-08:15)))
        .unwrap(),
    (0x2d7a, 0x9940, u8::MIN, Some(offset!(-08:15)))
);
source

pub fn from_dos_date_time( date: u16, time: u16, resolution: Option<u8>, offset: Option<UtcOffset> ) -> Result<Self, ComponentRange>

Creates a FileTime with the given MS-DOS date and time. This date and time is used as the timestamp such as FAT, exFAT or ZIP file format.

When resolution is Some, additional finer resolution (10 ms units) is added to time.

When offset is Some, converts date and time from the local date and time with the provided UTC offset to UTC. When offset is None or is not a multiple of 15 minute intervals, consider UTC to be the local date and time.

§Errors

Returns Err if date or time is an invalid date and time.

§Panics

Panics if any of the following are true:

  • resolution is greater than 199.
  • offset is not in the range “UTC-16:00” to “UTC+15:45”.1
§Examples
// `1980-01-01 00:00:00 UTC`.
assert_eq!(
    FileTime::from_dos_date_time(0x0021, u16::MIN, None, None).unwrap(),
    FileTime::new(119_600_064_000_000_000)
);
// `2107-12-31 23:59:59 UTC`.
assert_eq!(
    FileTime::from_dos_date_time(0xff9f, 0xbf7d, Some(100), None).unwrap(),
    FileTime::new(159_992_927_990_000_000)
);

// From `2002-11-26 19:25:00 -08:00` to `2002-11-27 03:25:00 UTC`.
assert_eq!(
    FileTime::from_dos_date_time(0x2d7a, 0x9b20, None, Some(offset!(-08:00))).unwrap(),
    FileTime::new(126_828_411_000_000_000)
);

// The Day field is 0.
assert!(FileTime::from_dos_date_time(0x0020, u16::MIN, None, None).is_err());
// The DoubleSeconds field is 30.
assert!(FileTime::from_dos_date_time(0x0021, 0x001e, None, None).is_err());

When the UTC offset is not a multiple of 15 minute intervals, consider UTC to be the local date and time:

// From `2002-11-26 19:25:00 -08:01` to `2002-11-26 19:25:00 UTC`.
assert_eq!(
    FileTime::from_dos_date_time(0x2d7a, 0x9b20, None, Some(offset!(-08:01))).unwrap(),
    FileTime::new(126_828_123_000_000_000)
);
// From `2002-11-26 19:25:00 -08:14` to `2002-11-26 19:25:00 UTC`.
assert_eq!(
    FileTime::from_dos_date_time(0x2d7a, 0x9b20, None, Some(offset!(-08:14))).unwrap(),
    FileTime::new(126_828_123_000_000_000)
);

// From `2002-11-26 19:25:00 -08:15` to `2002-11-27 03:40:00 UTC`.
assert_eq!(
    FileTime::from_dos_date_time(0x2d7a, 0x9b20, None, Some(offset!(-08:15))).unwrap(),
    FileTime::new(126_828_420_000_000_000)
);

Additional finer resolution must be in the range 0 to 199:

let _: FileTime = FileTime::from_dos_date_time(0x0021, u16::MIN, Some(200), None).unwrap();
source

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

Computes self + rhs, returning None if overflow occurred. The part of rhs less than 100-nanosecond is truncated.

§Examples
assert_eq!(
    FileTime::NT_TIME_EPOCH.checked_add(Duration::from_nanos(1)),
    Some(FileTime::NT_TIME_EPOCH)
);
assert_eq!(
    FileTime::NT_TIME_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. The part of rhs less than 100-nanosecond is truncated.

§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_TIME_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. The part of rhs less than 100-nanosecond is truncated.

§Examples
assert_eq!(
    FileTime::NT_TIME_EPOCH.saturating_add(Duration::from_nanos(1)),
    FileTime::NT_TIME_EPOCH
);
assert_eq!(
    FileTime::NT_TIME_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_TIME_EPOCH if the result would be negative or if overflow occurred. The part of rhs less than 100-nanosecond is truncated.

§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_TIME_EPOCH.saturating_sub(Duration::from_nanos(100)),
    FileTime::NT_TIME_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_TIME_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_TIME_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_TIME_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_TIME_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 Binary for FileTime

source§

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

Shows the underlying u64 value of this FileTime.

§Examples
assert_eq!(format!("{:#b}", FileTime::NT_TIME_EPOCH), "0b0");
assert_eq!(
    format!("{:064b}", FileTime::UNIX_EPOCH),
    "0000000110011101101100011101111011010101001111101000000000000000"
);
assert_eq!(
    format!("{:b}", FileTime::MAX),
    "1111111111111111111111111111111111111111111111111111111111111111"
);
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_TIME_EPOCH except that it is not callable in const contexts.

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

impl<'de> Deserialize<'de> for FileTime

Available on crate feature serde only.
source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserializes a FileTime from the given Serde deserializer.

This deserializes from its underlying u64 representation.

§Examples
assert_eq!(
    serde_json::from_str::<FileTime>("116444736000000000").unwrap(),
    FileTime::UNIX_EPOCH
);

assert_eq!(
    serde_json::from_str::<Option<FileTime>>("116444736000000000").unwrap(),
    Some(FileTime::UNIX_EPOCH)
);
assert_eq!(
    serde_json::from_str::<Option<FileTime>>("null").unwrap(),
    None
);
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_TIME_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(ft: FileTime) -> Self

Converts a FileTime to a DateTime<Utc>.

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

impl From<FileTime> for SystemTime

Available on crate feature std only.
source§

fn from(ft: FileTime) -> Self

Converts a FileTime to a SystemTime.

§Panics

Panics if the resulting time cannot be represented by a SystemTime.

§Examples
assert_eq!(
    SystemTime::from(FileTime::NT_TIME_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(ft: FileTime) -> Self

Converts a FileTime to the file time.

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

§Examples
assert_eq!(u64::from(FileTime::NT_TIME_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(ft: u64) -> Self

Converts the file 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_TIME_EPOCH);
assert_eq!(
    FileTime::from(116_444_736_000_000_000),
    FileTime::UNIX_EPOCH
);
assert_eq!(FileTime::from(u64::MAX), FileTime::MAX);
source§

impl FromStr for FileTime

source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of FileTime.

The string is expected to be a decimal non-negative integer. If the string is not a decimal integer, use u64::from_str_radix and FileTime::new instead.

§Errors

Returns Err if u64::from_str returns an error.

§Examples
assert_eq!(FileTime::from_str("0").unwrap(), FileTime::NT_TIME_EPOCH);
assert_eq!(
    FileTime::from_str("116444736000000000").unwrap(),
    FileTime::UNIX_EPOCH
);
assert_eq!(
    FileTime::from_str("+18446744073709551615").unwrap(),
    FileTime::MAX
);

assert!(FileTime::from_str("").is_err());

assert!(FileTime::from_str("a").is_err());
assert!(FileTime::from_str("-1").is_err());
assert!(FileTime::from_str("+").is_err());
assert!(FileTime::from_str("0 ").is_err());

assert!(FileTime::from_str("18446744073709551616").is_err());
§

type Err = ParseFileTimeError

The associated error which can be returned from parsing.
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 LowerExp for FileTime

source§

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

Shows the underlying u64 value of this FileTime.

§Examples
assert_eq!(
    format!("{:024e}", FileTime::NT_TIME_EPOCH),
    "0000000000000000000000e0"
);
assert_eq!(format!("{:e}", FileTime::UNIX_EPOCH), "1.16444736e17");
assert_eq!(format!("{:e}", FileTime::MAX), "1.8446744073709551615e19");
source§

impl LowerHex for FileTime

source§

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

Shows the underlying u64 value of this FileTime.

§Examples
assert_eq!(format!("{:#x}", FileTime::NT_TIME_EPOCH), "0x0");
assert_eq!(format!("{:016x}", FileTime::UNIX_EPOCH), "019db1ded53e8000");
assert_eq!(format!("{:x}", FileTime::MAX), "ffffffffffffffff");
source§

impl Octal for FileTime

source§

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

Shows the underlying u64 value of this FileTime.

§Examples
assert_eq!(format!("{:#o}", FileTime::NT_TIME_EPOCH), "0o0");
assert_eq!(
    format!("{:022o}", FileTime::UNIX_EPOCH),
    "0006355435732517500000"
);
assert_eq!(format!("{:o}", FileTime::MAX), "1777777777777777777777");
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) -> Self
where Self: Sized,

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

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

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

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

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 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 PartialEq 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 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 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 PartialOrd 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 Serialize for FileTime

Available on crate feature serde only.
source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serializes a FileTime into the given Serde serializer.

This serializes using the underlying u64 format.

§Examples
assert_eq!(
    serde_json::to_string(&FileTime::UNIX_EPOCH).unwrap(),
    "116444736000000000"
);

assert_eq!(
    serde_json::to_string(&Some(FileTime::UNIX_EPOCH)).unwrap(),
    "116444736000000000"
);
assert_eq!(serde_json::to_string(&None::<FileTime>).unwrap(), "null");
source§

impl Sub<DateTime<Utc>> for FileTime

Available on crate feature chrono only.
§

type Output = TimeDelta

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 = TimeDelta

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 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 Sub 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 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 file time.

§Examples
assert_eq!(
    FileTime::try_from(Utc.with_ymd_and_hms(1601, 1, 1, 0, 0, 0).unwrap()).unwrap(),
    FileTime::NT_TIME_EPOCH
);
assert_eq!(
    FileTime::try_from(DateTime::<Utc>::UNIX_EPOCH).unwrap(),
    FileTime::UNIX_EPOCH
);

// Before `1601-01-01 00:00:00 UTC`.
assert!(FileTime::try_from(
    Utc.with_ymd_and_hms(1601, 1, 1, 0, 0, 0).unwrap() - TimeDelta::nanoseconds(1)
)
.is_err());

// After `+60056-05-28 05:36:10.955161500 UTC`.
assert!(FileTime::try_from(
    Utc.with_ymd_and_hms(60056, 5, 28, 5, 36, 10).unwrap()
        + TimeDelta::nanoseconds(955_161_500)
        + TimeDelta::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(ft: 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_TIME_EPOCH).unwrap(),
    datetime!(1601-01-01 00:00 UTC)
);
assert_eq!(
    OffsetDateTime::try_from(FileTime::UNIX_EPOCH).unwrap(),
    OffsetDateTime::UNIX_EPOCH
);

With the large-dates feature disabled, returns Err if the file 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(),
    datetime!(+10000-01-01 00:00 UTC)
);
assert_eq!(
    OffsetDateTime::try_from(FileTime::MAX).unwrap(),
    datetime!(+60056-05-28 05:36:10.955_161_500 UTC)
);
§

type Error = OffsetDateTimeRangeError

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

impl TryFrom<FileTime> for i64

source§

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

Converts a FileTime to the file time.

The file time may be represented as an i64 value in WinRT,1 .NET,23 etc.

§Errors

Returns Err if ft is after “+30828-09-14 02:48:05.477580700 UTC”.

§Examples
assert_eq!(
    i64::try_from(FileTime::NT_TIME_EPOCH).unwrap(),
    i64::default()
);
assert_eq!(
    i64::try_from(FileTime::UNIX_EPOCH).unwrap(),
    116_444_736_000_000_000
);

assert!(i64::try_from(FileTime::MAX).is_err());
§

type Error = TryFromIntError

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 file time.

§Examples
assert_eq!(
    FileTime::try_from(datetime!(1601-01-01 00:00 UTC)).unwrap(),
    FileTime::NT_TIME_EPOCH
);
assert_eq!(
    FileTime::try_from(OffsetDateTime::UNIX_EPOCH).unwrap(),
    FileTime::UNIX_EPOCH
);

// Before `1601-01-01 00:00:00 UTC`.
assert!(FileTime::try_from(datetime!(1601-01-01 00:00 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(
    datetime!(+60056-05-28 05:36:10.955_161_500 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(st: SystemTime) -> Result<Self, Self::Error>

Converts a SystemTime to a FileTime.

§Errors

Returns Err if time is out of range for the file time.

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

// Before `1601-01-01 00:00:00 UTC`.
assert!(FileTime::try_from(
    SystemTime::UNIX_EPOCH - Duration::from_nanos(11_644_473_600_000_000_100)
)
.is_err());

// After `+60056-05-28 05:36:10.955161500 UTC`.
#[cfg(not(windows))]
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 TryFrom<i64> for FileTime

source§

fn try_from(ft: i64) -> Result<Self, Self::Error>

Converts the file time to a FileTime.

The file time may be represented as an i64 value in WinRT,1 .NET,23 etc.

§Errors

Returns Err if ft is negative.

§Examples
assert_eq!(
    FileTime::try_from(i64::default()).unwrap(),
    FileTime::NT_TIME_EPOCH
);
assert_eq!(
    FileTime::try_from(116_444_736_000_000_000_i64).unwrap(),
    FileTime::UNIX_EPOCH
);

assert!(FileTime::try_from(i64::MIN).is_err());
§

type Error = FileTimeRangeError

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

impl UpperExp for FileTime

source§

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

Shows the underlying u64 value of this FileTime.

§Examples
assert_eq!(
    format!("{:024E}", FileTime::NT_TIME_EPOCH),
    "0000000000000000000000E0"
);
assert_eq!(format!("{:E}", FileTime::UNIX_EPOCH), "1.16444736E17");
assert_eq!(format!("{:E}", FileTime::MAX), "1.8446744073709551615E19");
source§

impl UpperHex for FileTime

source§

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

Shows the underlying u64 value of this FileTime.

§Examples
assert_eq!(format!("{:#X}", FileTime::NT_TIME_EPOCH), "0x0");
assert_eq!(format!("{:016X}", FileTime::UNIX_EPOCH), "019DB1DED53E8000");
assert_eq!(format!("{:X}", FileTime::MAX), "FFFFFFFFFFFFFFFF");
source§

impl Copy for FileTime

source§

impl Eq for FileTime

source§

impl StructuralPartialEq for FileTime

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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 T
where 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 T
where 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 T
where U: Into<T>,

§

type Error = Infallible

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

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

Performs the conversion.
source§

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

§

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

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

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

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,