Example usage for java.time.temporal ChronoUnit YEARS

List of usage examples for java.time.temporal ChronoUnit YEARS

Introduction

In this page you can find the example usage for java.time.temporal ChronoUnit YEARS.

Prototype

ChronoUnit YEARS

To view the source code for java.time.temporal ChronoUnit YEARS.

Click Source Link

Document

Unit that represents the concept of a year.

Usage

From source file:msi.gama.util.GamaDate.java

public double getDuration(final IScope scope, final TimeUnitConstantExpression exp, final Double number) {
    final String name = exp.getName();
    // final boolean isTimeDependent = !exp.isConst();
    final boolean month = name.startsWith("m");
    final GamaDate next = this.plus(number, month ? ChronoUnit.MONTHS : ChronoUnit.YEARS);
    final double result = this.until(next, ChronoUnit.MILLIS) / 1000d;
    // DEBUG.LOG("Computation of " + number + " " + exp.getName() + " = " + result + "s or "
    // + this.until(next, ChronoUnit.DAYS) + " days");

    return result;
}

From source file:org.silverpeas.core.webapi.calendar.CalendarWebManager.java

/**
 * Gets the first occurrence of an event from the identifier of an event.
 * @param eventId an event identifier./*from  ww  w.j  a v a 2 s .com*/
 * @return the first {@link CalendarEventOccurrence} instance of an event.
 */
public CalendarEventOccurrence getFirstCalendarEventOccurrenceFromEventId(final String eventId) {
    CalendarEvent event = CalendarEvent.getById(eventId);
    final Temporal startTemporal = event.getStartDate();
    final Temporal endTemporal;
    if (!event.isRecurrent()) {
        endTemporal = event.getEndDate();
    } else {
        endTemporal = event.getEndDate().plus(END_YEAR_OFFSET, ChronoUnit.YEARS);
    }
    return generator.generateOccurrencesOf(singletonList(event), Period.between(startTemporal, endTemporal))
            .get(0);
}

From source file:org.talend.dataprep.transformation.actions.date.ComputeTimeSince.java

@Override
public List<Parameter> getParameters() {
    List<Parameter> parameters = super.getParameters();

    parameters.add(SelectParameter.Builder.builder() //
            .name(TIME_UNIT_PARAMETER) //
            .item(ChronoUnit.YEARS.name(), "years") //
            .item(ChronoUnit.MONTHS.name(), "months") //
            .item(ChronoUnit.DAYS.name(), "days") //
            .item(ChronoUnit.HOURS.name(), "hours") //
            .defaultValue(ChronoUnit.HOURS.name()) //
            .build());//  ww  w  .j  a  va2s.  c o m

    parameters.add(SelectParameter.Builder.builder() //
            .name(SINCE_WHEN_PARAMETER) //
            .canBeBlank(false) //
            .item(NOW_SERVER_SIDE_MODE, NOW_SERVER_SIDE_MODE) //
            .item(SPECIFIC_DATE_MODE, SPECIFIC_DATE_MODE, new Parameter(SPECIFIC_DATE_PARAMETER, //
                    ParameterType.DATE, //
                    StringUtils.EMPTY, //
                    false, //
                    false)) //
            .item(OTHER_COLUMN_MODE, OTHER_COLUMN_MODE, new Parameter(SELECTED_COLUMN_PARAMETER, //
                    ParameterType.COLUMN, //
                    StringUtils.EMPTY, //
                    false, //
                    false)) //
            .defaultValue(NOW_SERVER_SIDE_MODE) //
            .build());

    return ActionsBundle.attachToAction(parameters, this);
}

From source file:org.talend.dataprep.transformation.actions.date.ComputeTimeSinceTest.java

@Test
public void should_compute_twice_diff_units() throws IOException {
    //given/*from ww  w . ja v a 2s.c  o m*/
    final String date = "07/15/2014 02:00";
    final String resultInMonth = computeTimeSince(date, "M/d/yyyy HH:mm", ChronoUnit.MONTHS);
    final String resultInYears = computeTimeSince(date, "M/d/yyyy HH:mm", ChronoUnit.YEARS);

    final DataSetRow row = getDefaultRow("statistics_MM_dd_yyyy_HH_mm.json");
    row.set("0001", date);

    final Map<String, String> expectedValues = new TreeMap<>();
    expectedValues.put("0000", "lorem bacon");
    expectedValues.put("0001", date);
    expectedValues.put("0004", resultInMonth);
    expectedValues.put("0003", resultInYears);
    expectedValues.put("0002", "Bacon");

    //when
    parameters.put(TIME_UNIT_PARAMETER, YEARS.name());
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));

    parameters.put(TIME_UNIT_PARAMETER, MONTHS.name());
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));

    //then
    assertEquals(expectedValues, row.values());
}