mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-11-21 18:40:40 +08:00
git-ext: Display/parse timezone offset in the format git2 expects.
The previous implementation of Display for Time is shown as absolute minutes, whereas git expects HH:MM format. The FromStr implementation for Author also did not correctly convert +/-HHMM to absolute minutes. Signed-off-by: xphoniex <xphoniex@users.noreply.github.com> Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
This commit is contained in:
@@ -60,7 +60,9 @@ impl From<git2::Time> for Time {
|
||||
impl fmt::Display for Time {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let sign = if self.offset.is_negative() { '-' } else { '+' };
|
||||
write!(f, "{} {}{:0>4}", self.seconds, sign, self.offset.abs())
|
||||
let hours = self.offset.abs() / 60;
|
||||
let minutes = self.offset.abs() % 60;
|
||||
write!(f, "{} {}{:0>2}{:0>2}", self.seconds, sign, hours, minutes)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +112,17 @@ impl FromStr for Author {
|
||||
let mut components = s.split(' ');
|
||||
let offset = match components.next_back() {
|
||||
None => return Err(ParseError::Missing("offset")),
|
||||
Some(offset) => offset.parse::<i32>().map_err(ParseError::Offset)?,
|
||||
Some(offset) => {
|
||||
// The offset is in the form of timezone offset,
|
||||
// e.g. +0200, -0100. This needs to be converted into
|
||||
// minutes. The first two digits in the offset are the
|
||||
// number of hours in the offset, while the latter two
|
||||
// digits are the number of minutes in the offset.
|
||||
let tz_offset = offset.parse::<i32>().map_err(ParseError::Offset)?;
|
||||
let hours = tz_offset / 100;
|
||||
let minutes = tz_offset % 100;
|
||||
hours * 60 + minutes
|
||||
},
|
||||
};
|
||||
let time = match components.next_back() {
|
||||
None => return Err(ParseError::Missing("time")),
|
||||
|
||||
Reference in New Issue
Block a user