@@ -748,6 +748,50 @@ public void shouldGenerateClosestTagInformationWhenCommitHasTwoTags(boolean useN
748748 assertThat (targetProject .getProperties ().getProperty ("git.closest.tag.commit.count" )).isEqualTo ("0" );
749749 }
750750
751+ @ Test
752+ @ Parameters (method = "useNativeGit" )
753+ public void shouldUseDateFormatTimeZone (boolean useNativeGit ) throws Exception {
754+ // given
755+ mavenSandbox .withParentProject ("my-pom-project" , "pom" )
756+ .withChildProject ("my-jar-module" , "jar" )
757+ .withGitRepoInChild (AvailableGitTestRepo .ON_A_TAG_DIRTY )
758+ .create (CleanUp .CLEANUP_FIRST );
759+ MavenProject targetProject = mavenSandbox .getChildProject ();
760+
761+ setProjectToExecuteMojoIn (targetProject );
762+
763+ // RFC 822 time zone: Sign TwoDigitHours Minutes
764+ String dateFormat = "Z" ; // we want only the timezone (formated in RFC 822) out of the dateformat (easier for asserts)
765+ String expectedTimeZoneOffset = "+0200" ;
766+ String executionTimeZoneOffset = "-0800" ;
767+ TimeZone expectedTimeZone = TimeZone .getTimeZone ("GMT" + expectedTimeZoneOffset );
768+ TimeZone executionTimeZone = TimeZone .getTimeZone ("GMT" + executionTimeZoneOffset );
769+
770+ GitDescribeConfig gitDescribeConfig = createGitDescribeConfig (true , 7 );
771+ alterMojoSettings ("gitDescribe" , gitDescribeConfig );
772+ alterMojoSettings ("useNativeGit" , useNativeGit );
773+ alterMojoSettings ("dateFormat" , dateFormat );
774+ alterMojoSettings ("dateFormatTimeZone" , expectedTimeZone .getID ());
775+
776+ // override the default timezone for execution and testing
777+ TimeZone currentDefaultTimeZone = TimeZone .getDefault ();
778+ TimeZone .setDefault (executionTimeZone );
779+
780+ // when
781+ mojo .execute ();
782+
783+ // then
784+ Properties properties = targetProject .getProperties ();
785+ assertThat (properties .stringPropertyNames ()).contains ("git.commit.time" );
786+ assertThat (properties .getProperty ("git.commit.time" )).isEqualTo (expectedTimeZoneOffset );
787+
788+ assertThat (properties .stringPropertyNames ()).contains ("git.build.time" );
789+ assertThat (properties .getProperty ("git.build.time" )).isEqualTo (expectedTimeZoneOffset );
790+
791+ // set the timezone back
792+ TimeZone .setDefault (currentDefaultTimeZone );
793+ }
794+
751795 private GitDescribeConfig createGitDescribeConfig (boolean forceLongFormat , int abbrev ) {
752796 GitDescribeConfig gitDescribeConfig = new GitDescribeConfig ();
753797 gitDescribeConfig .setTags (true );
0 commit comments