pub struct HgTime {
pub unixtime: i64,
pub offset: i32,
}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: i32Implementations§
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 clear_now_for_testing()
pub fn clear_now_for_testing()
Remove faked “now”. Reverts “set_as_now_for_testing” effect.
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 fn parse_hg_internal_format(date: &str) -> Option<Option<Self>>
pub fn parse_hg_internal_format(date: &str) -> Option<Option<Self>>
Parse a date from a Sapling-internal format. Tolerates floating point timestamps for compatibility reasons.
Return None if cannot be parsed, Option<None> if the parsed date is invalid
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.