Skip to content

Commit

Permalink
cli: show timestamp in local timezone and without millis and offset
Browse files Browse the repository at this point in the history
As discussed in #2900, the milliseconds are rarely useful, and it can
be confusing with different timezones because it makes harder to
compare timestamps.

I added an environment variable to control the timestamp in a
cross-platform way. I didn't document because it exists only for tests
(like `JJ_RANDOMNESS_SEED`).

Closes #2900
  • Loading branch information
martinvonz committed Mar 20, 2024
1 parent 4fbe6ae commit fcad432
Show file tree
Hide file tree
Showing 20 changed files with 175 additions and 174 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Commit templates now support `immutable` keyword.

* Timestamps are now shown in local timezone and without milliseconds and
timezone offset by default.

### Fixed bugs

## [0.15.1] - 2024-03-06
Expand Down
2 changes: 1 addition & 1 deletion cli/src/config/templates.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ commit_summary_separator = 'label("separator", " | ")'
++ " (" ++ format_timestamp(signature.timestamp()) ++ ")"'''
'format_time_range(time_range)' = '''
time_range.start().ago() ++ label("time", ", lasted ") ++ time_range.duration()'''
'format_timestamp(timestamp)' = 'timestamp'
'format_timestamp(timestamp)' = 'timestamp.local().format("%Y-%m-%d %H:%M:%S")'

# We have "hidden" override "divergent", since a hidden revision does not cause
# change id conflicts and is not affected by such conflicts; you have to use the
Expand Down
5 changes: 4 additions & 1 deletion cli/src/template_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,10 @@ fn builtin_timestamp_methods<'a, L: TemplateLanguage<'a> + ?Sized>(
});
map.insert("local", |language, _build_ctx, self_property, function| {
template_parser::expect_no_arguments(function)?;
let tz_offset = chrono::Local::now().offset().local_minus_utc() / 60;
let tz_offset = std::env::var("JJ_TZ_OFFSET_MINS")
.ok()
.and_then(|tz_string| tz_string.parse::<i32>().ok())
.unwrap_or_else(|| chrono::Local::now().offset().local_minus_utc() / 60);
let out_property = TemplateFunction::new(self_property, move |mut timestamp| {
timestamp.tz_offset = tz_offset;
Ok(timestamp)
Expand Down
1 change: 1 addition & 0 deletions cli/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl TestEnvironment {
cmd.env("JJ_EMAIL", "[email protected]");
cmd.env("JJ_OP_HOSTNAME", "host.example.com");
cmd.env("JJ_OP_USERNAME", "test-username");
cmd.env("JJ_TZ_OFFSET_MINS", "660");

let mut command_number = self.command_number.borrow_mut();
*command_number += 1;
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_abandon_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fn test_double_abandon() {
insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["log", "--no-graph", "-r", "a"])
, @r###"
rlvkpnrz [email protected] 2001-02-03 04:05:09.000 +07:00 a 2443ea76
rlvkpnrz [email protected] 2001-02-03 08:05:09 a 2443ea76
a
"###);

Expand Down
10 changes: 5 additions & 5 deletions cli/tests/test_builtin_aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn test_builtin_alias_trunk_matches_main() {

let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "trunk()"]);
insta::assert_snapshot!(stdout, @r###"
◉ lzmmnrxq [email protected] 2001-02-03 04:05:08.000 +07:00 main 45a3aa29
◉ lzmmnrxq [email protected] 2001-02-03 08:05:08 main 45a3aa29
│ (empty) description 1
~
"###);
Expand All @@ -64,7 +64,7 @@ fn test_builtin_alias_trunk_matches_master() {

let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "trunk()"]);
insta::assert_snapshot!(stdout, @r###"
◉ lzmmnrxq [email protected] 2001-02-03 04:05:08.000 +07:00 master 45a3aa29
◉ lzmmnrxq [email protected] 2001-02-03 08:05:08 master 45a3aa29
│ (empty) description 1
~
"###);
Expand All @@ -76,7 +76,7 @@ fn test_builtin_alias_trunk_matches_trunk() {

let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "trunk()"]);
insta::assert_snapshot!(stdout, @r###"
◉ lzmmnrxq [email protected] 2001-02-03 04:05:08.000 +07:00 trunk 45a3aa29
◉ lzmmnrxq [email protected] 2001-02-03 08:05:08 trunk 45a3aa29
│ (empty) description 1
~
"###);
Expand All @@ -91,7 +91,7 @@ fn test_builtin_alias_trunk_matches_exactly_one_commit() {

let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "trunk()"]);
insta::assert_snapshot!(stdout, @r###"
◉ lzmmnrxq [email protected] 2001-02-03 04:05:08.000 +07:00 main 45a3aa29
◉ lzmmnrxq [email protected] 2001-02-03 08:05:08 main 45a3aa29
│ (empty) description 1
~
"###);
Expand All @@ -107,7 +107,7 @@ fn test_builtin_alias_trunk_override_alias() {

let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "trunk()"]);
insta::assert_snapshot!(stdout, @r###"
◉ lzmmnrxq [email protected] 2001-02-03 04:05:08.000 +07:00 override-trunk 45a3aa29
◉ lzmmnrxq [email protected] 2001-02-03 08:05:08 override-trunk 45a3aa29
│ (empty) description 1
~
"###);
Expand Down
98 changes: 49 additions & 49 deletions cli/tests/test_commit_template.rs

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions cli/tests/test_diff_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,14 +779,14 @@ fn test_diff_external_tool() {

insta::assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["log", "-p", "--tool=fake-diff-editor"]), @r###"
@ rlvkpnrz [email protected] 2001-02-03 04:05:09.000 +07:00 0cba70c7
@ rlvkpnrz [email protected] 2001-02-03 08:05:09 0cba70c7
│ (no description set)
│ file1
│ file2
│ --
│ file2
│ file3
◉ qpvuntsm [email protected] 2001-02-03 04:05:08.000 +07:00 39b5a56f
◉ qpvuntsm [email protected] 2001-02-03 08:05:08 39b5a56f
│ (no description set)
│ --
│ file1
Expand All @@ -799,8 +799,8 @@ fn test_diff_external_tool() {
test_env.jj_cmd_success(&repo_path, &["show", "--tool=fake-diff-editor"]), @r###"
Commit ID: 0cba70c72186eabb5a2f91be63a8366b9f6da6c6
Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
Author: Test User <[email protected]> (2001-02-03 04:05:08.000 +07:00)
Committer: Test User <[email protected]> (2001-02-03 04:05:09.000 +07:00)
Author: Test User <[email protected]> (2001-02-03 08:05:08)
Committer: Test User <[email protected]> (2001-02-03 08:05:09)
(no description set)
Expand Down Expand Up @@ -846,8 +846,8 @@ fn test_diff_external_tool() {
insta::assert_snapshot!(stdout, @r###"
Commit ID: 0cba70c72186eabb5a2f91be63a8366b9f6da6c6
Change ID: rlvkpnrzqnoowoytxnquwvuryrwnrmlp
Author: Test User <[email protected]> (2001-02-03 04:05:08.000 +07:00)
Committer: Test User <[email protected]> (2001-02-03 04:05:09.000 +07:00)
Author: Test User <[email protected]> (2001-02-03 08:05:08)
Committer: Test User <[email protected]> (2001-02-03 08:05:09)
(no description set)
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/test_git_import_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn test_git_export_undo() {
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["log", "-ra@git"]), @r###"
@ qpvuntsm [email protected] 2001-02-03 04:05:07.000 +07:00 a 230dd059
@ qpvuntsm [email protected] 2001-02-03 08:05:07 a 230dd059
│ (empty) (no description set)
~
"###);
Expand Down Expand Up @@ -121,7 +121,7 @@ fn test_git_export_undo() {
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @"");
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["log", "-ra@git"]), @r###"
@ qpvuntsm [email protected] 2001-02-03 04:05:07.000 +07:00 a 230dd059
@ qpvuntsm [email protected] 2001-02-03 08:05:07 a 230dd059
│ (empty) (no description set)
~
"###);
Expand Down
32 changes: 16 additions & 16 deletions cli/tests/test_git_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn test_git_init_external(bare: bool) {
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "@-"]);
insta::allow_duplicates! {
insta::assert_snapshot!(stdout, @r###"
◉ mwrttmos [email protected] 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git 8d698d4a
◉ mwrttmos [email protected] 1970-01-01 11:02:03 my-branch HEAD@git 8d698d4a
│ My commit message
~
"###);
Expand Down Expand Up @@ -205,7 +205,7 @@ fn test_git_init_colocated_via_git_repo_path() {
// Check that the Git repo's HEAD got checked out
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ mwrttmos [email protected] 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git 8d698d4a
◉ mwrttmos [email protected] 1970-01-01 11:02:03 my-branch HEAD@git 8d698d4a
│ My commit message
~
"###);
Expand All @@ -214,7 +214,7 @@ fn test_git_init_colocated_via_git_repo_path() {
test_env.jj_cmd_ok(&workspace_root, &["new"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ sqpuoqvx [email protected] 2001-02-03 04:05:07.000 +07:00 HEAD@git f61b77cd
◉ sqpuoqvx [email protected] 2001-02-03 08:05:07 HEAD@git f61b77cd
│ (no description set)
~
"###);
Expand Down Expand Up @@ -242,7 +242,7 @@ fn test_git_init_colocated_via_git_repo_path_gitlink() {
// Check that the Git repo's HEAD got checked out
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ mwrttmos [email protected] 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git 8d698d4a
◉ mwrttmos [email protected] 1970-01-01 11:02:03 my-branch HEAD@git 8d698d4a
│ My commit message
~
"###);
Expand All @@ -251,7 +251,7 @@ fn test_git_init_colocated_via_git_repo_path_gitlink() {
test_env.jj_cmd_ok(&workspace_root, &["new"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ sqpuoqvx [email protected] 2001-02-03 04:05:07.000 +07:00 HEAD@git f61b77cd
◉ sqpuoqvx [email protected] 2001-02-03 08:05:07 HEAD@git f61b77cd
│ (no description set)
~
"###);
Expand All @@ -278,7 +278,7 @@ fn test_git_init_colocated_via_git_repo_path_symlink_directory() {
// Check that the Git repo's HEAD got checked out
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ mwrttmos [email protected] 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git 8d698d4a
◉ mwrttmos [email protected] 1970-01-01 11:02:03 my-branch HEAD@git 8d698d4a
│ My commit message
~
"###);
Expand All @@ -287,7 +287,7 @@ fn test_git_init_colocated_via_git_repo_path_symlink_directory() {
test_env.jj_cmd_ok(&workspace_root, &["new"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ sqpuoqvx [email protected] 2001-02-03 04:05:07.000 +07:00 HEAD@git f61b77cd
◉ sqpuoqvx [email protected] 2001-02-03 08:05:07 HEAD@git f61b77cd
│ (no description set)
~
"###);
Expand Down Expand Up @@ -317,7 +317,7 @@ fn test_git_init_colocated_via_git_repo_path_symlink_directory_without_bare_conf
// Check that the Git repo's HEAD got checked out
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ mwrttmos [email protected] 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git 8d698d4a
◉ mwrttmos [email protected] 1970-01-01 11:02:03 my-branch HEAD@git 8d698d4a
│ My commit message
~
"###);
Expand All @@ -326,7 +326,7 @@ fn test_git_init_colocated_via_git_repo_path_symlink_directory_without_bare_conf
test_env.jj_cmd_ok(&workspace_root, &["new"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ sqpuoqvx [email protected] 2001-02-03 04:05:07.000 +07:00 HEAD@git f61b77cd
◉ sqpuoqvx [email protected] 2001-02-03 08:05:07 HEAD@git f61b77cd
│ (no description set)
~
"###);
Expand Down Expand Up @@ -358,7 +358,7 @@ fn test_git_init_colocated_via_git_repo_path_symlink_gitlink() {
// Check that the Git repo's HEAD got checked out
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ mwrttmos [email protected] 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git 8d698d4a
◉ mwrttmos [email protected] 1970-01-01 11:02:03 my-branch HEAD@git 8d698d4a
│ My commit message
~
"###);
Expand All @@ -367,7 +367,7 @@ fn test_git_init_colocated_via_git_repo_path_symlink_gitlink() {
test_env.jj_cmd_ok(&workspace_root, &["new"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ sqpuoqvx [email protected] 2001-02-03 04:05:07.000 +07:00 HEAD@git f61b77cd
◉ sqpuoqvx [email protected] 2001-02-03 08:05:07 HEAD@git f61b77cd
│ (no description set)
~
"###);
Expand Down Expand Up @@ -481,12 +481,12 @@ fn test_git_init_colocated_dirty_working_copy() {
// Working-copy changes should have been snapshotted.
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-s", "--ignore-working-copy"]);
insta::assert_snapshot!(stdout, @r###"
@ sqpuoqvx [email protected] 2001-02-03 04:05:07.000 +07:00 cd1e144d
@ sqpuoqvx [email protected] 2001-02-03 08:05:07 cd1e144d
│ (no description set)
│ A new-staged-file
│ M some-file
│ A unstaged-file
◉ mwrttmos [email protected] 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git 8d698d4a
◉ mwrttmos [email protected] 1970-01-01 11:02:03 my-branch HEAD@git 8d698d4a
│ My commit message
│ A some-file
◉ zzzzzzzz root() 00000000
Expand Down Expand Up @@ -532,7 +532,7 @@ fn test_git_init_external_but_git_dir_exists() {
test_env.jj_cmd_ok(&workspace_root, &["new"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ qpvuntsm [email protected] 2001-02-03 04:05:07.000 +07:00 230dd059
◉ qpvuntsm [email protected] 2001-02-03 08:05:07 230dd059
│ (empty) (no description set)
~
"###);
Expand All @@ -555,7 +555,7 @@ fn test_git_init_colocated_via_flag_git_dir_exists() {
// Check that the Git repo's HEAD got checked out
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ mwrttmos [email protected] 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git 8d698d4a
◉ mwrttmos [email protected] 1970-01-01 11:02:03 my-branch HEAD@git 8d698d4a
│ My commit message
~
"###);
Expand All @@ -564,7 +564,7 @@ fn test_git_init_colocated_via_flag_git_dir_exists() {
test_env.jj_cmd_ok(&workspace_root, &["new"]);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]);
insta::assert_snapshot!(stdout, @r###"
◉ sqpuoqvx [email protected] 2001-02-03 04:05:07.000 +07:00 HEAD@git f61b77cd
◉ sqpuoqvx [email protected] 2001-02-03 08:05:07 HEAD@git f61b77cd
│ (no description set)
~
"###);
Expand Down
12 changes: 6 additions & 6 deletions cli/tests/test_git_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,11 @@ fn test_git_push_multiple() {
"###);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-rall()"]);
insta::assert_snapshot!(stdout, @r###"
@ yqosqzyt [email protected] 2001-02-03 04:05:17.000 +07:00 branch2 my-branch 15dcdaa4
@ yqosqzyt [email protected] 2001-02-03 08:05:17 branch2 my-branch 15dcdaa4
│ (empty) foo
│ ◉ rlzusymt [email protected] 2001-02-03 04:05:10.000 +07:00 8476341e
│ ◉ rlzusymt [email protected] 2001-02-03 08:05:10 8476341e
├─╯ (empty) description 2
│ ◉ lzmmnrxq [email protected] 2001-02-03 04:05:08.000 +07:00 45a3aa29
│ ◉ lzmmnrxq [email protected] 2001-02-03 08:05:08 45a3aa29
├─╯ (empty) description 1
◉ zzzzzzzz root() 00000000
"###);
Expand Down Expand Up @@ -672,11 +672,11 @@ fn test_git_push_deleted() {
"###);
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-rall()"]);
insta::assert_snapshot!(stdout, @r###"
◉ rlzusymt [email protected] 2001-02-03 04:05:10.000 +07:00 branch2 8476341e
◉ rlzusymt [email protected] 2001-02-03 08:05:10 branch2 8476341e
│ (empty) description 2
│ ◉ lzmmnrxq [email protected] 2001-02-03 04:05:08.000 +07:00 45a3aa29
│ ◉ lzmmnrxq [email protected] 2001-02-03 08:05:08 45a3aa29
├─╯ (empty) description 1
│ @ yqosqzyt [email protected] 2001-02-03 04:05:13.000 +07:00 5b36783c
│ @ yqosqzyt [email protected] 2001-02-03 08:05:13 5b36783c
├─╯ (empty) (no description set)
◉ zzzzzzzz root() 00000000
"###);
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/test_global_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ fn test_no_subcommand() {
test_env.jj_cmd_ok(&repo_path, &["branch", "create", "show"]);
// TODO: test_env.jj_cmd_ok(&repo_path, &["-r", "help"])
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["-r", "log"]), @r###"
@ qpvuntsm [email protected] 2001-02-03 04:05:07.000 +07:00 help log show 230dd059
@ qpvuntsm [email protected] 2001-02-03 08:05:07 help log show 230dd059
│ (empty) (no description set)
~
"###);
insta::assert_snapshot!(test_env.jj_cmd_success(&repo_path, &["-r", "show"]), @r###"
@ qpvuntsm [email protected] 2001-02-03 04:05:07.000 +07:00 help log show 230dd059
@ qpvuntsm [email protected] 2001-02-03 08:05:07 help log show 230dd059
│ (empty) (no description set)
~
"###);
Expand Down
12 changes: 6 additions & 6 deletions cli/tests/test_immutable_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ fn test_rewrite_immutable_generic() {
std::fs::write(repo_path.join("file"), "c").unwrap();
let stdout = test_env.jj_cmd_success(&repo_path, &["log"]);
insta::assert_snapshot!(stdout, @r###"
@ mzvwutvl [email protected] 2001-02-03 04:05:12.000 +07:00 78ebd449
@ mzvwutvl [email protected] 2001-02-03 08:05:12 78ebd449
│ c
│ ◉ kkmpptxz [email protected] 2001-02-03 04:05:10.000 +07:00 main c8d4c7ca
│ ◉ kkmpptxz [email protected] 2001-02-03 08:05:10 main c8d4c7ca
├─╯ b
◉ qpvuntsm [email protected] 2001-02-03 04:05:08.000 +07:00 46a8dc51
◉ qpvuntsm [email protected] 2001-02-03 08:05:08 46a8dc51
│ a
◉ zzzzzzzz root() 00000000
"###);
Expand Down Expand Up @@ -90,14 +90,14 @@ fn test_rewrite_immutable_commands() {
// Log shows mutable commits, their parents, and trunk() by default
let stdout = test_env.jj_cmd_success(&repo_path, &["log"]);
insta::assert_snapshot!(stdout, @r###"
@ yqosqzyt [email protected] 2001-02-03 04:05:13.000 +07:00 3f89addf
@ yqosqzyt [email protected] 2001-02-03 08:05:13 3f89addf
│ (empty) (no description set)
│ ◉ mzvwutvl [email protected] 2001-02-03 04:05:11.000 +07:00 main 3d14df18 conflict
│ ◉ mzvwutvl [email protected] 2001-02-03 08:05:11 main 3d14df18 conflict
╭─┤ (empty) merge
│ │
│ ~
◉ kkmpptxz [email protected] 2001-02-03 04:05:10.000 +07:00 c8d4c7ca
◉ kkmpptxz [email protected] 2001-02-03 08:05:10 c8d4c7ca
│ b
~
"###);
Expand Down
Loading

0 comments on commit fcad432

Please sign in to comment.