Skip to content

Commit

Permalink
changelogger: Normalize UTC timezone (#37436)
Browse files Browse the repository at this point in the history
It seems that some versions of git may be returning `Z` rather than
`+00:00` when reporting timezones from `%cI`, which broke a test.
Normalize it to `Z` always so the test can have a consistent value to
expect.
  • Loading branch information
anomiex committed May 17, 2024
1 parent 7b46749 commit e80078a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Fix test by always using `Z`, not `+00:00`, for UTC timezones. No functionality change as both are equivalent ISO timestamps.


2 changes: 1 addition & 1 deletion projects/packages/changelogger/src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
class Application extends SymfonyApplication {

const VERSION = '4.2.3';
const VERSION = '4.2.4-alpha';

/**
* Constructor.
Expand Down
4 changes: 4 additions & 0 deletions projects/packages/changelogger/src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ public static function getRepoData( $file, OutputInterface $output, DebugFormatt
// Timestamp.
if ( isset( $cmd_output[0] ) && preg_match( '/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-]\d{2}:\d{2})$/', $cmd_output[0] ) ) {
$repo_data['timestamp'] = $cmd_output[0];
// Normalize UTC
if ( substr( $repo_data['timestamp'], -6 ) === '+00:00' ) {
$repo_data['timestamp'] = substr( $repo_data['timestamp'], 0, -6 ) . 'Z';
}
}

// PR number.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public function testGetRepoData() {

$this->assertSame(
array(
'timestamp' => '2021-02-02T22:22:22+00:00',
'timestamp' => '2021-02-02T22:22:22Z',
'pr-num' => '123',
),
Utils::getRepoData( 'in-git.txt', $output, $helper )
Expand All @@ -399,7 +399,7 @@ public function testGetRepoData() {
// Test the second commit.
$this->assertSame(
array(
'timestamp' => '2021-02-02T22:22:22+00:00',
'timestamp' => '2021-02-02T22:22:22Z',
'pr-num' => '124',
),
Utils::getRepoData( 'in-git2.txt', $output, $helper )
Expand Down

0 comments on commit e80078a

Please sign in to comment.