Skip to content

fix: always consider timestamps as UTC when loading from commits #646

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion git-date/src/time/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ impl Time {
fn to_time(self) -> time::OffsetDateTime {
time::OffsetDateTime::from_unix_timestamp(self.seconds_since_unix_epoch as i64)
.expect("always valid unix time")
.replace_offset(time::UtcOffset::from_whole_seconds(self.offset_in_seconds).expect("valid offset"))
.to_offset(time::UtcOffset::from_whole_seconds(self.offset_in_seconds).expect("valid offset"))
}
}
12 changes: 6 additions & 6 deletions git-date/tests/time/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use time::macros::format_description;

#[test]
fn short() {
assert_eq!(time().format(format::SHORT), "1973-11-29");
assert_eq!(time().format(format::SHORT), "1973-11-30");
}

#[test]
Expand All @@ -25,32 +25,32 @@ fn raw() {

#[test]
fn iso8601() {
assert_eq!(time().format(format::ISO8601), "1973-11-29 21:33:09 +0230");
assert_eq!(time().format(format::ISO8601), "1973-11-30 00:03:09 +0230");
}

#[test]
fn iso8601_strict() {
assert_eq!(time().format(format::ISO8601_STRICT), "1973-11-29T21:33:09+02:30");
assert_eq!(time().format(format::ISO8601_STRICT), "1973-11-30T00:03:09+02:30");
}

#[test]
fn rfc2822() {
assert_eq!(time().format(format::RFC2822), "Thu, 29 Nov 1973 21:33:09 +0230");
assert_eq!(time().format(format::RFC2822), "Fri, 30 Nov 1973 00:03:09 +0230");
}

#[test]
fn default() {
assert_eq!(
time().format(git_date::time::format::DEFAULT),
"Thu Nov 29 1973 21:33:09 +0230"
"Fri Nov 30 1973 00:03:09 +0230"
);
}

#[test]
fn custom_compile_time() {
assert_eq!(
time().format(format_description!("[year]-[month]-[day] [hour]:[minute]:[second]")),
"1973-11-29 21:33:09",
"1973-11-30 00:03:09",
);
}

Expand Down