Example usage for java.time LocalDate MIN

List of usage examples for java.time LocalDate MIN

Introduction

In this page you can find the example usage for java.time LocalDate MIN.

Prototype

LocalDate MIN

To view the source code for java.time LocalDate MIN.

Click Source Link

Document

The minimum supported LocalDate , '-999999999-01-01'.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.MIN;

    System.out.println(a);
}

From source file:Main.java

public static void main(String[] args) {
    System.out.println(getElapsedYears(LocalDate.MAX, LocalDate.MIN));
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate february20th = LocalDate.of(2014, Month.FEBRUARY, 20);
    System.out.println(february20th);
    System.out.println(LocalDate.from(february20th.plus(15, ChronoUnit.YEARS))); // 2029-02-20
    System.out.println(LocalDate.MAX);
    System.out.println(LocalDate.MIN);

    System.out.println(LocalTime.MIDNIGHT); // 00:00
    System.out.println(LocalTime.NOON); // 12:00
    System.out.println(LocalTime.of(23, 12, 30, 500)); // 23:12:30.000000500
    System.out.println(LocalTime.now()); // 00:40:34.110
    System.out.println(LocalTime.ofSecondOfDay(11 * 60 * 60)); // 11:00
    System.out.println(LocalTime.from(LocalTime.MIDNIGHT.plusHours(4))); // 04:00
    System.out.println(LocalTime.MIN);
    System.out.println(LocalTime.MAX);

    System.out.println(LocalDateTime.of(2014, 2, 15, 12, 30, 50, 200)); // 2014-02-15T12:30:50.000000200
    System.out.println(LocalDateTime.now()); // 2014-02-28T17:28:21.002
    System.out.println(LocalDateTime.from(LocalDateTime.of(2014, 2, 15, 12, 30, 40, 500).plusHours(19))); // 2014-02-16T07:30:40.000000500
    System.out.println(LocalDateTime.MAX);
}

From source file:com.streamsets.pipeline.lib.jdbc.JdbcUtil.java

public Field resultToField(ResultSetMetaData md, ResultSet rs, int columnIndex, int maxClobSize,
        int maxBlobSize, DataType userSpecifiedType, UnknownTypeAction unknownTypeAction,
        boolean timestampToString) throws SQLException, IOException, StageException {
    Field field;/*from   w w w . j av  a2  s. c  o m*/
    if (userSpecifiedType != DataType.USE_COLUMN_TYPE) {
        // If user specifies the data type, overwrite the column type returned by database.
        field = Field.create(Field.Type.valueOf(userSpecifiedType.getLabel()), rs.getObject(columnIndex));
    } else {
        // All types as of JDBC 2.0 are here:
        // https://docs.oracle.com/javase/8/docs/api/constant-values.html#java.sql.Types.ARRAY
        // Good source of recommended mappings is here:
        // http://www.cs.mun.ca/java-api-1.5/guide/jdbc/getstart/mapping.html
        switch (md.getColumnType(columnIndex)) {
        case Types.BIGINT:
            field = Field.create(Field.Type.LONG, rs.getObject(columnIndex));
            break;
        case Types.BINARY:
        case Types.LONGVARBINARY:
        case Types.VARBINARY:
            field = Field.create(Field.Type.BYTE_ARRAY, rs.getBytes(columnIndex));
            break;
        case Types.BIT:
        case Types.BOOLEAN:
            field = Field.create(Field.Type.BOOLEAN, rs.getObject(columnIndex));
            break;
        case Types.CHAR:
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
        case Types.VARCHAR:
            field = Field.create(Field.Type.STRING, rs.getObject(columnIndex));
            break;
        case Types.CLOB:
        case Types.NCLOB:
            field = Field.create(Field.Type.STRING, getClobString(rs.getClob(columnIndex), maxClobSize));
            break;
        case Types.BLOB:
            field = Field.create(Field.Type.BYTE_ARRAY, getBlobBytes(rs.getBlob(columnIndex), maxBlobSize));
            break;
        case Types.DATE:
            field = Field.create(Field.Type.DATE, rs.getDate(columnIndex));
            break;
        case Types.DECIMAL:
        case Types.NUMERIC:
            field = Field.create(Field.Type.DECIMAL, rs.getBigDecimal(columnIndex));
            field.setAttribute(HeaderAttributeConstants.ATTR_SCALE,
                    String.valueOf(rs.getMetaData().getScale(columnIndex)));
            field.setAttribute(HeaderAttributeConstants.ATTR_PRECISION,
                    String.valueOf(rs.getMetaData().getPrecision(columnIndex)));
            break;
        case Types.DOUBLE:
            field = Field.create(Field.Type.DOUBLE, rs.getObject(columnIndex));
            break;
        case Types.FLOAT:
        case Types.REAL:
            field = Field.create(Field.Type.FLOAT, rs.getObject(columnIndex));
            break;
        case Types.INTEGER:
            field = Field.create(Field.Type.INTEGER, rs.getObject(columnIndex));
            break;
        case Types.ROWID:
            field = Field.create(Field.Type.STRING, rs.getRowId(columnIndex).toString());
            break;
        case Types.SMALLINT:
        case Types.TINYINT:
            field = Field.create(Field.Type.SHORT, rs.getObject(columnIndex));
            break;
        case Types.TIME:
            field = Field.create(Field.Type.TIME, rs.getObject(columnIndex));
            break;
        case Types.TIMESTAMP:
            final Timestamp timestamp = rs.getTimestamp(columnIndex);
            if (timestampToString) {
                field = Field.create(Field.Type.STRING, timestamp == null ? null : timestamp.toString());
            } else {
                field = Field.create(Field.Type.DATETIME, timestamp);
                if (timestamp != null) {
                    final long actualNanos = timestamp.getNanos() % NANOS_TO_MILLIS_ADJUSTMENT;
                    if (actualNanos > 0) {
                        field.setAttribute(FIELD_ATTRIBUTE_NANOSECONDS, String.valueOf(actualNanos));
                    }
                }
            }
            break;
        // Ugly hack until we can support LocalTime, LocalDate, LocalDateTime, etc.
        case Types.TIME_WITH_TIMEZONE:
            OffsetTime offsetTime = rs.getObject(columnIndex, OffsetTime.class);
            field = Field.create(Field.Type.TIME, Date.from(offsetTime.atDate(LocalDate.MIN).toInstant()));
            break;
        case Types.TIMESTAMP_WITH_TIMEZONE:
            OffsetDateTime offsetDateTime = rs.getObject(columnIndex, OffsetDateTime.class);
            field = Field.create(Field.Type.ZONED_DATETIME, offsetDateTime.toZonedDateTime());
            break;
        //case Types.REF_CURSOR: // JDK8 only
        case Types.SQLXML:
        case Types.STRUCT:
        case Types.ARRAY:
        case Types.DATALINK:
        case Types.DISTINCT:
        case Types.JAVA_OBJECT:
        case Types.NULL:
        case Types.OTHER:
        case Types.REF:
        default:
            if (unknownTypeAction == null) {
                return null;
            }
            switch (unknownTypeAction) {
            case STOP_PIPELINE:
                throw new StageException(JdbcErrors.JDBC_37, md.getColumnType(columnIndex),
                        md.getColumnLabel(columnIndex));
            case CONVERT_TO_STRING:
                Object value = rs.getObject(columnIndex);
                if (value != null) {
                    field = Field.create(Field.Type.STRING, rs.getObject(columnIndex).toString());
                } else {
                    field = Field.create(Field.Type.STRING, null);
                }
                break;
            default:
                throw new IllegalStateException("Unknown action: " + unknownTypeAction);
            }
        }
    }

    return field;
}

From source file:org.gradoop.flink.datagen.transactions.foodbroker.config.FoodBrokerConfig.java

/**
 * Loads the start date.//from   ww  w.jav a 2  s .  c o  m
 *
 * @return long representation of the start date
 */
public LocalDate getStartDate() {
    String startDate;
    DateTimeFormatter formatter;
    LocalDate date = LocalDate.MIN;

    try {
        startDate = root.getJSONObject("Process").getString("startDate");
        formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        date = LocalDate.parse(startDate, formatter);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return date;
}

From source file:org.silverpeas.core.date.Period.java

/**
 * Creates a new period of time between the two non null specified dates. The period is spreading
 * over all the day(s) between the specified inclusive start day and the exclusive end day; the
 * period is expressed in days. For example, a period between 2016-12-15 and 2016-12-17 means the
 * period is spreading over two days (2016-12-15 and 2016-12-16).
 * @param startDay the start day of the period. It defines the inclusive date at which the
 * period starts./*from  www .  java2 s .  co m*/
 * @param endDay the end day of the period. It defines the exclusive date at which the period
 * ends. The end date must be the same or after the start date. An end date equal to the start
 * date means the period is spanning all the day of the start date; it is equivalent to an end
 * date being one day after the start date.
 * @return the period of days between the two specified dates.
 */
public static Period between(LocalDate startDay, LocalDate endDay) {
    checkPeriod(startDay, endDay);
    Period period = new Period();
    period.startDateTime = startDay == LocalDate.MIN ? OffsetDateTime.MIN
            : startDay.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime();
    period.endDateTime = endDay == LocalDate.MAX ? OffsetDateTime.MAX
            : endDay.atStartOfDay(ZoneOffset.UTC).toOffsetDateTime();
    if (startDay.isEqual(endDay)) {
        period.endDateTime = period.endDateTime.plusDays(1);
    }
    period.inDays = true;
    return period;
}

From source file:org.silverpeas.core.date.Period.java

/**
 * Creates a new period of time between the two specified date or datetime.
 * If date parameters are instances of {@link LocalDate}, take a look at method
 * {@link #betweenNullable(Temporal, Temporal)} (LocalDate, LocalDate)}.
 * If date parameters are instances of {@link OffsetDateTime}, take a look at method
 * {@link #betweenNullable(Temporal, Temporal)} (OffsetDateTime, OffsetDateTime)}.
 * If both date parameters are null, then a period between {@link LocalDate#MIN} and
 * {@link LocalDate#MAX} is returned unless those parameters are explicitly typed; for example:
 * {@code Period.betweenNullable((OffsetDateTime) null, null)}
 * @param start the start of the period. It defines the inclusive date or datetime at which the
 * period starts. If it is null then the minimum temporal (date or datetime) is taken.
 * @param end the end day of the period. It defines the exclusive date or the exclusive datetime
 * at which the period ends. The end date must be the same or after the start date. An end date
 * equal to the start date means the period is spanning all the day; it is equivalent to an end
 * date being one day after the start date. If It is null then the maximum temporal (date or
 * datetime) is taken.//  w ww  .ja v a2 s .  c  o m
 * @return the period of days between the two specified dates.
 * @throws IllegalArgumentException if date parameters are not both {@link LocalDate} or
 * {@link OffsetDateTime} instances.
 * @see LocalDate#MIN for the minimum supported date.
 * @see OffsetDateTime#MIN for the maximum supported date.
 * @see LocalDate#MAX for the maximum supported datetime.
 * @see OffsetDateTime#MAX for the maximum supported datetime.
 */
public static Period betweenNullable(java.time.temporal.Temporal start, java.time.temporal.Temporal end) {
    if (start == null && end == null) {
        return betweenNullable(LocalDate.MIN, LocalDate.MAX);
    }
    if (start != null && end != null) {
        // we ensure start and end are of the same type
        return between(start, end);
    }
    if (start instanceof LocalDate || end instanceof LocalDate) {
        return betweenNullable(minOrDate(start), maxOrDate(end));
    } else if (start instanceof OffsetDateTime || end instanceof OffsetDateTime) {
        return betweenNullable(minOrDateTime(start), maxOrDateTime(end));
    }
    throw new IllegalArgumentException(
            "Temporal parameters must be either of type LocalDate or OffsetDateTime");
}

From source file:org.silverpeas.core.date.Period.java

private static LocalDate minOrDate(final Temporal date) {
    return date == null ? LocalDate.MIN : asLocalDate(date);
}