Expand description
A simple time structure that matches hg’s time representation.
Internally it’s unixtime (in GMT), and offset (GMT -1 = +3600).
Fields§
§unixtime: i64
§offset: i32
Implementations§
source§impl HgTime
impl HgTime
sourcepub const RANGE: RangeInclusive<HgTime> = _
pub const RANGE: RangeInclusive<HgTime> = _
Supported Range. This is to be compatible with Python stdlib.
The Python datetime
library can only express a limited range
of dates (0001-01-01 to 9999-12-31). Its strftime requires
year >= 1900.
sourcepub fn now() -> Option<Self>
pub fn now() -> Option<Self>
Return the current time with local timezone, or None
if the timestamp
is outside HgTime::RANGE
.
The local timezone can be affected by set_default_offset
.
pub fn to_utc(self) -> DateTime<Utc>
sourcepub fn set_as_now_for_testing(self)
pub fn set_as_now_for_testing(self)
Set as the faked “now”. Useful for testing.
This should only be used for testing.
sourcepub fn parse(date: &str) -> Option<Self>
pub fn parse(date: &str) -> Option<Self>
Parse a date string.
Return None
if it cannot be parsed.
This function matches mercurial.util.parsedate
, and can parse
some additional forms like 2 days ago
.
sourcepub fn parse_range(date: &str) -> Option<Range<Self>>
pub fn parse_range(date: &str) -> Option<Range<Self>>
Parse a date string as a range.
For example, Apr 2000
covers range Apr 1, 2000
to Apr 30, 2000
.
Also support more explicit ranges:
- START to END
-
START
- < END
sourcepub const fn min_value() -> Self
pub const fn min_value() -> Self
See HgTime::RANGE
for details.
sourcepub const fn max_value() -> Self
pub const fn max_value() -> Self
See HgTime::RANGE
for details.
sourcepub fn bounded(self) -> Option<Self>
pub fn bounded(self) -> Option<Self>
Return None
if timestamp is out of HgTime::RANGE
.
Trait Implementations§
source§impl From<HgTime> for NaiveDateTime
impl From<HgTime> for NaiveDateTime
source§impl PartialEq<HgTime> for HgTime
impl PartialEq<HgTime> for HgTime
source§impl PartialOrd<HgTime> for HgTime
impl PartialOrd<HgTime> for HgTime
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more