Skip to content

Commit

Permalink
Change so it only warns on custom formats
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoop committed Sep 6, 2024
1 parent 5e497c0 commit 1e565aa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ static DateFormatter forPattern(String input, IndexVersion supportedVersion) {
input = input.substring(1);
}

DateUtils.checkTextualDateFormats(input);

// forPattern can be hot (e.g. executing a date processor on each document in a 1000 document bulk index request),
// so this is a for each loop instead of the equivalent stream pipeline
String[] patterns = splitCombinedPatterns(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2323,6 +2323,8 @@ static DateFormatter forPattern(String input) {
} else if (FormatNames.STRICT_YEAR_MONTH_DAY.matches(input)) {
return STRICT_YEAR_MONTH_DAY;
} else {
DateUtils.checkTextualDateFormats(input);

try {
return newDateFormatter(
input,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.elasticsearch.xpack.core.XPackSettings;

import java.time.Clock;
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -140,7 +142,7 @@ CharSequence buildExpirationMessage(long expirationMillis, boolean expired) {
License [{}] on [{}].
# If you have a new license, please update it. Otherwise, please reach out to
# your support contact.
#\s""", expiredMsg, LicenseUtils.DATE_FORMATTER.formatMillis(expirationMillis));
#\s""", expiredMsg, LicenseUtils.formatMillis(expirationMillis));
if (expired) {
general = general.toUpperCase(Locale.ROOT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

import org.elasticsearch.ElasticsearchSecurityException;
import org.elasticsearch.common.hash.MessageDigests;
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.license.License.LicenseType;
import org.elasticsearch.license.internal.XPackLicenseStatus;
import org.elasticsearch.protocol.xpack.license.LicenseStatus;
import org.elasticsearch.rest.RestStatus;

import java.nio.charset.StandardCharsets;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
Expand All @@ -25,7 +27,10 @@
public class LicenseUtils {

public static final String EXPIRED_FEATURE_METADATA = "es.license.expired.feature";
public static final DateFormatter DATE_FORMATTER = DateFormatter.forPattern("EEEE, MMMM dd, yyyy").withLocale(Locale.ENGLISH);

public static String formatMillis(long millis) {
return DateTimeFormatter.ofPattern("EEEE, MMMM dd, yyyy").withLocale(Locale.ENGLISH).format(Instant.ofEpochMilli(millis).atOffset(ZoneOffset.UTC));
}

/**
* Exception to be thrown when a feature action requires a valid license, but license
Expand Down Expand Up @@ -155,7 +160,7 @@ public static String getExpiryWarning(long licenseExpiryDate, long currentTime)
? "expires today"
: (diff > 0
? String.format(Locale.ROOT, "will expire in [%d] days", days)
: String.format(Locale.ROOT, "expired on [%s]", LicenseUtils.DATE_FORMATTER.formatMillis(licenseExpiryDate)));
: String.format(Locale.ROOT, "expired on [%s]", formatMillis(licenseExpiryDate)));
return "Your license "
+ expiryMessage
+ ". "
Expand Down

0 comments on commit 1e565aa

Please sign in to comment.