-
Notifications
You must be signed in to change notification settings - Fork 37k
Add configurable date and time formats for blame information #284425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @lszomoruMatched files:
|
There was a problem hiding this 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 |
| 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); |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
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).
extensions/git/package.nls.json
Outdated
| "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.", |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
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.
| "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.", |
| 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); |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
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.
extensions/git/package.nls.json
Outdated
| "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')", |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
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.
| "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')", |
extensions/git/package.nls.json
Outdated
| "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')", |
Copilot
AI
Dec 19, 2025
There was a problem hiding this comment.
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.
| "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')", |
Fix #240861
Added
blame.dateFormatandblame.timeFormatsettings.