Skip to content

Commit 85dc995

Browse files
committed
Address code review comments from @Zabuzard
Signed-off-by: Chris Sdogkos <work@chris-sdogkos.com>
1 parent d688bb2 commit 85dc995

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

application/src/main/java/org/togetherjava/tjbot/features/rss/RSSHandlerRoutine.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private static Instant getDateTimeFromItem(Item item, String dateTimeFormat)
303303
throws DateTimeParseException {
304304
Optional<String> pubDate = item.getPubDate();
305305

306-
return pubDate.map(s -> getInstantTimeFromFormat(s, dateTimeFormat)).orElse(Instant.MIN);
306+
return pubDate.map(s -> parseDateTime(s, dateTimeFormat)).orElse(Instant.MIN);
307307

308308
}
309309

@@ -325,7 +325,7 @@ private static boolean isValidDateFormat(Item rssItem, RSSFeed feedConfig) {
325325
// If this throws a DateTimeParseException then it's certain
326326
// that the format pattern defined in the config and the
327327
// feed's actual format differ.
328-
getInstantTimeFromFormat(firstRssFeedPubDate.get(), feedConfig.dateFormatterPattern());
328+
parseDateTime(firstRssFeedPubDate.get(), feedConfig.dateFormatterPattern());
329329
} catch (DateTimeParseException _) {
330330
return false;
331331
}
@@ -374,8 +374,8 @@ private MessageCreateData constructMessage(Item item, RSSFeed feedConfig) {
374374

375375
// Set the item's timestamp to the embed if found
376376
item.getPubDate()
377-
.ifPresent(date -> embedBuilder
378-
.setTimestamp(getInstantTimeFromFormat(date, feedConfig.dateFormatterPattern())));
377+
.ifPresent(dateTime -> embedBuilder
378+
.setTimestamp(parseDateTime(dateTime, feedConfig.dateFormatterPattern())));
379379

380380
embedBuilder.setTitle(title, titleLink);
381381
embedBuilder.setAuthor(item.getChannel().getLink());
@@ -434,17 +434,17 @@ private List<Item> fetchRSSItemsFromURL(String rssUrl) {
434434
/**
435435
* Helper function for parsing a given date value to a {@link Instant} with a given format.
436436
*
437-
* @param date the date value to parse, can be null
437+
* @param dateTime the date and time value to parse, can be null
438438
* @return the parsed {@link Instant} object
439439
* @throws DateTimeParseException if the date cannot be parsed
440440
*/
441-
private static Instant getInstantTimeFromFormat(@Nullable String date, String datePattern)
441+
private static Instant parseDateTime(@Nullable String dateTime, String datePattern)
442442
throws DateTimeParseException {
443-
if (date == null) {
443+
if (dateTime == null) {
444444
return Instant.MIN;
445445
}
446446

447-
return Instant.from(DateTimeFormatter.ofPattern(datePattern).parse(date));
447+
return Instant.from(DateTimeFormatter.ofPattern(datePattern).parse(dateTime));
448448
}
449449

450450
private long calculateWaitHours(int failureCount) {

0 commit comments

Comments
 (0)