Example usage for org.joda.time LocalDateTime getYear

List of usage examples for org.joda.time LocalDateTime getYear

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime getYear.

Prototype

public int getYear() 

Source Link

Document

Get the year field value.

Usage

From source file:de.avanux.smartapplianceenabler.appliance.TimeOfDayOfWeek.java

License:Open Source License

public LocalDateTime toNextOccurrence(LocalDateTime now) {
    LocalDateTime dateTime = new LocalDateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(),
            getHour(), getMinute(), getSecond());
    while (dateTime.get(DateTimeFieldType.dayOfWeek()) != dayOfWeek) {
        dateTime = dateTime.plusDays(1);
    }/*from  w  w w  .  j  a va2  s  . c  o  m*/
    return dateTime;
}

From source file:de.avanux.smartapplianceenabler.appliance.TimeOfDayOfWeek.java

License:Open Source License

public LocalDateTime toLastOccurrence(LocalDateTime now) {
    LocalDateTime dateTime = new LocalDateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(),
            getHour(), getMinute(), getSecond());
    while (dateTime.get(DateTimeFieldType.dayOfWeek()) != dayOfWeek) {
        dateTime = dateTime.minusDays(1);
    }//  w ww.  ja va 2  s  .  com
    return dateTime;
}

From source file:de.javakaffee.kryoserializers.jodatime.JodaLocalDateTimeSerializer.java

License:Apache License

@Override
public void write(Kryo kryo, Output output, LocalDateTime localDateTime) {
    final int packedYearMonthDay = localDateTime.getYear() * 13 * 32 + localDateTime.getMonthOfYear() * 32
            + localDateTime.getDayOfMonth();
    output.writeLong((long) packedYearMonthDay * 86400000 + localDateTime.getMillisOfDay(), true);
    final String chronologyId = IdentifiableChronology.getChronologyId(localDateTime.getChronology());
    output.writeString(chronologyId == null ? "" : chronologyId);
}

From source file:de.jpaw.bonaparte.util.DayTime.java

License:Apache License

/** Converts the day portion of a LocalDate or localDateTime into a number in the format YYYYMMDD. */
static public int dayAsInt(LocalDateTime when) {
    return when.getDayOfMonth() + 100 * when.getMonthOfYear() + 10000 * when.getYear();
}

From source file:ee.ut.soras.ajavtV2.Main.java

License:Open Source License

/**
 *    Loob etteantud sisends6ne p6hjal referentsaja: granulaarsuste <i>aasta, kuu, kuupaev,
 *    tund, minut</i> vaartuste j2rjendi. Kui sisends6ne ei rahulda regulaaravaldisi 
 *    <code>/[0-9X]{4}-[0-9X]{2}-[0-9X]{2}T[0-9X]{2}:[0-9X]{2}/</code> vi
 *    <code>/[0-9X]{4}-[0-9X]{2}-[0-9X]{2}/</code> , tagastatakse null.
 *    Kui sisends6ne on null, luuakse referentsaja j2rjend minuti-t2psusega hetkeaja p6hjal.
 *    <br><br> //  w  ww .ja  v a2  s . co m
 *    Tagastatud j2rjendis on granulaarsuste vaartused j2rjekorras 
 *    <i>aasta, kuu, kuupaev, tund, minut</i>. 
 */
public static String[] looSonePohjalReferentsAeg(String sone) {
    if (sone != null) {
        if (sone.matches("[0-9X]{4}-[0-9X]{2}-[0-9X]{2}T[0-9X]{2}:[0-9X]{2}")) {
            // 1) Kui sisends6ne vastab etteantud mustrile
            String[] kalendriValjadeVaartused = new String[5];
            int j = 0;
            boolean seenXXXvalues = false;
            StringTokenizer tokens1 = new StringTokenizer(sone, "-:T");
            while (tokens1.hasMoreTokens()) {
                String s = (String) tokens1.nextToken();
                if (j < kalendriValjadeVaartused.length) {
                    kalendriValjadeVaartused[j] = s;
                }
                if (s.matches("X+")) {
                    seenXXXvalues = true;
                } else {
                    if (seenXXXvalues) {
                        // Kui on l2bisegi numbrid ja XX-v22rtused, on tegemist mitte-
                        // koosk6lalise  sisendajaga:   parandame   numbrid   XX-ideks
                        kalendriValjadeVaartused[j] = "XX";
                    }
                }
                if (j < kalendriValjadeVaartused.length) {
                    j++;
                }
            }
            return kalendriValjadeVaartused;
        } else if (sone.matches("^[0-9X]{4}-[0-9X]{2}-[0-9X]{2}$")) {
            // 2) Kui sisends6ne vastab etteantud mustrile
            String[] kalendriValjadeVaartused = new String[5];
            int j = 0;
            boolean seenXXXvalues = false;
            StringTokenizer tokens2 = new StringTokenizer(sone, "-");
            while (tokens2.hasMoreTokens()) {
                String s = (String) tokens2.nextToken();
                if (j < kalendriValjadeVaartused.length) {
                    kalendriValjadeVaartused[j] = s;
                }
                if (s.matches("X+")) {
                    seenXXXvalues = true;
                } else {
                    if (seenXXXvalues) {
                        // Kui on l2bisegi numbrid ja XX-v22rtused, on tegemist mitte-
                        // koosk6lalise  sisendajaga:   parandame   numbrid   XX-ideks
                        kalendriValjadeVaartused[j] = "XX";
                    }
                }
                if (j < kalendriValjadeVaartused.length) {
                    j++;
                }
            }
            // Viimased (kellaaja osa) ongi selle mustri puhul teadmata
            kalendriValjadeVaartused[3] = "XX";
            kalendriValjadeVaartused[4] = "XX";
            return kalendriValjadeVaartused;
        }
        return null;
    } else {
        // 2) Kui sisends6ne puudub v6i ei vasta etteantud mustrile, loome uue
        // referentsaja, milleks saab hetkeaeg
        LocalDateTime hetkeAeg = new LocalDateTime();
        String[] kalendriValjadeVaartused = new String[5];
        kalendriValjadeVaartused[0] = String.valueOf(hetkeAeg.getYear());
        kalendriValjadeVaartused[1] = String.valueOf(hetkeAeg.getMonthOfYear());
        kalendriValjadeVaartused[2] = String.valueOf(hetkeAeg.getDayOfMonth());
        kalendriValjadeVaartused[3] = String.valueOf(hetkeAeg.getHourOfDay());
        kalendriValjadeVaartused[4] = String.valueOf(hetkeAeg.getMinuteOfHour());
        for (int i = 1; i < kalendriValjadeVaartused.length; i++) {
            if (kalendriValjadeVaartused[i].length() == 1) {
                kalendriValjadeVaartused[i] = "0" + kalendriValjadeVaartused[i];
            }
        }
        return kalendriValjadeVaartused;
    }
}

From source file:org.apache.isis.applib.fixturescripts.clock.ClockFixture.java

License:Apache License

@Override
protected void execute(ExecutionContext ec) {

    // can only be used in the context of integration tests
    if (!(Clock.getInstance() instanceof FixtureClock)) {
        throw new IllegalStateException("Clock has not been initialized as a FixtureClock");
    }/*from  w w w .  j  av  a  2  s  .  c  om*/
    final FixtureClock fixtureClock = (FixtureClock) FixtureClock.getInstance();

    // check that some value has been set
    checkParam("date", ec, String.class);

    // process if can be parsed as a LocalDateTime
    LocalDateTime ldt = parseAsLocalDateTime(date);
    if (ldt != null) {
        fixtureClock.setDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth());
        fixtureClock.setTime(ldt.getHourOfDay(), ldt.getMinuteOfHour());
        return;
    }

    // else process if can be parsed as a LocalDate
    LocalDate ld = parseAsLocalDate(date);
    if (ld != null) {
        fixtureClock.setDate(ld.getYear(), ld.getMonthOfYear(), ld.getDayOfMonth());
        return;
    }

    // else
    throw new IllegalArgumentException(
            String.format("'%s' could not be parsed as a local date/time or local date", date));
}

From source file:org.apache.isis.applib.fixturescripts.clock.TickingClockFixture.java

License:Apache License

private void setTo(final String date) {

    if (!(Clock.getInstance() instanceof FixtureClock)) {
        throw new IllegalStateException("Clock has not been initialized as a FixtureClock");
    }/* www. j a  v a 2 s.  c o  m*/
    final FixtureClock fixtureClock = (FixtureClock) FixtureClock.getInstance();

    // process if can be parsed as a LocalDateTime
    LocalDateTime ldt = parseAsLocalDateTime(date);
    if (ldt != null) {
        fixtureClock.setDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth());
        fixtureClock.setTime(ldt.getHourOfDay(), ldt.getMinuteOfHour());
        return;
    }

    // else process if can be parsed as a LocalDate
    LocalDate ld = parseAsLocalDate(date);
    if (ld != null) {
        fixtureClock.setDate(ld.getYear(), ld.getMonthOfYear(), ld.getDayOfMonth());
        return;
    }

    // else
    throw new IllegalArgumentException(
            String.format("'%s' could not be parsed as a local date/time or local date", date));

}

From source file:org.apache.isis.schema.utils.jaxbadapters.JodaLocalDateTimeXMLGregorianCalendarAdapter.java

License:Apache License

public static XMLGregorianCalendar print(final LocalDateTime dateTime) {
    if (dateTime == null)
        return null;

    final XMLGregorianCalendarImpl xgc = new XMLGregorianCalendarImpl();
    xgc.setYear(dateTime.getYear());
    xgc.setMonth(dateTime.getMonthOfYear());
    xgc.setDay(dateTime.getDayOfMonth());
    xgc.setHour(dateTime.getHourOfDay());
    xgc.setMinute(dateTime.getMinuteOfHour());
    xgc.setSecond(dateTime.getSecondOfMinute());
    xgc.setMillisecond(dateTime.getMillisOfSecond());

    return xgc;//from ww w .j  a  v a2s  .c om
}

From source file:org.apache.isis.schema.utils.jaxbadapters.XmlCalendarFactory.java

License:Apache License

public static XMLGregorianCalendar create(LocalDateTime localDateTime) {
    return localDateTime != null ? withTypeFactoryDo(dtf -> dtf.newXMLGregorianCalendar(localDateTime.getYear(),
            localDateTime.getMonthOfYear(), localDateTime.getDayOfMonth(), localDateTime.getHourOfDay(),
            localDateTime.getMinuteOfHour(), localDateTime.getSecondOfMinute(),
            localDateTime.getMillisOfSecond(), DatatypeConstants.FIELD_UNDEFINED)) : null;
}

From source file:org.assertj.jodatime.api.LocalDateTimeAssert.java

License:Apache License

/**
 * Returns true if both datetime are in the same year, false otherwise.
 * //from ww  w  .ja  v  a 2  s  .com
 * @param actual the actual datetime. expected not be null
 * @param other the other datetime. expected not be null
 * @return true if both datetime are in the same year, false otherwise
 */
private static boolean haveSameYear(LocalDateTime actual, LocalDateTime other) {
    return actual.getYear() == other.getYear();
}