public static Optional parseBuildOutputTimestamp()

in src/main/java/org/apache/maven/archiver/MavenArchiver.java [768:801]


    public static Optional<Instant> parseBuildOutputTimestamp(String outputTimestamp) {
        // Fail-fast on nulls
        if (outputTimestamp == null) {
            return Optional.empty();
        }

        // Number representing seconds since the epoch
        if ((outputTimestamp != null && !outputTimestamp.isEmpty()) && StringUtils.isNumeric(outputTimestamp)) {
            return Optional.of(Instant.ofEpochSecond(Long.parseLong(outputTimestamp)));
        }

        // no timestamp configured (1 character configuration is useful to override a full value during pom
        // inheritance)
        if (outputTimestamp.length() < 2) {
            return Optional.empty();
        }

        try {
            // Parse the date in UTC such as '2011-12-03T10:15:30Z' or with an offset '2019-10-05T20:37:42+06:00'.
            final Instant date = OffsetDateTime.parse(outputTimestamp)
                    .withOffsetSameInstant(ZoneOffset.UTC)
                    .truncatedTo(ChronoUnit.SECONDS)
                    .toInstant();

            if (date.isBefore(DATE_MIN) || date.isAfter(DATE_MAX)) {
                throw new IllegalArgumentException(
                        "'" + date + "' is not within the valid range " + DATE_MIN + " to " + DATE_MAX);
            }
            return Optional.of(date);
        } catch (DateTimeParseException pe) {
            throw new IllegalArgumentException(
                    "Invalid project.build.outputTimestamp value '" + outputTimestamp + "'", pe);
        }
    }