
org.jresearch.commons.base.date.BaseDates Maven / Gradle / Ivy
The newest version!
package org.jresearch.commons.base.date;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import javax.annotation.Nonnull;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime;
public final class BaseDates {
private BaseDates() {
super();
}
public static LocalDate localJavaJodaDate(@Nonnull final java.time.LocalDate date) {
return new LocalDate(date.getYear(), date.getMonthValue(), date.getDayOfMonth());
}
public static java.time.LocalDate localJodaJavaDate(@Nonnull final LocalDate date) {
return java.time.LocalDate.of(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
}
public static LocalDateTime localJavaJodaDateTime(@Nonnull final java.time.LocalDate date, final int hour, final int minute) {
return new LocalDateTime(date.getYear(), date.getMonthValue(), date.getDayOfMonth(), hour, minute);
}
public static LocalTime localJavaJodaTime(@Nonnull final java.time.LocalTime time) {
return new LocalTime(time.getHour(), time.getMinute(), time.getSecond());
}
public static java.time.LocalTime localJodaJavaTime(@Nonnull final LocalTime time) {
return java.time.LocalTime.of(time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute());
}
public static DateTime javaJodaDateTime(@Nonnull final java.time.LocalDate date, @Nonnull final ZoneId zone) {
return localJavaJodaDate(date).toDateTimeAtStartOfDay(javaJodaTimeZone(zone));
}
public static ZonedDateTime jodaJavaDateTime(@Nonnull final DateTime dateTime) {
return ZonedDateTime.of(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute(), 0, ZoneId.of(dateTime.getZone().getID()));
}
public static DateTimeZone javaJodaTimeZone(@Nonnull final ZoneId zone) {
return DateTimeZone.forID(zone.getId());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy