Skip to content

Conversation

@SalerSimo
Copy link
Contributor

Fix #240861
Added blame.dateFormat and blame.timeFormat settings.

Copilot AI review requested due to automatic review settings December 19, 2025 11:51
@vs-code-engineering
Copy link

vs-code-engineering bot commented Dec 19, 2025

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@lszomoru

Matched files:

  • extensions/git/package.json
  • extensions/git/package.nls.json
  • extensions/git/src/hover.ts

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds two new configuration settings (git.blame.dateFormat and git.blame.timeFormat) that allow users to customize how dates and times are displayed in Git blame information. The implementation modifies the hover display logic to respect these new settings.

Key changes:

  • Added configurable date format options (date-long, date-short, locale) and time format options (locale, 12hour, 24hour)
  • Modified the hover display logic to apply these formatting preferences when showing blame information
  • Added localized configuration descriptions and enum values

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
extensions/git/src/hover.ts Modified to read the new configuration settings and apply date/time formatting options when displaying blame information in hover tooltips
extensions/git/package.json Added two new configuration settings: git.blame.dateFormat and git.blame.timeFormat with their enum values and defaults
extensions/git/package.nls.json Added localized description strings for the new configuration settings and their enum values

Comment on lines +93 to +121
const config = workspace.getConfiguration('git');
let options: Intl.DateTimeFormatOptions = {};
switch (config.get<string>('blame.dateFormat')) {
case 'date-short':
options = { year: '2-digit', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' };
break;
case 'date-long':
options = { year: 'numeric', month: 'long', day: '2-digit', hour: '2-digit', minute: '2-digit' };
break;
case 'locale':
// leave empty to use locale default
break;
default:
break;
}
switch (config.get<string>('blame.timeFormat')) {
case 'locale':
// Use system's default time format (hour12 not set)
break;
case '12hour':
options.hour12 = true;
break;
case '24hour':
options.hour12 = false;
break;
default:
break;
}
const dateString = new Date(authorDate).toLocaleString(undefined, options);
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new blame.dateFormat and blame.timeFormat settings are not applied to the authorDate template token in formatBlameInformationMessage method in blame.ts (line 198). According to the documentation in package.nls.json line 310, these settings should affect "the authorDate and authorDateAgo variables in the blame information editor decoration and status bar item". This means the same date formatting logic should be applied here to ensure consistency across all blame displays (hover, editor decoration, and status bar).

Copilot uses AI. Check for mistakes.
"config.blameStatusBarItem.enabled": "Controls whether to show blame information in the status bar.",
"config.blameStatusBarItem.template": "Template for the blame information status bar item. Supported variables:\n\n* `hash`: Commit hash\n\n* `hashShort`: First N characters of the commit hash according to `#git.commitShortHashLength#`\n\n* `subject`: First line of the commit message\n\n* `authorName`: Author name\n\n* `authorEmail`: Author email\n\n* `authorDate`: Author date\n\n* `authorDateAgo`: Time difference between now and the author date\n\n",
"config.blameIgnoreWhitespace": "Controls whether to ignore whitespace changes when computing blame information.",
"config.blameDateFormat": "Specifies the format used for the `authorDate` and `authorDateAgo` variables in the blame information editor decoration and status bar item.",
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description mentions authorDateAgo being affected by these settings, but authorDateAgo uses the fromNow function which generates relative time strings (e.g., "2 hours ago") and is not affected by the blame.dateFormat or blame.timeFormat settings. Only authorDate is affected by these settings. Consider removing the reference to authorDateAgo from this description to avoid confusion.

Suggested change
"config.blameDateFormat": "Specifies the format used for the `authorDate` and `authorDateAgo` variables in the blame information editor decoration and status bar item.",
"config.blameDateFormat": "Specifies the format used for the `authorDate` variable in the blame information editor decoration and status bar item.",

Copilot uses AI. Check for mistakes.
Comment on lines +93 to +121
const config = workspace.getConfiguration('git');
let options: Intl.DateTimeFormatOptions = {};
switch (config.get<string>('blame.dateFormat')) {
case 'date-short':
options = { year: '2-digit', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' };
break;
case 'date-long':
options = { year: 'numeric', month: 'long', day: '2-digit', hour: '2-digit', minute: '2-digit' };
break;
case 'locale':
// leave empty to use locale default
break;
default:
break;
}
switch (config.get<string>('blame.timeFormat')) {
case 'locale':
// Use system's default time format (hour12 not set)
break;
case '12hour':
options.hour12 = true;
break;
case '24hour':
options.hour12 = false;
break;
default:
break;
}
const dateString = new Date(authorDate).toLocaleString(undefined, options);
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The date/time formatting logic is duplicated here and should also be in blame.ts (line 198). Consider extracting this logic into a shared utility function to avoid code duplication and ensure consistent formatting behavior across all blame displays. The function could be added to util.ts and called from both hover.ts and blame.ts.

Copilot uses AI. Check for mistakes.
"config.blameStatusBarItem.template": "Template for the blame information status bar item. Supported variables:\n\n* `hash`: Commit hash\n\n* `hashShort`: First N characters of the commit hash according to `#git.commitShortHashLength#`\n\n* `subject`: First line of the commit message\n\n* `authorName`: Author name\n\n* `authorEmail`: Author email\n\n* `authorDate`: Author date\n\n* `authorDateAgo`: Time difference between now and the author date\n\n",
"config.blameIgnoreWhitespace": "Controls whether to ignore whitespace changes when computing blame information.",
"config.blameDateFormat": "Specifies the format used for the `authorDate` and `authorDateAgo` variables in the blame information editor decoration and status bar item.",
"config.blameDateFormat.date-long": "Use a long date format (e.g. 'December 18, 2025')",
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example for the long date format is misleading. The format includes time fields (hour and minute per line 100 in hover.ts), so the output will include time information, not just the date. Consider updating the example to something like "Use a long date format (e.g., 'December 18, 2025, 3:30 PM')" to accurately reflect what users will see.

Suggested change
"config.blameDateFormat.date-long": "Use a long date format (e.g. 'December 18, 2025')",
"config.blameDateFormat.date-long": "Use a long date format (e.g. 'December 18, 2025, 3:30 PM')",

Copilot uses AI. Check for mistakes.
"config.blameIgnoreWhitespace": "Controls whether to ignore whitespace changes when computing blame information.",
"config.blameDateFormat": "Specifies the format used for the `authorDate` and `authorDateAgo` variables in the blame information editor decoration and status bar item.",
"config.blameDateFormat.date-long": "Use a long date format (e.g. 'December 18, 2025')",
"config.blameDateFormat.date-short": "Use a short date format (e.g. '12/18/2025')",
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example for the short date format is misleading. The format includes time fields (hour and minute per line 97 in hover.ts), so the output will include time information, not just the date. Consider updating the example to something like "Use a short date format (e.g., '12/18/25, 3:30 PM')" to accurately reflect what users will see.

Suggested change
"config.blameDateFormat.date-short": "Use a short date format (e.g. '12/18/2025')",
"config.blameDateFormat.date-short": "Use a short date format (e.g. '12/18/25, 3:30 PM')",

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git - blame date formatting

2 participants