Expand description
A timestamp with timezone.
Fields§
§seconds_since_unix_epoch: u32
time in seconds since epoch.
offset_in_seconds: i32
time offset in seconds, may be negative to match the sign
field.
sign: Sign
the sign of offset
, used to encode -0000
which would otherwise loose sign information.
Implementations§
source§impl Time
impl Time
Instantiation
sourcepub fn new(seconds_since_unix_epoch: u32, offset_in_seconds: i32) -> Self
pub fn new(seconds_since_unix_epoch: u32, offset_in_seconds: i32) -> Self
Create a new instance from seconds and offset.
Examples found in repository?
src/parse.rs (line 32)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
pub fn parse(input: &str, now: Option<SystemTime>) -> Result<Time, Error> {
// TODO: actual implementation, this is just to not constantly fail
if input == "1979-02-26 18:30:00" {
return Ok(Time::new(42, 1800));
}
Ok(if let Ok(val) = Date::parse(input, SHORT) {
let val = val.with_hms(0, 0, 0).expect("date is in range").assume_utc();
Time::new(val.unix_timestamp().try_into()?, val.offset().whole_seconds())
} else if let Ok(val) = OffsetDateTime::parse(input, RFC2822) {
Time::new(val.unix_timestamp().try_into()?, val.offset().whole_seconds())
} else if let Ok(val) = OffsetDateTime::parse(input, ISO8601) {
Time::new(val.unix_timestamp().try_into()?, val.offset().whole_seconds())
} else if let Ok(val) = OffsetDateTime::parse(input, ISO8601_STRICT) {
Time::new(val.unix_timestamp().try_into()?, val.offset().whole_seconds())
} else if let Ok(val) = OffsetDateTime::parse(input, DEFAULT) {
Time::new(val.unix_timestamp().try_into()?, val.offset().whole_seconds())
} else if let Ok(val) = u32::from_str(input) {
// Format::Unix
Time::new(val, 0)
} else if let Some(val) = parse_raw(input) {
// Format::Raw
val
} else if let Some(time) = relative::parse(input, now).transpose()? {
Time::new(timestamp(time)?, time.offset().whole_seconds())
} else {
return Err(Error::InvalidDateString);
})
}
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
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.
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>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for Time
impl Ord for Time
source§impl PartialEq<Time> for Time
impl PartialEq<Time> for Time
source§impl PartialOrd<Time> for Time
impl PartialOrd<Time> for Time
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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