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. Windows uses a file time to record when an application creates, accesses, or writes to a file.
This represents the same value as the FILETIME
structure of the Win32
API, which represents a 64-bit unsigned integer value.
Note that many environments, such as the Win32 API, may limit the largest
value of the file time to “+30828-09-14 02:48:05.477580700 UTC”, which is
equal to i64::MAX
, the largest value of a 64-bit signed integer type
when represented as an underlying integer value. This is the largest file
time accepted by the FileTimeToSystemTime
function of the Win32 API.
Also, the file time is sometimes represented as an i64
value, such as in
the DateTime.FromFileTimeUtc
method and the DateTime.ToFileTimeUtc
method in .NET.
Therefore, if you want the process to succeed in more environments, it is
generally recommended that you use FileTime::SIGNED_MAX
as the largest
value instead of FileTime::MAX
.
Implementations§
Source§impl FileTime
impl FileTime
Sourcepub const NT_TIME_EPOCH: Self
pub const NT_TIME_EPOCH: Self
The NT time epoch.
This is defined as “1601-01-01 00:00:00 UTC”, which was the first year of the 400-year Gregorian calendar cycle at the time Windows NT was being designed.
§Examples
assert_eq!(FileTime::NT_TIME_EPOCH, datetime!(1601-01-01 00:00 UTC));
Sourcepub const UNIX_EPOCH: Self
pub const UNIX_EPOCH: Self
The Unix epoch.
This is defined as “1970-01-01 00:00:00 UTC”, which is 11,644,473,600
seconds after FileTime::NT_TIME_EPOCH
.
§Examples
assert_eq!(FileTime::UNIX_EPOCH, OffsetDateTime::UNIX_EPOCH);
Sourcepub const SIGNED_MAX: Self
pub const SIGNED_MAX: Self
The largest file time accepted by the FileTimeToSystemTime
function
of the Win32 API.
This is “+30828-09-14 02:48:05.477580700 UTC”, which is equal to the largest value of a 64-bit signed integer type when represented as an underlying integer value.
The FILETIME
structure of the Win32 API represents a 64-bit unsigned
integer value, but many environments, such as the Win32 API, may limit
the largest value to i64::MAX
, and the file time is sometimes
represented as an i64
value, such as in the
DateTime.FromFileTimeUtc
method and the DateTime.ToFileTimeUtc
method in .NET, so if you want the process to succeed in more
environments, it is generally recommended that you use this constant as
the largest value instead of FileTime::MAX
.
Note that the actual largest value of the SYSTEMTIME
structure of
the Win32 API is “+30827-12-31 23:59:59.999000000” (which is either in
UTC or local time, depending on the function that is being called),
which is different from this constant. The FileTimeToSystemTime
function accepts the value of this constant, but it is an invalid date
and time for the SYSTEMTIME
structure.
§Examples
assert_eq!(
FileTime::SIGNED_MAX,
datetime!(+30828-09-14 02:48:05.477_580_700 UTC)
);
Sourcepub const MAX: Self
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”.
This is the theoretical largest value that the FILETIME
structure of
the Win32 API can represent.
Many environments, such as the Win32 API, may limit the largest file
time to i64::MAX
, and the file time is sometimes represented as an
i64
value, such as in the DateTime.FromFileTimeUtc
method and
the DateTime.ToFileTimeUtc
method in .NET, so if you want the
process to succeed in more environments, it is generally recommended
that you use FileTime::SIGNED_MAX
as the largest value instead of
this constant.
§Examples
assert_eq!(
FileTime::MAX,
datetime!(+60056-05-28 05:36:10.955_161_500 UTC)
);
Source§impl FileTime
impl FileTime
Sourcepub fn to_dos_date_time(
self,
offset: Option<UtcOffset>,
) -> Result<(u16, u16, u8, Option<UtcOffset>), DosDateTimeRangeError>
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 if the
result is Ok
.
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 in the provided time zone and returns it
with the UTC offset. When the offset
parameter is None
or is not
a multiple of 15 minute intervals, returns the UTC date and time as a
date and time and None
as the UTC offset.
Note that exFAT supports resolution
for creation and last modified
times, and the offset
return value for these times and last access
time, but other file systems and file formats may not support these. For
example, the built-in timestamp of ZIP used for last modified time only
records date
and time
, not resolution
and the offset
return
value.
§Errors
Returns Err
if the resulting date and time is out of range for
MS-DOS date and time.
§Panics
Panics if the offset
parameter is out of range for the OffsetFromUtc
field.
§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, returns the UTC 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)))
);
Sourcepub fn from_dos_date_time(
date: u16,
time: u16,
resolution: Option<u8>,
offset: Option<UtcOffset>,
) -> Result<Self, ComponentRange>
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 in the provided time zone to UTC. When offset
is
None
or is not a multiple of 15 minute intervals, assumes the
provided date and time is in UTC.
Note that exFAT supports resolution
for creation and last modified
times, and offset
for these times and last access time, but other file
systems and file formats may not support these. For example, the
built-in timestamp of ZIP used for last modified time only records
date
and time
, not resolution
and offset
.
§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 out of range for the OffsetFromUtc field.
§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, assumes the provided date and time is in UTC:
// 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::from_dos_date_time(0x0021, u16::MIN, Some(200), None).unwrap();
Source§impl FileTime
impl FileTime
Sourcepub fn checked_add(self, rhs: Duration) -> Option<Self>
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);
Sourcepub fn checked_sub(self, rhs: Duration) -> Option<Self>
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
);
Sourcepub fn saturating_add(self, rhs: Duration) -> Self
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
);
Sourcepub fn saturating_sub(self, rhs: Duration) -> Self
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§impl FileTime
impl FileTime
Sourcepub fn to_unix_time(self) -> (i64, u32)
pub fn to_unix_time(self) -> (i64, u32)
Returns Unix time represented as a pair of the number of whole seconds
and the number of additional nanoseconds, like the timespec
structure in C11, which represents the same date and time as this
FileTime
.
The first return value represents the number of whole seconds, and the second return value represents the number of additional nanoseconds.
§Examples
assert_eq!(FileTime::NT_TIME_EPOCH.to_unix_time(), (-11_644_473_600, 0));
assert_eq!(FileTime::UNIX_EPOCH.to_unix_time(), (0, 0));
assert_eq!(
FileTime::SIGNED_MAX.to_unix_time(),
(910_692_730_085, 477_580_700)
);
assert_eq!(
FileTime::MAX.to_unix_time(),
(1_833_029_933_770, 955_161_500)
);
Sourcepub fn to_unix_time_secs(self) -> i64
pub fn to_unix_time_secs(self) -> i64
Returns Unix time in seconds which represents the same date and time
as this FileTime
.
§Examples
assert_eq!(FileTime::NT_TIME_EPOCH.to_unix_time_secs(), -11_644_473_600);
assert_eq!(FileTime::UNIX_EPOCH.to_unix_time_secs(), 0);
assert_eq!(FileTime::SIGNED_MAX.to_unix_time_secs(), 910_692_730_085);
assert_eq!(FileTime::MAX.to_unix_time_secs(), 1_833_029_933_770);
Sourcepub fn to_unix_time_millis(self) -> i64
pub fn to_unix_time_millis(self) -> i64
Returns Unix time in milliseconds which represents the same date and
time as this FileTime
.
§Examples
assert_eq!(
FileTime::NT_TIME_EPOCH.to_unix_time_millis(),
-11_644_473_600_000
);
assert_eq!(FileTime::UNIX_EPOCH.to_unix_time_millis(), 0);
assert_eq!(
FileTime::SIGNED_MAX.to_unix_time_millis(),
910_692_730_085_477
);
assert_eq!(FileTime::MAX.to_unix_time_millis(), 1_833_029_933_770_955);
Sourcepub fn to_unix_time_micros(self) -> i64
pub fn to_unix_time_micros(self) -> i64
Returns Unix time in microseconds which represents the same date and
time as this FileTime
.
§Examples
assert_eq!(
FileTime::NT_TIME_EPOCH.to_unix_time_micros(),
-11_644_473_600_000_000
);
assert_eq!(FileTime::UNIX_EPOCH.to_unix_time_micros(), 0);
assert_eq!(
FileTime::SIGNED_MAX.to_unix_time_micros(),
910_692_730_085_477_580
);
assert_eq!(
FileTime::MAX.to_unix_time_micros(),
1_833_029_933_770_955_161
);
Sourcepub fn to_unix_time_nanos(self) -> i128
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(), 0);
assert_eq!(
FileTime::SIGNED_MAX.to_unix_time_nanos(),
910_692_730_085_477_580_700
);
assert_eq!(
FileTime::MAX.to_unix_time_nanos(),
1_833_029_933_770_955_161_500
);
Sourcepub fn from_unix_time(secs: i64, nanos: u32) -> Result<Self, FileTimeRangeError>
pub fn from_unix_time(secs: i64, nanos: u32) -> Result<Self, FileTimeRangeError>
Creates a FileTime
with the given Unix time, represented as a pair
of the number of whole seconds and the number of additional nanoseconds,
like the timespec
structure in C11.
secs
is the number of whole seconds, and nanos
is the number of
additional nanoseconds.
If the number of nanoseconds is greater than 1 billion (the number of nanoseconds in a second), then it will carry over into the seconds provided.
§Errors
Returns Err
if the provided Unix time is out of range for the file
time.
§Examples
assert_eq!(
FileTime::from_unix_time(-11_644_473_600, 0).unwrap(),
FileTime::NT_TIME_EPOCH
);
assert_eq!(
FileTime::from_unix_time(0, 0).unwrap(),
FileTime::UNIX_EPOCH
);
assert_eq!(
FileTime::from_unix_time(910_692_730_085, 477_580_700).unwrap(),
FileTime::SIGNED_MAX
);
assert_eq!(
FileTime::from_unix_time(1_833_029_933_770, 955_161_500).unwrap(),
FileTime::MAX
);
// The number of nanoseconds is greater than 1 billion.
assert_eq!(
FileTime::from_unix_time(0, 1_000_000_000).unwrap(),
FileTime::from_unix_time(1, 0).unwrap()
);
// Before `1601-01-01 00:00:00 UTC`.
assert!(FileTime::from_unix_time(-11_644_473_601, 999_999_999).is_err());
// After `+60056-05-28 05:36:10.955161500 UTC`.
assert!(FileTime::from_unix_time(1_833_029_933_770, 955_161_600).is_err());
Sourcepub fn from_unix_time_secs(secs: i64) -> Result<Self, FileTimeRangeError>
pub fn from_unix_time_secs(secs: i64) -> Result<Self, FileTimeRangeError>
Creates a FileTime
with the given Unix time in seconds.
§Errors
Returns Err
if secs
is out of range for the file time.
§Examples
assert_eq!(
FileTime::from_unix_time_secs(-11_644_473_600).unwrap(),
FileTime::NT_TIME_EPOCH
);
assert_eq!(
FileTime::from_unix_time_secs(0).unwrap(),
FileTime::UNIX_EPOCH
);
assert_eq!(
FileTime::from_unix_time_secs(910_692_730_085).unwrap(),
FileTime::SIGNED_MAX - Duration::from_nanos(477_580_700)
);
assert_eq!(
FileTime::from_unix_time_secs(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_secs(-11_644_473_601).is_err());
// After `+60056-05-28 05:36:10.955161500 UTC`.
assert!(FileTime::from_unix_time_secs(1_833_029_933_771).is_err());
Sourcepub fn from_unix_time_millis(millis: i64) -> Result<Self, FileTimeRangeError>
pub fn from_unix_time_millis(millis: i64) -> Result<Self, FileTimeRangeError>
Creates a FileTime
with the given Unix time in milliseconds.
§Errors
Returns Err
if millis
is out of range for the file time.
§Examples
assert_eq!(
FileTime::from_unix_time_millis(-11_644_473_600_000).unwrap(),
FileTime::NT_TIME_EPOCH
);
assert_eq!(
FileTime::from_unix_time_millis(0).unwrap(),
FileTime::UNIX_EPOCH
);
assert_eq!(
FileTime::from_unix_time_millis(910_692_730_085_477).unwrap(),
FileTime::SIGNED_MAX - Duration::from_nanos(580_700)
);
assert_eq!(
FileTime::from_unix_time_millis(1_833_029_933_770_955).unwrap(),
FileTime::MAX - Duration::from_nanos(161_500)
);
// Before `1601-01-01 00:00:00 UTC`.
assert!(FileTime::from_unix_time_millis(-11_644_473_600_001).is_err());
// After `+60056-05-28 05:36:10.955161500 UTC`.
assert!(FileTime::from_unix_time_millis(1_833_029_933_770_956).is_err());
Sourcepub fn from_unix_time_micros(micros: i64) -> Result<Self, FileTimeRangeError>
pub fn from_unix_time_micros(micros: i64) -> Result<Self, FileTimeRangeError>
Creates a FileTime
with the given Unix time in microseconds.
§Errors
Returns Err
if micros
is out of range for the file time.
§Examples
assert_eq!(
FileTime::from_unix_time_micros(-11_644_473_600_000_000).unwrap(),
FileTime::NT_TIME_EPOCH
);
assert_eq!(
FileTime::from_unix_time_micros(0).unwrap(),
FileTime::UNIX_EPOCH
);
assert_eq!(
FileTime::from_unix_time_micros(910_692_730_085_477_580).unwrap(),
FileTime::SIGNED_MAX - Duration::from_nanos(700)
);
assert_eq!(
FileTime::from_unix_time_micros(1_833_029_933_770_955_161).unwrap(),
FileTime::MAX - Duration::from_nanos(500)
);
// Before `1601-01-01 00:00:00 UTC`.
assert!(FileTime::from_unix_time_micros(-11_644_473_600_000_001).is_err());
// After `+60056-05-28 05:36:10.955161500 UTC`.
assert!(FileTime::from_unix_time_micros(1_833_029_933_770_955_162).is_err());
Sourcepub fn from_unix_time_nanos(nanos: i128) -> Result<Self, FileTimeRangeError>
pub fn from_unix_time_nanos(nanos: i128) -> Result<Self, FileTimeRangeError>
Creates a FileTime
with the given Unix time in nanoseconds.
§Errors
Returns Err
if nanos
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(0).unwrap(),
FileTime::UNIX_EPOCH
);
assert_eq!(
FileTime::from_unix_time_nanos(910_692_730_085_477_580_700).unwrap(),
FileTime::SIGNED_MAX
);
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_001).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§impl FileTime
impl FileTime
Sourcepub const fn new(ft: u64) -> Self
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(i64::MAX as u64), FileTime::SIGNED_MAX);
assert_eq!(FileTime::new(u64::MAX), FileTime::MAX);
Sourcepub const fn to_raw(self) -> u64
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::SIGNED_MAX.to_raw(), i64::MAX as u64);
assert_eq!(FileTime::MAX.to_raw(), u64::MAX);
Sourcepub const fn to_be_bytes(self) -> [u8; 8]
pub const fn to_be_bytes(self) -> [u8; 8]
Returns the memory representation of this FileTime
as a byte array in
big-endian (network) 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::SIGNED_MAX.to_be_bytes(),
[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]
);
assert_eq!(FileTime::MAX.to_be_bytes(), [u8::MAX; 8]);
Sourcepub const fn to_le_bytes(self) -> [u8; 8]
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::SIGNED_MAX.to_le_bytes(),
[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f]
);
assert_eq!(FileTime::MAX.to_le_bytes(), [u8::MAX; 8]);
Sourcepub const fn to_ne_bytes(self) -> [u8; 8]
pub const fn to_ne_bytes(self) -> [u8; 8]
Returns the memory representation of this FileTime
as a byte array in
native byte order.
As the target platform’s native endianness is used, portable code should
use FileTime::to_be_bytes
or FileTime::to_le_bytes
, as
appropriate, instead.
§Examples
assert_eq!(FileTime::NT_TIME_EPOCH.to_ne_bytes(), [u8::MIN; 8]);
assert_eq!(
FileTime::UNIX_EPOCH.to_ne_bytes(),
if cfg!(target_endian = "big") {
[0x01, 0x9d, 0xb1, 0xde, 0xd5, 0x3e, 0x80, 0x00]
} else {
[0x00, 0x80, 0x3e, 0xd5, 0xde, 0xb1, 0x9d, 0x01]
}
);
assert_eq!(
FileTime::SIGNED_MAX.to_ne_bytes(),
if cfg!(target_endian = "big") {
[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]
} else {
[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f]
}
);
assert_eq!(FileTime::MAX.to_ne_bytes(), [u8::MAX; 8]);
Sourcepub const fn from_be_bytes(bytes: [u8; 8]) -> Self
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([0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]),
FileTime::SIGNED_MAX
);
assert_eq!(FileTime::from_be_bytes([u8::MAX; 8]), FileTime::MAX);
Sourcepub const fn from_le_bytes(bytes: [u8; 8]) -> Self
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([0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f]),
FileTime::SIGNED_MAX
);
assert_eq!(FileTime::from_le_bytes([u8::MAX; 8]), FileTime::MAX);
Sourcepub const fn from_ne_bytes(bytes: [u8; 8]) -> Self
pub const fn from_ne_bytes(bytes: [u8; 8]) -> Self
Creates a native endian FileTime
value from its memory representation
as a byte array in native endianness.
As the target platform’s native endianness is used, portable code likely
wants to use FileTime::from_be_bytes
or FileTime::from_le_bytes
,
as appropriate instead.
§Examples
assert_eq!(
FileTime::from_ne_bytes([u8::MIN; 8]),
FileTime::NT_TIME_EPOCH
);
assert_eq!(
FileTime::from_ne_bytes(if cfg!(target_endian = "big") {
[0x01, 0x9d, 0xb1, 0xde, 0xd5, 0x3e, 0x80, 0x00]
} else {
[0x00, 0x80, 0x3e, 0xd5, 0xde, 0xb1, 0x9d, 0x01]
}),
FileTime::UNIX_EPOCH
);
assert_eq!(
FileTime::from_ne_bytes(if cfg!(target_endian = "big") {
[0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff]
} else {
[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f]
}),
FileTime::SIGNED_MAX
);
assert_eq!(FileTime::from_ne_bytes([u8::MAX; 8]), FileTime::MAX);
Sourcepub const fn to_high_low(self) -> (u32, u32)
pub const fn to_high_low(self) -> (u32, u32)
Returns the high-order and low-order parts of this FileTime
.
The first return value represents the high-order part of this
FileTime
, and the second return value represents the low-order part of
this FileTime
.
The first return value corresponds to the dwHighDateTime
member of the
FILETIME
structure of the Win32 API, and the second return value
corresponds to the dwLowDateTime
member of the FILETIME
structure.
The data type of these members is DWORD
, a 32-bit unsigned integer
type the same as u32
.
§Examples
assert_eq!(FileTime::NT_TIME_EPOCH.to_high_low(), (u32::MIN, u32::MIN));
assert_eq!(
FileTime::UNIX_EPOCH.to_high_low(),
(0x019d_b1de, 0xd53e_8000)
);
assert_eq!(
FileTime::SIGNED_MAX.to_high_low(),
(i32::MAX as u32, u32::MAX)
);
assert_eq!(FileTime::MAX.to_high_low(), (u32::MAX, u32::MAX));
Sourcepub const fn from_high_low(high: u32, low: u32) -> Self
pub const fn from_high_low(high: u32, low: u32) -> Self
Creates a FileTime
from u32
values representing the high-order and
low-order parts of the file time.
high
corresponds to the dwHighDateTime
member of the FILETIME
structure of the Win32 API, and low
corresponds to the
dwLowDateTime
member of the FILETIME
structure. The data type of
these members is DWORD
, a 32-bit unsigned integer type the same as
u32
.
§Examples
assert_eq!(
FileTime::from_high_low(u32::MIN, u32::MIN),
FileTime::NT_TIME_EPOCH
);
assert_eq!(
FileTime::from_high_low(0x019d_b1de, 0xd53e_8000),
FileTime::UNIX_EPOCH
);
assert_eq!(
FileTime::from_high_low(i32::MAX as u32, u32::MAX),
FileTime::SIGNED_MAX
);
assert_eq!(FileTime::from_high_low(u32::MAX, u32::MAX), FileTime::MAX);
Trait Implementations§
Source§impl AddAssign<Duration> for FileTime
impl AddAssign<Duration> for FileTime
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moreSource§impl AddAssign<Duration> for FileTime
impl AddAssign<Duration> for FileTime
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moreSource§impl AddAssign<TimeDelta> for FileTime
Available on crate feature chrono
only.
impl AddAssign<TimeDelta> for FileTime
chrono
only.Source§fn add_assign(&mut self, rhs: TimeDelta)
fn add_assign(&mut self, rhs: TimeDelta)
+=
operation. Read moreSource§impl Binary for FileTime
impl Binary for FileTime
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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!("{:#066b}", FileTime::SIGNED_MAX),
"0b0111111111111111111111111111111111111111111111111111111111111111"
);
assert_eq!(
format!("{:b}", FileTime::MAX),
"1111111111111111111111111111111111111111111111111111111111111111"
);
Source§impl Default for FileTime
impl Default for FileTime
Source§fn default() -> Self
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.
impl<'de> Deserialize<'de> for FileTime
serde
only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
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
#[derive(Deserialize)]
struct Time {
time: FileTime,
}
let ft: Time = serde_json::from_str(r#"{"time":116444736000000000}"#).unwrap();
assert_eq!(ft.time, FileTime::UNIX_EPOCH);
#[derive(Deserialize)]
struct Time {
time: Option<FileTime>,
}
let ft: Time = serde_json::from_str(r#"{"time":116444736000000000}"#).unwrap();
assert_eq!(ft.time, Some(FileTime::UNIX_EPOCH));
let ft: Time = serde_json::from_str(r#"{"time":null}"#).unwrap();
assert_eq!(ft.time, None);
Source§impl Display for FileTime
impl Display for FileTime
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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::SIGNED_MAX), "9223372036854775807");
assert_eq!(format!("{}", FileTime::MAX), "18446744073709551615");
Source§impl Distribution<FileTime> for Standard
Available on crate feature rand
only.
impl Distribution<FileTime> for Standard
rand
only.Source§impl From<FileTime> for SystemTime
Available on crate feature std
only.
impl From<FileTime> for SystemTime
std
only.Source§fn from(ft: FileTime) -> Self
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
impl From<FileTime> for u64
Source§fn from(ft: FileTime) -> Self
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::SIGNED_MAX), i64::MAX as u64);
assert_eq!(u64::from(FileTime::MAX), u64::MAX);
Source§impl From<u64> for FileTime
impl From<u64> for FileTime
Source§fn from(ft: u64) -> Self
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(i64::MAX as u64), FileTime::SIGNED_MAX);
assert_eq!(FileTime::from(u64::MAX), FileTime::MAX);
Source§impl FromStr for FileTime
impl FromStr for FileTime
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
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("+9223372036854775807").unwrap(),
FileTime::SIGNED_MAX
);
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());
Source§type Err = ParseFileTimeError
type Err = ParseFileTimeError
Source§impl LowerExp for FileTime
impl LowerExp for FileTime
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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!("{:024e}", FileTime::SIGNED_MAX),
"09.223372036854775807e18"
);
assert_eq!(format!("{:e}", FileTime::MAX), "1.8446744073709551615e19");
Source§impl LowerHex for FileTime
impl LowerHex for FileTime
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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!("{:#018x}", FileTime::SIGNED_MAX),
"0x7fffffffffffffff"
);
assert_eq!(format!("{:x}", FileTime::MAX), "ffffffffffffffff");
Source§impl Octal for FileTime
impl Octal for FileTime
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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!("{:#024o}", FileTime::SIGNED_MAX),
"0o0777777777777777777777"
);
assert_eq!(format!("{:o}", FileTime::MAX), "1777777777777777777777");
Source§impl Ord for FileTime
impl Ord for FileTime
Source§impl PartialEq<FileTime> for OffsetDateTime
impl PartialEq<FileTime> for OffsetDateTime
Source§impl PartialEq<FileTime> for SystemTime
Available on crate feature std
only.
impl PartialEq<FileTime> for SystemTime
std
only.Source§impl PartialEq<OffsetDateTime> for FileTime
impl PartialEq<OffsetDateTime> for FileTime
Source§impl PartialEq<SystemTime> for FileTime
Available on crate feature std
only.
impl PartialEq<SystemTime> for FileTime
std
only.Source§impl PartialOrd<DateTime<Utc>> for FileTime
Available on crate feature chrono
only.
impl PartialOrd<DateTime<Utc>> for FileTime
chrono
only.Source§impl PartialOrd<FileTime> for DateTime<Utc>
Available on crate feature chrono
only.
impl PartialOrd<FileTime> for DateTime<Utc>
chrono
only.Source§impl PartialOrd<FileTime> for OffsetDateTime
impl PartialOrd<FileTime> for OffsetDateTime
Source§impl PartialOrd<FileTime> for SystemTime
Available on crate feature std
only.
impl PartialOrd<FileTime> for SystemTime
std
only.Source§impl PartialOrd<OffsetDateTime> for FileTime
impl PartialOrd<OffsetDateTime> for FileTime
Source§impl PartialOrd<SystemTime> for FileTime
Available on crate feature std
only.
impl PartialOrd<SystemTime> for FileTime
std
only.Source§impl PartialOrd for FileTime
impl PartialOrd for FileTime
Source§impl Serialize for FileTime
Available on crate feature serde
only.
impl Serialize for FileTime
serde
only.Source§fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
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
#[derive(Serialize)]
struct Time {
time: FileTime,
}
let ft = Time {
time: FileTime::UNIX_EPOCH,
};
let json = serde_json::to_string(&ft).unwrap();
assert_eq!(json, r#"{"time":116444736000000000}"#);
#[derive(Serialize)]
struct Time {
time: Option<FileTime>,
}
let ft = Time {
time: Some(FileTime::UNIX_EPOCH),
};
let json = serde_json::to_string(&ft).unwrap();
assert_eq!(json, r#"{"time":116444736000000000}"#);
let ft = Time { time: None };
let json = serde_json::to_string(&ft).unwrap();
assert_eq!(json, r#"{"time":null}"#);
Source§impl Sub<FileTime> for OffsetDateTime
impl Sub<FileTime> for OffsetDateTime
Source§impl Sub<FileTime> for SystemTime
Available on crate feature std
only.
impl Sub<FileTime> for SystemTime
std
only.Source§impl Sub<OffsetDateTime> for FileTime
impl Sub<OffsetDateTime> for FileTime
Source§impl Sub<SystemTime> for FileTime
Available on crate feature std
only.
impl Sub<SystemTime> for FileTime
std
only.Source§impl SubAssign<Duration> for FileTime
impl SubAssign<Duration> for FileTime
Source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moreSource§impl SubAssign<Duration> for FileTime
impl SubAssign<Duration> for FileTime
Source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-=
operation. Read moreSource§impl SubAssign<TimeDelta> for FileTime
Available on crate feature chrono
only.
impl SubAssign<TimeDelta> for FileTime
chrono
only.Source§fn sub_assign(&mut self, rhs: TimeDelta)
fn sub_assign(&mut self, rhs: TimeDelta)
-=
operation. Read moreSource§impl TryFrom<DateTime<Utc>> for FileTime
Available on crate feature chrono
only.
impl TryFrom<DateTime<Utc>> for FileTime
chrono
only.Source§fn try_from(dt: DateTime<Utc>) -> Result<Self, Self::Error>
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("1601-01-01 00:00:00 UTC".parse::<DateTime<Utc>>().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(
"1601-01-01 00:00:00 UTC".parse::<DateTime<Utc>>().unwrap() - TimeDelta::nanoseconds(100)
)
.is_err());
// After `+60056-05-28 05:36:10.955161500 UTC`.
assert!(FileTime::try_from(
"+60056-05-28 05:36:10.955161500 UTC"
.parse::<DateTime<Utc>>()
.unwrap()
+ TimeDelta::nanoseconds(100)
)
.is_err());
Source§type Error = FileTimeRangeError
type Error = FileTimeRangeError
Source§impl TryFrom<FileTime> for OffsetDateTime
impl TryFrom<FileTime> for OffsetDateTime
Source§fn try_from(ft: FileTime) -> Result<Self, Self::Error>
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::SIGNED_MAX).unwrap(),
datetime!(+30828-09-14 02:48:05.477_580_700 UTC)
);
assert_eq!(
OffsetDateTime::try_from(FileTime::MAX).unwrap(),
datetime!(+60056-05-28 05:36:10.955_161_500 UTC)
);
Source§type Error = ComponentRange
type Error = ComponentRange
Source§impl TryFrom<FileTime> for i64
impl TryFrom<FileTime> for i64
Source§fn try_from(ft: FileTime) -> Result<Self, Self::Error>
fn try_from(ft: FileTime) -> Result<Self, Self::Error>
Converts a FileTime
to the file time.
The file time is sometimes represented as an i64
value, such as in
the DateTime.FromFileTimeUtc
method and the
DateTime.ToFileTimeUtc
method in .NET.
§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(), 0);
assert_eq!(
i64::try_from(FileTime::UNIX_EPOCH).unwrap(),
116_444_736_000_000_000
);
assert_eq!(i64::try_from(FileTime::SIGNED_MAX).unwrap(), i64::MAX);
assert!(i64::try_from(FileTime::MAX).is_err());
Source§type Error = TryFromIntError
type Error = TryFromIntError
Source§impl TryFrom<OffsetDateTime> for FileTime
impl TryFrom<OffsetDateTime> for FileTime
Source§fn try_from(dt: OffsetDateTime) -> Result<Self, Self::Error>
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::nanoseconds(100)).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());
Source§type Error = FileTimeRangeError
type Error = FileTimeRangeError
Source§impl TryFrom<SystemTime> for FileTime
Available on crate feature std
only.
impl TryFrom<SystemTime> for FileTime
std
only.Source§fn try_from(st: SystemTime) -> Result<Self, Self::Error>
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());
Source§type Error = FileTimeRangeError
type Error = FileTimeRangeError
Source§impl TryFrom<i64> for FileTime
impl TryFrom<i64> for FileTime
Source§fn try_from(ft: i64) -> Result<Self, Self::Error>
fn try_from(ft: i64) -> Result<Self, Self::Error>
Converts the file time to a FileTime
.
The file time is sometimes represented as an i64
value, such as in
the DateTime.FromFileTimeUtc
method and the
DateTime.ToFileTimeUtc
method in .NET.
§Errors
Returns Err
if ft
is negative.
§Examples
assert_eq!(FileTime::try_from(0_i64).unwrap(), FileTime::NT_TIME_EPOCH);
assert_eq!(
FileTime::try_from(116_444_736_000_000_000_i64).unwrap(),
FileTime::UNIX_EPOCH
);
assert_eq!(FileTime::try_from(i64::MAX).unwrap(), FileTime::SIGNED_MAX);
assert!(FileTime::try_from(i64::MIN).is_err());
Source§type Error = FileTimeRangeError
type Error = FileTimeRangeError
Source§impl UpperExp for FileTime
impl UpperExp for FileTime
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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!("{:024E}", FileTime::SIGNED_MAX),
"09.223372036854775807E18"
);
assert_eq!(format!("{:E}", FileTime::MAX), "1.8446744073709551615E19");
Source§impl UpperHex for FileTime
impl UpperHex for FileTime
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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!("{:#018X}", FileTime::SIGNED_MAX),
"0x7FFFFFFFFFFFFFFF"
);
assert_eq!(format!("{:X}", FileTime::MAX), "FFFFFFFFFFFFFFFF");