pub struct Time {
pub seconds: SecondsSinceUnixEpoch,
pub offset: OffsetInSeconds,
pub sign: Sign,
}Expand description
A timestamp with timezone.
Fields§
§seconds: SecondsSinceUnixEpochThe seconds that passed since UNIX epoch. This makes it UTC, or <seconds>+0000.
offset: OffsetInSecondsThe time’s offset in seconds, which may be negative to match the sign field.
sign: Signthe sign of offset, used to encode -0000 which would otherwise lose sign information.
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 fn to_bstring(&self) -> BString
pub fn to_bstring(&self) -> BString
Serialize this instance into memory, similar to what write_to() would do with arbitrary Write implementations.
§Panics
If the underlying call fails as this instance can’t be represented, typically due to an invalid offset.
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 fn size(&self) -> usize
pub fn size(&self) -> usize
Computes the number of bytes necessary to write it using Time::write_to().