Skip to content

Commit b58134b

Browse files
committed
[features #189] simple UTC-offset support for git-features
1 parent 1388ebf commit b58134b

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ Provide a CLI to for the most basic user journey:
251251
[fossil-scm]: https://www.fossil-scm.org
252252

253253

254-
## Shortcomings
254+
## Shortcomings & Limitations
255255

256256
* **fetches using protocol V1 and stateful connections, i.e. ssh, git, file, may hang**
257257
* This can be fixed by making response parsing.
@@ -277,6 +277,7 @@ Provide a CLI to for the most basic user journey:
277277
* **git-url** _might_ be more restrictive than what git allows as for the most part, it uses a browser grade URL parser.
278278
* Thus far there is no proof for this, and as _potential remedy_ we could certainly re-implement exactly what git does
279279
to handle its URLs.
280+
* **local time** is currently impeded by [this issue](https://github.com/time-rs/time/issues/293#issuecomment-909158529) but it's planned to resolve it eventually.
280281

281282
## Credits
282283

cargo-features.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ All feature toggles are additive.
129129
* **cache-efficiency-debug**
130130
* Caches implement this by default, which costs nothing unless this feature is enabled
131131
* Count cache hits and misses and print that debug information on drop
132+
* **time**
133+
* Make the `time` module available with access to the local time as configured by the system.
132134

133135
### git-packetline
134136

git-features/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ progress = ["prodash"]
1717
parallel = ["crossbeam-utils", "crossbeam-channel", "num_cpus", "jwalk"]
1818
fast-sha1 = ["sha-1"]
1919
io-pipe = ["bytes"]
20-
time = ["libc"]
2120
crc32 = ["crc32fast"]
2221
zlib = ["flate2", "flate2/rust_backend", "quick-error"]
2322
zlib-ng-compat = ["flate2/zlib-ng-compat"]
@@ -76,7 +75,7 @@ flate2 = { version = "1.0.17", optional = true, default-features = false }
7675
quick-error = { version = "2.0.0", optional = true }
7776

7877
# time module
79-
libc = { version = "0.2.101", optional = true }
78+
time = { version = "0.3.2", optional = true, default-features = false, features = ["local-offset"] }
8079

8180
[package.metadata.docs.rs]
8281
all-features = true

git-features/src/time.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
1-
pub struct Local {
2-
seconds_since_epoch: i64,
3-
tz_offset_in_seconds: i64,
4-
}
5-
pub fn local_since_epoch() -> Local {
6-
todo!("implement localtime")
1+
///
2+
pub mod tz {
3+
mod error {
4+
use std::fmt;
5+
6+
/// The error returned by [`offset()`]
7+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8+
pub struct Error;
9+
10+
impl fmt::Display for Error {
11+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12+
f.write_str("The system's UTC offset could not be determined")
13+
}
14+
}
15+
16+
impl std::error::Error for Error {}
17+
}
18+
pub use error::Error;
19+
20+
/// The UTC offset in seconds
21+
pub type UTCOffsetInSeconds = i32;
22+
23+
/// Return time offset in seconds from UTC based on the current timezone.
24+
///
25+
/// Note that there may be various legitimate reasons for failure, which should be accounted for.
26+
pub fn current_utc_offset() -> Result<UTCOffsetInSeconds, Error> {
27+
// TODO: make this work without cfg(unsound_local_offset), see
28+
// https://github.com/time-rs/time/issues/293#issuecomment-909158529
29+
time::UtcOffset::current_local_offset()
30+
.map(|ofs| ofs.whole_seconds())
31+
.map_err(|_| Error)
32+
}
733
}

0 commit comments

Comments
 (0)