Skip to content

Commit

Permalink
remove deprecated timeutil methods (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb authored Feb 2, 2024
1 parent 995b71e commit e54f3a7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 110 deletions.
11 changes: 9 additions & 2 deletions src/main/java/emissary/output/DropOffUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import emissary.config.Configurator;
import emissary.core.Family;
import emissary.core.IBaseDataObject;
import emissary.util.FlexibleDateTimeParser;
import emissary.util.ShortNameComparator;
import emissary.util.TimeUtil;
import emissary.util.shell.Executrix;
Expand All @@ -22,6 +23,7 @@
import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -42,6 +44,7 @@
import static emissary.core.constants.Parameters.FILEXT;
import static emissary.core.constants.Parameters.FILE_ABSOLUTEPATH;
import static emissary.core.constants.Parameters.ORIGINAL_FILENAME;
import static emissary.util.TimeUtil.DATE_ISO_8601;

public class DropOffUtil {
protected static final Logger logger = LoggerFactory.getLogger(DropOffUtil.class);
Expand Down Expand Up @@ -886,8 +889,12 @@ public Date extractEventDateFrom(final IBaseDataObject d, final boolean lastReso
final String value = d.getStringParameter(paramName);
if (value != null) {
try {
date = TimeUtil.getDateFromISO8601(value);
return date;
ZonedDateTime zdt = FlexibleDateTimeParser.parse(value, DATE_ISO_8601);
if (zdt == null) {
logger.debug("FlexibleDateTimeParser returned null trying to parse EventDate");
} else {
return Date.from(zdt.toInstant());
}
} catch (DateTimeParseException ex) {
logger.debug("Cannot parse EventDate", ex);
}
Expand Down
61 changes: 5 additions & 56 deletions src/main/java/emissary/util/TimeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor;
import java.time.zone.ZoneRulesException;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;

public class TimeUtil {

private static final ZoneId GMT = ZoneId.of("GMT");
private static final DateTimeFormatter DATE_WITH_SLASHES = DateTimeFormatter.ofPattern("yyyy-MM-dd/HH/mm").withZone(GMT);
private static final DateTimeFormatter DATE_ISO_8601 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(GMT);
private static final DateTimeFormatter DATE_FULL_ISO_8601 = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX").withZone(GMT);
private static final DateTimeFormatter DATE_ORDINAL = DateTimeFormatter.ofPattern("yyyyDDD").withZone(GMT);
private static final DateTimeFormatter DATE_ISO_8601_SSS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
public static final DateTimeFormatter DATE_WITH_SLASHES = DateTimeFormatter.ofPattern("yyyy-MM-dd/HH/mm").withZone(GMT);
public static final DateTimeFormatter DATE_ISO_8601 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(GMT);
public static final DateTimeFormatter DATE_FULL_ISO_8601 = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssX").withZone(GMT);
public static final DateTimeFormatter DATE_ORDINAL = DateTimeFormatter.ofPattern("yyyyDDD").withZone(GMT);
public static final DateTimeFormatter DATE_ISO_8601_SSS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
private static final String ISO_8601_TIME_DATE_STRING = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private static final String HEX_REGEX = "^0x([0-9A-Fa-f]{8})([0-9A-Fa-f]{8})";
private static final Pattern HEX_DATE_PATTERN = Pattern.compile(HEX_REGEX);
Expand Down Expand Up @@ -92,16 +91,6 @@ public static String getCurrentDate() {
return getDateAsPath(ZonedDateTime.now(GMT));
}

/**
* Get specified date/time as a slash separated path component
*
* @deprecated replaced by {@link #getDateAsPath(TemporalAccessor)}
*/
@Deprecated
public static String getDateAsPath(final Date date) {
return getDateAsPath(date.toInstant());
}

/**
* Get specified date/time as a slash separated path component (yyyy-MM-dd/HH/mm)
*
Expand All @@ -127,16 +116,6 @@ public static String getCurrentDateOrdinal() {
return getDateOrdinal(ZonedDateTime.now(GMT));
}

/**
* Get current date as yyyyjjj
*
* @deprecated replaced by {@link #getDateOrdinal(TemporalAccessor)}
*/
@Deprecated
public static String getDateOrdinal(@Nullable Date date) {
return date == null ? null : getDateOrdinal(date.toInstant());
}

/**
* Get current date as yyyyjjj
*
Expand Down Expand Up @@ -168,16 +147,6 @@ public static String getDateAsISO8601(final long time) {
return getDateAsISO8601(ZonedDateTime.ofInstant(Instant.ofEpochMilli(time), GMT));
}

/**
* Get specified date object as ISO-8601 string
*
* @deprecated replaced by {@link #getDateAsISO8601(TemporalAccessor)}
*/
@Deprecated
public static String getDateAsISO8601(@Nullable final Date date) {
return date == null ? null : getDateAsISO8601(date.toInstant());
}

/**
* Get specified date object as ISO-8601 string (yyyy-MM-dd HH:mm:ss)
*
Expand All @@ -199,16 +168,6 @@ public static String getCurrentDateFullISO8601() {
return getDateAsFullISO8601(ZonedDateTime.now(GMT));
}

/**
* Get specified date object as a full ISO-8601 string yyyy-MM-dd'T'HH:mm:ss'Z'
*
* @deprecated replaced by {@link #getDateAsFullISO8601(TemporalAccessor)}
*/
@Deprecated
public static String getDateAsFullISO8601(@Nullable final Date date) {
return date == null ? null : getDateAsFullISO8601(date.toInstant());
}

/**
* Get specified date object as a full ISO-8601 string (yyyy-MM-dd'T'HH:mm:ss'Z')
*
Expand All @@ -220,16 +179,6 @@ public static String getDateAsFullISO8601(@Nullable final TemporalAccessor date)
return date == null ? null : DATE_FULL_ISO_8601.format(date);
}

/**
* Get Date object from ISO-8601 formatted string
*
* @deprecated replaced by {@link FlexibleDateTimeParser#parse(String)}
*/
@Deprecated
public static Date getDateFromISO8601(@Nullable final String dateString) throws DateTimeParseException {
return dateString == null ? null : Date.from(getZonedDateFromISO8601(dateString).toInstant());
}

/**
* Get Date object from ISO-8601 formatted string ("yyyy-MM-dd HH:mm:ss")
*
Expand Down
52 changes: 0 additions & 52 deletions src/test/java/emissary/util/TimeUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
import java.time.zone.ZoneRulesException;
import java.util.Date;

Expand Down Expand Up @@ -55,47 +54,11 @@ void testGetDateExceptionBadZone() {
assertThrows(ZoneRulesException.class, () -> TimeUtil.getDate("yyyy", "BAD"));
}

@Deprecated
@Test
void testGetDateAsPath() {
assertEquals("2016-12-25/15/30", TimeUtil.getDateAsPath(testUtilDate), "GetDateAsPath");
}

@Deprecated
@Test
void testGetDateOrdinal() {
assertEquals("2016360", TimeUtil.getDateOrdinal(testUtilDate), "GetDateOrdinal");
}

@Deprecated
@Test
void testGetDateAsISO8601() {
assertEquals("2016-12-25 15:30:25", TimeUtil.getDateAsISO8601(testUtilDate), "GetDateAsISO8601");
}

@Test
void testGetDateAsISO8601Long() {
assertEquals("2016-12-25 15:30:25", TimeUtil.getDateAsISO8601(testUtilDate.getTime()), "GetDateAsISO8601Long");
}

@Deprecated
@Test
void testGetDateAsFullISO8601() {
assertEquals("2016-12-25T15:30:25Z", TimeUtil.getDateAsFullISO8601(testUtilDate), "GetDateAsFullISO8601");
}

@Deprecated
@Test
void testGetDateFromISO8601() {
assertEquals(testUtilDate.getTime(), TimeUtil.getDateFromISO8601("2016-12-25 15:30:25").getTime(), "GetDateFromISO8601");
}

@Deprecated
@Test
void testGetDateFromISO8601Exception() {
assertThrows(DateTimeParseException.class, () -> TimeUtil.getDateFromISO8601("Bad Date"));
}

@Deprecated
@Test
void testGetZonedDateFromISO8601() {
Expand All @@ -110,26 +73,11 @@ void testGetZonedDateFromISO8601() {
assertEquals("GMT", zdt.getZone().getId());
}

@Deprecated
@Test
void testDatePath() {
assertTrue(TimeUtil.getDateAsPath(new Date()).contains("/"), "Date with slashes must have slashes");
}

@Test
void testOrdinal() {
assertEquals(7, TimeUtil.getCurrentDateOrdinal().length(), "Date with ordinal must be 7 long");
}

@Deprecated
@Test
void testISO8601RoundTrip() {
final String s = TimeUtil.getCurrentDateISO8601();
final Date d = TimeUtil.getDateFromISO8601(s);
final String s2 = TimeUtil.getDateAsISO8601(d.getTime());
assertEquals(s, s2, "ISO8601 utils should make round trip");
}

@Test
void testCurrentTimeAsPath() {
final String path = TimeUtil.getCurrentDate();
Expand Down

0 comments on commit e54f3a7

Please sign in to comment.