pub struct Time {
pub seconds: SecondsSinceUnixEpoch,
pub offset: OffsetInSeconds,
}
Expand description
A timestamp with timezone.
Fields§
§seconds: SecondsSinceUnixEpoch
The seconds that have passed since UNIX epoch. This makes it UTC, or <seconds>+0000
.
offset: OffsetInSeconds
The time’s offset in seconds, which may be negative to match the sign
field.
Implementations§
Source§impl Time
Formatting
impl Time
Formatting
Sourcepub fn format(&self, format: impl Into<Format>) -> String
pub fn format(&self, format: impl Into<Format>) -> String
Format this instance according to the given format
.
Use Format::Unix
, Format::Raw
or one of the custom formats
defined in the format
submodule.
Source§impl Time
Instantiation
impl Time
Instantiation
Sourcepub fn new(seconds: SecondsSinceUnixEpoch, offset: OffsetInSeconds) -> Self
pub fn new(seconds: SecondsSinceUnixEpoch, offset: OffsetInSeconds) -> Self
Create a new instance from seconds and offset.
Sourcepub fn now_local() -> Option<Self>
pub fn now_local() -> Option<Self>
Return the current local time, or None
if the local time wasn’t available.
Sourcepub fn now_local_or_utc() -> Self
pub fn now_local_or_utc() -> Self
Return the current local time, or the one at UTC if the local time wasn’t available.
Source§impl Time
Serialization with standard git
format
impl Time
Serialization with standard git
format
Sourcepub const MAX: Time
pub const MAX: Time
The numerically largest possible time instance, whose size() is the largest possible
number of bytes to write using Time::write_to()
.
Sourcepub fn write_to(&self, out: &mut dyn Write) -> Result<()>
pub fn write_to(&self, out: &mut dyn Write) -> Result<()>
Serialize this instance to out
in a format suitable for use in header fields of serialized git commits or tags.
Sourcepub const fn size(&self) -> usize
pub const fn size(&self) -> usize
Computes the number of bytes necessary to write it using Time::write_to()
.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Time
impl<'de> Deserialize<'de> for Time
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Time
Serialize this instance as string, similar to what write_to()
would do.
impl Display for Time
Serialize this instance as string, similar to what write_to()
would do.