diff --git a/src/main/java/com/epam/ta/reportportal/commons/EntityUtils.java b/src/main/java/com/epam/ta/reportportal/commons/EntityUtils.java index 68479be51..e0b5fdd82 100644 --- a/src/main/java/com/epam/ta/reportportal/commons/EntityUtils.java +++ b/src/main/java/com/epam/ta/reportportal/commons/EntityUtils.java @@ -49,6 +49,23 @@ public class EntityUtils { .toLocalDateTime()) .orElse(null); + + /** + * This operator performs time zone conversion for date and time. + * Specifically, it converts input dates from UTC timezone to the system default timezone. + * Usage: + * LocalDateTime originalDate = ...; + * LocalDateTime localDate = FROM_UTC_TO_LOCAL_DATE_TIME.apply(originalDate); + * + */ + public static final UnaryOperator FROM_UTC_TO_LOCAL_DATE_TIME = + localDateTime -> ofNullable(localDateTime) + .map(date -> date.atZone(ZoneOffset.UTC) + .toInstant() + .atZone(ZoneId.systemDefault()) + .toLocalDateTime()) + .orElse(null); + public static final Function TO_DATE = localDateTime -> ofNullable( localDateTime).map(l -> Date.from(l.atZone( ZoneOffset.UTC).toInstant())).orElse(null);