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.

Closes #2900
  • Loading branch information
martinvonz committed Feb 22, 2024
1 parent c32b68e commit b632881
Show file tree
Hide file tree
Showing 19 changed files with 169 additions and 171 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* In the templating language, Timestamps now have a `.local()` method for
converting to the local timezone.

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

* `jj next/prev` now infer `--edit` when you're already editing a non-head
commit (a commit with children).

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 @@ -143,7 +143,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
1 change: 1 addition & 0 deletions cli/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl TestEnvironment {
}
cmd.env("RUST_BACKTRACE", "1");
cmd.env("HOME", self.home_dir.to_str().unwrap());
cmd.env("TZ", "UTC-11:00");
cmd.env("JJ_CONFIG", self.config_path.to_str().unwrap());
cmd.env("JJ_USER", "Test User");
cmd.env("JJ_EMAIL", "[email protected]");
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 @@ -329,7 +329,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 @@ -676,14 +676,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 @@ -696,8 +696,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 @@ -743,8 +743,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
28 changes: 14 additions & 14 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 @@ -203,7 +203,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 @@ -212,7 +212,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 @@ -240,7 +240,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 @@ -249,7 +249,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 @@ -276,7 +276,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 @@ -285,7 +285,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 @@ -315,7 +315,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 @@ -324,7 +324,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 @@ -356,7 +356,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 @@ -365,7 +365,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 @@ -479,12 +479,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 @@ -530,7 +530,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 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 @@ -670,11 +670,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 @@ -97,14 +97,14 @@ fn test_rewrite_immutable_commands() {
// Log shows mutable commits and immutable heads 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 16ca9d80 conflict
│ ◉ mzvwutvl [email protected] 2001-02-03 08:05:11 main 16ca9d80 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 b632881

Please sign in to comment.