Skip to content

Commit

Permalink
Enforce UTC time for parsing qualifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Mar 18, 2024
1 parent 51e39d6 commit 9ab4ac4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
@Mojo(name = "build-qualifier", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true)
public class BuildQualifierMojo extends AbstractVersionMojo {

static final TimeZone TIME_ZONE = TimeZone.getTimeZone("UTC");

static final String PARAMETER_FORMAT = "format";

static final String DEFAULT_DATE_FORMAT = "yyyyMMddHHmm";
Expand Down Expand Up @@ -144,7 +146,7 @@ public class BuildQualifierMojo extends AbstractVersionMojo {
// setter is needed to make sure we always use UTC
public void setFormat(String formatString) {
format = new SimpleDateFormat(formatString);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
format.setTimeZone(TIME_ZONE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public Date getTimestamp(MavenSession session, MavenProject project, MojoExecuti
.getString(BuildQualifierMojo.PARAMETER_FORMAT);
SimpleDateFormat format = formatString.map(SimpleDateFormat::new)
.orElseGet(() -> new SimpleDateFormat(BuildQualifierMojo.DEFAULT_DATE_FORMAT));
format.setTimeZone(BuildQualifierMojo.TIME_ZONE);
Date date = timestampFinder.findByDescriptor(descriptor, format);
if (date != null) {
return date;
Expand Down

0 comments on commit 9ab4ac4

Please sign in to comment.