Example usage for java.time LocalDate getYear

List of usage examples for java.time LocalDate getYear

Introduction

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

Prototype

public int getYear() 

Source Link

Document

Gets the year field.

Usage

From source file:Pages.LandingPage.java

private String dateToString(LocalDate date) {
    String fixedDate;/*  w ww.  j a  v a  2  s  .  c o  m*/
    fixedDate = String.valueOf(date.getYear());
    fixedDate += "/" + String.valueOf(date.getDayOfMonth());
    fixedDate += "/" + String.valueOf(date.getMonthValue());
    return fixedDate;
}

From source file:com.objy.se.ClassAccessor.java

public Object getCorrectValue(String strValue, LogicalType logicalType) {
    Object retValue = null;/*from   w w  w .ja va  2s .  c o m*/
    switch (logicalType) {
    case INTEGER: {
        long attrValue = 0;
        try {
            if (!strValue.equals("")) {
                attrValue = Long.parseLong(strValue);
            }
        } catch (NumberFormatException nfEx) {
            //        System.out.println("... entry: " + entry.getValue() + " for raw: " + entry.getKey());
            nfEx.printStackTrace();
            throw nfEx;
        }
        retValue = Long.valueOf(attrValue);
    }
        break;
    case REAL: {
        double attrValue = 0;
        try {
            if (!strValue.equals("")) {
                attrValue = Double.parseDouble(strValue);
            }
        } catch (NumberFormatException nfEx) {
            //        System.out.println("... entry: " + entry.getValue() + " for raw: " + entry.getKey());
            nfEx.printStackTrace();
            throw nfEx;
        }
        retValue = Double.valueOf(attrValue);
    }
        break;
    case STRING:
        retValue = strValue;
        break;
    case BOOLEAN: {
        if (strValue.equalsIgnoreCase("TRUE") || strValue.equals("1")) {
            retValue = Boolean.valueOf(true);
        } else if (strValue.equalsIgnoreCase("FALSE") || strValue.equals("0")) {
            retValue = Boolean.valueOf(false);
        } else {
            LOG.error("Expected Boolean value but got: {}", strValue);
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
        break;

    case CHARACTER: {
        if (strValue.length() == 1) {
            retValue = Character.valueOf(strValue.charAt(0));
        } else { /* not a char value... report that */
            LOG.error("Expected Character value but got: {}", strValue);
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
        break;
    case DATE: {
        try {
            LocalDate ldate = LocalDate.parse(strValue, dateFormatter);
            //            System.out.println("... ... year: " + ldate.getYear() + " - month:" + ldate.getMonthValue());
            retValue = new com.objy.db.Date(ldate.getYear(), ldate.getMonthValue(), ldate.getDayOfMonth());
        } catch (DateTimeParseException ex) {
            LOG.error(ex.toString());
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
        break;
    case DATE_TIME: {
        try {
            //            System.out.println(".... formatter: " + mapper.getDateTimeFormat());
            LocalDateTime ldt = LocalDateTime.parse(strValue, dateTimeFormatter);
            //            System.out.println("... ... year: " + ldt.getYear() + 
            //                    " - month:" + ldt.getMonthValue() + " - day: " +
            //                    ldt.getDayOfMonth() + " - hour: " + ldt.getHour() +
            //                    " - min: " + ldt.getMinute() + " - sec: " + 
            //                    ldt.getSecond() + " - nsec: " + ldt.getNano() );
            //retValue = new com.objy.db.DateTime(date.getTime(), TimeKind.LOCAL);
            retValue = new com.objy.db.DateTime(ldt.getYear(), ldt.getMonthValue(), ldt.getDayOfMonth(),
                    ldt.getHour(), ldt.getMinute(), ldt.getSecond(), ldt.getNano());
        } catch (DateTimeParseException ex) {
            LOG.error(ex.toString());
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
        break;
    case TIME: {
        try {
            //            System.out.println(".... formatter: " + mapper.getTimeFormat());
            LocalDateTime ltime = LocalDateTime.parse(strValue, dateFormatter);
            //            System.out.println("... ... hour: " + ltime.getHour() +
            //                    " - min: " + ltime.getMinute() + " - sec: " + 
            //                    ltime.getSecond() + " - nsec: " + ltime.getNano() );
            //retValue = new com.objy.db.DateTime(date.getTime(), TimeKind.LOCAL);
            retValue = new com.objy.db.Time(ltime.getHour(), ltime.getMinute(), ltime.getSecond(),
                    ltime.getNano());
        } catch (DateTimeParseException ex) {
            LOG.error(ex.toString());
            throw new IllegalStateException("Possible invalid configuration... check mapper vs. schema"
                    + "... or check records for invalid values");
        }
    }
    default: {
        throw new UnsupportedOperationException("LogicalType: " + logicalType + " is not supported!!!");
    }
    }
    return retValue;
}

From source file:ui.Analyze.java

private void fillPermintaanTgl(LocalDate ld1, LocalDate ld2) {
    thnAkhir.setValue(ld1.getYear());
    blnAkhir.setValue(ld1.getMonthValue());
    tglAkhir.setValue(ld1.getDayOfMonth());
    thnAwal.setValue(ld2.getYear());//from   ww  w. j a  va  2  s  .c om
    blnAwal.setValue(ld2.getMonthValue());
    tglAwal.setValue(ld2.getDayOfMonth());
}

From source file:ui.Analyze.java

private void fillURTgl(LocalDate ld1, LocalDate ld2) {
    thnAkhirUR.setValue(ld1.getYear());
    blnAkhirUR.setValue(ld1.getMonthValue());
    tglAkhirUR.setValue(ld1.getDayOfMonth());
    thnAwalUR.setValue(ld2.getYear());/*ww w.  j a va 2s .c  o  m*/
    blnAwalUR.setValue(ld2.getMonthValue());
    tglAwalUR.setValue(ld2.getDayOfMonth());
}

From source file:ui.Analyze.java

private void fillLabaTgl(LocalDate ld1, LocalDate ld2) {
    thnAkhirLaba.setValue(ld1.getYear());
    blnAkhirLaba.setValue(ld1.getMonthValue());
    tglAkhirLaba.setValue(ld1.getDayOfMonth());
    thnAwalLaba.setValue(ld2.getYear());
    blnAwalLaba.setValue(ld2.getMonthValue());
    tglAwalLaba.setValue(ld2.getDayOfMonth());
}

From source file:org.efaps.esjp.common.uiform.Field_Base.java

/**
 * @param _parameter    Parameter as passed from the eFaps API
 * @return Return containing Html Snipplet
 * @throws EFapsException on error//from   w  ww.  ja  va  2 s .c  o m
 */
public Return getOptionList4DateTime(final Parameter _parameter) throws EFapsException {
    final List<DropDownPosition> positions = new ArrayList<>();
    final String dateFieldType = getProperty(_parameter, "DateFieldType", "YEAR");
    switch (dateFieldType) {
    case "MONTH":
        for (final Month month : Month.values()) {
            final DropDownPosition pos = getDropDownPosition(_parameter, month.getValue(),
                    month.getDisplayName(TextStyle.FULL, Context.getThreadContext().getLocale()));
            pos.setSelected(month.getValue() == new DateTime().getMonthOfYear());
            positions.add(pos);
        }
        break;
    case "YEAR":
    default:
        final String fromStr = getProperty(_parameter, "From", "-10");
        final String toStr = getProperty(_parameter, "To", "+10");
        LocalDate start;
        if (StringUtils.isNumeric(fromStr)) {
            start = LocalDate.of(Integer.parseInt(fromStr), 1, 1);
        } else {
            start = LocalDate.now().plusYears(Integer.parseInt(fromStr));
        }
        final LocalDate end;
        if (StringUtils.isNumeric(toStr)) {
            end = LocalDate.of(Integer.parseInt(toStr), 1, 1);
        } else {
            end = LocalDate.now().plusYears(Integer.parseInt(toStr));
        }
        while (start.isBefore(end)) {
            final DropDownPosition pos = getDropDownPosition(_parameter, start.getYear(), start.getYear());
            pos.setSelected(start.getYear() == new DateTime().getYear());
            positions.add(pos);
            start = start.plusYears(1);
        }
        break;
    }
    final Return ret = new Return();
    ret.put(ReturnValues.VALUES, positions);
    return ret;
}