Example usage for org.joda.time LocalDateTime toLocalDate

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

Introduction

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

Prototype

public LocalDate toLocalDate() 

Source Link

Document

Converts this object to a LocalDate with the same date and chronology.

Usage

From source file:com.gst.infrastructure.campaigns.sms.service.SmsCampaignWritePlatformServiceJpaImpl.java

License:Apache License

private void updateTriggerDates(Long campaignId) {
    final SmsCampaign smsCampaign = this.smsCampaignRepository.findOne(campaignId);
    if (smsCampaign == null) {
        throw new SmsCampaignNotFound(campaignId);
    }/*  w w  w.  jav  a 2  s.  com*/
    LocalDateTime nextTriggerDate = smsCampaign.getNextTriggerDate();
    smsCampaign.setLastTriggerDate(nextTriggerDate.toDate());
    // calculate new trigger date and insert into next trigger date

    /**
     * next run time has to be in the future if not calculate a new future
     * date
     */
    LocalDate nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
            smsCampaign.getNextTriggerDate().toLocalDate(), nextTriggerDate.toLocalDate());
    if (nextRuntime.isBefore(DateUtils.getLocalDateOfTenant())) { // means
                                                                  // next
                                                                  // run
                                                                  // time is
                                                                  // in the
                                                                  // past
                                                                  // calculate
                                                                  // a new
                                                                  // future
                                                                  // date
        nextRuntime = CalendarUtils.getNextRecurringDate(smsCampaign.getRecurrence(),
                smsCampaign.getNextTriggerDate().toLocalDate(), DateUtils.getLocalDateOfTenant());
    }
    final LocalDateTime getTime = smsCampaign.getRecurrenceStartDateTime();
    final String dateString = nextRuntime.toString() + " " + getTime.getHourOfDay() + ":"
            + getTime.getMinuteOfHour() + ":" + getTime.getSecondOfMinute();
    final DateTimeFormatter simpleDateFormat = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    final LocalDateTime newTriggerDateWithTime = LocalDateTime.parse(dateString, simpleDateFormat);

    smsCampaign.setNextTriggerDate(newTriggerDateWithTime.toDate());
    this.smsCampaignRepository.saveAndFlush(smsCampaign);
}

From source file:com.helger.datetime.PDTFactory.java

License:Apache License

@Nonnull
public static LocalDate createLocalDate(@Nonnull final LocalDateTime aLocalDateTime) {
    return aLocalDateTime.toLocalDate();
}

From source file:de.appsolve.padelcampus.utils.BookingUtil.java

private void addTimeSlot(List<TimeSlot> timeSlots, LocalDateTime time, CalendarConfig config,
        BigDecimal pricePerMinDuration) {
    TimeSlot timeSlot = new TimeSlot();
    timeSlot.setDate(time.toLocalDate());
    timeSlot.setStartTime(time.toLocalTime());
    timeSlot.setEndTime(time.toLocalTime().plusMinutes(config.getMinDuration()));
    timeSlot.setConfig(config);/*  w  w w. j  a va  2  s  . co  m*/
    timeSlot.setPricePerMinDuration(pricePerMinDuration);

    //only add timeSlot if timeSlots does not already contain an entry that overlaps
    if (!overlaps(timeSlot, timeSlots)) {
        timeSlots.add(timeSlot);
    }
}

From source file:edu.harvard.med.screensaver.io.workbook2.Cell.java

License:Open Source License

/**
 * Convenience method to get a LocaleDate from a date cell, when cell might be
 * empty. Behaves same as {@link #getDate()}.
 *//*  ww w.  jav a2  s  .  co  m*/
public LocalDate getLocalDate() {
    LocalDateTime date = getDate();
    if (date == null) {
        return null;
    }
    return date.toLocalDate();
}

From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java

License:Open Source License

public TimeMLDateTimePoint(LocalDateTime lct) {
    this.underlyingTime = lct.toLocalTime();
    this.underlyingDate = lct.toLocalDate();
    inputFields.put(VALUE_FIELD.YEAR,/* ww  w. j a va2s. co m*/
            normalizeByAddingZeroes(VALUE_FIELD.YEAR, (this.underlyingDate).getYear()));
    inputFields.put(VALUE_FIELD.MONTH_OR_WEEK,
            normalizeByAddingZeroes(VALUE_FIELD.MONTH_OR_WEEK, (this.underlyingDate).getMonthOfYear()));
    inputFields.put(VALUE_FIELD.DAY,
            normalizeByAddingZeroes(VALUE_FIELD.DAY, (this.underlyingDate).getDayOfMonth()));
    inputFields.put(VALUE_FIELD.HOUR_OR_POD,
            normalizeByAddingZeroes(VALUE_FIELD.HOUR_OR_POD, (this.underlyingTime).getHourOfDay()));
    inputFields.put(VALUE_FIELD.MINUTE,
            normalizeByAddingZeroes(VALUE_FIELD.MINUTE, (this.underlyingTime).getMinuteOfHour()));
}

From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java

License:Open Source License

public void addToField(Granulaarsus field, int value) {
    if (field == Granulaarsus.MINUTE || field == Granulaarsus.HOUR_OF_HALF_DAY
            || field == Granulaarsus.HOUR_OF_DAY) {
        // Put date and time together
        LocalDateTime ajaFookus = getAsLocalDateTime();
        // perform operation
        if (field == Granulaarsus.MINUTE) {
            ajaFookus = ajaFookus.plusMinutes(value);
            this.underlyingTime = ajaFookus.toLocalTime();
            this.underlyingDate = ajaFookus.toLocalDate();
            if (dateModified) {
                updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION);
            }/*w w  w. ja  va 2 s.  c  o  m*/
            updateTimeRepresentation(field, null, false, ADD_TYPE_OPERATION);
            functionOtherThanSetUsed = true;
        }
        if (field == Granulaarsus.HOUR_OF_DAY || field == Granulaarsus.HOUR_OF_HALF_DAY) {
            ajaFookus = ajaFookus.plusHours(value);
            this.underlyingTime = ajaFookus.toLocalTime();
            this.underlyingDate = ajaFookus.toLocalDate();
            if (dateModified) {
                updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION);
            }
            updateTimeRepresentation(field, null, false, ADD_TYPE_OPERATION);
            functionOtherThanSetUsed = true;
        }
    }
    if (field == Granulaarsus.DAY_OF_MONTH) {
        this.underlyingDate = (this.underlyingDate).plusDays(value);
        updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        dateModified = true;
    }
    if (field == Granulaarsus.DAY_OF_WEEK) {
        this.underlyingDate = (this.underlyingDate).plusDays(value);
        updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        dateModified = true;
    }
    if (field == Granulaarsus.WEEK_OF_YEAR) {
        this.underlyingDate = (this.underlyingDate).plusWeeks(value);
        updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        dateModified = true;
    }
    if (field == Granulaarsus.MONTH) {
        this.underlyingDate = (this.underlyingDate).plusMonths(value);
        updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        dateModified = true;
    }
    if (field == Granulaarsus.YEAR) {
        this.underlyingDate = (this.underlyingDate).plusYears(value);
        updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        dateModified = true;
    }
    if (field == Granulaarsus.YEAR_OF_CENTURY) {
        // NB! Toimib nagu tavalise aastaarvu muutmine         
        this.underlyingDate = (this.underlyingDate).plusYears(value);
        updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        dateModified = true;
    }
    if (field == Granulaarsus.CENTURY_OF_ERA) {
        this.underlyingDate = (this.underlyingDate).plusYears(value * 100);
        updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        dateModified = true;
    }
}

From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java

License:Open Source License

public void addToField(Granulaarsus field, Period period, int direction) {
    if (field.compareByCoarseRank(Granulaarsus.WEEK_OF_YEAR) == -1) {
        // ---- paev, tund, minut
        LocalDateTime ajaFookus = getAsLocalDateTime();
        try {/*from  w  w  w  .  java 2  s.co m*/
            if (direction > 0) {
                ajaFookus = ajaFookus.plus(period);
            } else {
                ajaFookus = ajaFookus.minus(period);
            }
            this.functionOtherThanSetUsed = true;
        } catch (Exception e) {
            // Erindi korral jaabki muutmata
        }
        this.underlyingTime = ajaFookus.toLocalTime();
        this.underlyingDate = ajaFookus.toLocalDate();
        if (field.compareByCoarseRank(Granulaarsus.DAY_OF_MONTH) == 0) {
            this.dateModified = true;
            updateTimeRepresentation(Granulaarsus.HOUR_OF_DAY, null, false, ADD_TYPE_OPERATION);
        } else {
            updateTimeRepresentation(Granulaarsus.MINUTE, null, false, ADD_TYPE_OPERATION);
        }
        if (dateModified) {
            updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION);
        }
    } else {
        // ---- nadal, kuu, aasta, sajand
        try {
            if (direction > 0) {
                this.underlyingDate = (this.underlyingDate).plus(period);
            } else {
                this.underlyingDate = (this.underlyingDate).minus(period);
            }
            this.functionOtherThanSetUsed = true;
            this.dateModified = true;
        } catch (Exception e) {
            // Erindi korral jaabki muutmata
        }
        if (field == Granulaarsus.MONTH || field == Granulaarsus.WEEK_OF_YEAR) {
            updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION);
        }
        if (field == Granulaarsus.YEAR) {
            updateDateRepresentation(Granulaarsus.MONTH, null, false, ADD_TYPE_OPERATION);
        }
        if (field == Granulaarsus.CENTURY_OF_ERA) {
            updateDateRepresentation(Granulaarsus.YEAR, null, false, ADD_TYPE_OPERATION);
        }
    }
}

From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java

License:Open Source License

public void seekField(Granulaarsus field, int direction, String soughtValue, boolean excludingCurrent) {
    // ---------------------------------
    //  PART OF DAY
    // ---------------------------------
    if (field == Granulaarsus.TIME && soughtValue != null && soughtValue.matches("(NI|MO|AF|EV)")
            && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        // Loome k2esolevat ajafookust t2ielikult kirjeldava objekti
        LocalDateTime ajaFookus = getAsLocalDateTime();
        // AlgneMargend ehk p2evaosa, millest peame ennem m66da saama, kuni v6ime uue
        // v22rtuse omaks v6tta
        String algneMargend = (excludingCurrent)
                ? (SemLeidmiseAbimeetodid.getPartOfDay(ajaFookus.toLocalTime()))
                : (null);//from ww  w  .  j a v  a 2s. com
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale tunnile   
            ajaFookus = ajaFookus.plusHours(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDateTime uusFookus = ajaFookus.plusHours(1 * dir);
            ajaFookus = uusFookus;
            String newPartOfDay = SemLeidmiseAbimeetodid.getPartOfDay(uusFookus.toLocalTime());
            if (algneMargend != null) {
                if (algneMargend.equals(newPartOfDay)) {
                    continue;
                } else {
                    algneMargend = null;
                }
            }
            if (newPartOfDay != null && newPartOfDay.equals(soughtValue)) {
                algneMargend = newPartOfDay;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.partOfDay = soughtValue;
        updateTimeRepresentation(Granulaarsus.TIME, soughtValue, true, ADD_TYPE_OPERATION);
        this.underlyingTime = ajaFookus.toLocalTime();
        this.underlyingDate = ajaFookus.toLocalDate();
        functionOtherThanSetUsed = true;
    }
    // ---------------------------------
    //  WORKDAY OR WEEKEND
    // ---------------------------------
    if (field == Granulaarsus.DAY_OF_WEEK && soughtValue != null && soughtValue.matches("(WD|WE)")
            && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne p2ev ehk p2ev, millest tahame tingimata m66duda
        String algneMargend = (excludingCurrent) ? (SemLeidmiseAbimeetodid.getWordDayOrWeekend(ajaFookus))
                : (null);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale p2evale
            ajaFookus = ajaFookus.plusDays(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusDays(1 * dir);
            ajaFookus = nihutatudFookus;
            String toopaevVoiNadalalopp = SemLeidmiseAbimeetodid.getWordDayOrWeekend(ajaFookus);
            if (algneMargend != null) {
                if (algneMargend.equals(toopaevVoiNadalalopp)) {
                    continue;
                } else {
                    algneMargend = null;
                }
            }
            if (toopaevVoiNadalalopp.equals(soughtValue)) {
                algneMargend = toopaevVoiNadalalopp;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        (this.openedFields).put(VALUE_FIELD.DAY, soughtValue);
        updateDateRepresentation(Granulaarsus.DAY_OF_WEEK, soughtValue, true, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //  SEASONs
    // ---------------------------------      
    if (field == Granulaarsus.MONTH && soughtValue != null && soughtValue.matches("(SP|SU|FA|WI)")
            && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne aastaaeg ehk aastaaeg, millest tahame tingimata m66duda
        String algneMargend = (excludingCurrent) ? (SemLeidmiseAbimeetodid.getSeason(ajaFookus)) : (null);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale kuule
            ajaFookus = ajaFookus.plusMonths(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusMonths(1 * dir);
            ajaFookus = nihutatudFookus;
            String aastaaeg = SemLeidmiseAbimeetodid.getSeason(ajaFookus);
            if (algneMargend != null) {
                if (algneMargend.equals(aastaaeg)) {
                    continue;
                } else {
                    algneMargend = null;
                }
            }
            if (aastaaeg.equals(soughtValue)) {
                algneMargend = aastaaeg;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        // Detsembri puhul liigume j2rgmisesse aastasse (st - talve loetakse aasta algusest) ...
        if ((this.underlyingDate).getMonthOfYear() == DateTimeConstants.DECEMBER) {
            this.underlyingDate = (this.underlyingDate).plusMonths(1);
        }
        openedFields.put(VALUE_FIELD.MONTH_OR_WEEK, soughtValue);
        updateDateRepresentation(Granulaarsus.MONTH, soughtValue, true, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
    // ---------------------------------
    //  QUARTERs
    // ---------------------------------      
    if (field == Granulaarsus.MONTH && soughtValue != null && soughtValue.matches("Q(1|2|3|4)")
            && direction != 0) {
        int dir = (direction > 0) ? (1) : (-1);
        LocalDate ajaFookus = new LocalDate(this.underlyingDate);
        // Algne kvartal ehk kvartal, millest tahame tingimata m66duda
        String algneMargend = (excludingCurrent) ? (SemLeidmiseAbimeetodid.getQuarterOfYear(ajaFookus))
                : (null);
        if (!excludingCurrent) {
            // V6tame sammu tagasi, et esimene nihe tooks meid t2pselt k2esolevale kuule
            ajaFookus = ajaFookus.plusMonths(dir * (-1));
        }
        int count = 0;
        while (true) {
            LocalDate nihutatudFookus = ajaFookus.plusMonths(1 * dir);
            ajaFookus = nihutatudFookus;
            String kvartal = SemLeidmiseAbimeetodid.getQuarterOfYear(ajaFookus);
            if (algneMargend != null) {
                if (algneMargend.equals(kvartal)) {
                    continue;
                } else {
                    algneMargend = null;
                }
            }
            if (kvartal.equals(soughtValue)) {
                algneMargend = kvartal;
                count++;
                if (count == Math.abs(direction)) {
                    break;
                }
            }
        }
        this.underlyingDate = ajaFookus;
        String newQuarterVal = SemLeidmiseAbimeetodid.getQuarterOfYear(this.underlyingDate);
        openedFields.put(VALUE_FIELD.MONTH_OR_WEEK, newQuarterVal);
        updateDateRepresentation(Granulaarsus.MONTH, newQuarterVal, true, ADD_TYPE_OPERATION);
        functionOtherThanSetUsed = true;
        this.dateModified = true;
    }
}

From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java

License:Open Source License

/**
 *  Applies the algorithm of Baldwin's window (as implemented in {@link SemLeidmiseAbimeetodid}),
 *  in order to find closest moment of time within a Baldwin's window, which satisfies the 
 *  constraint <tt>field = soughtValue</tt>.
 *  <br>/*from ww w  .  j  a v a  2  s.  com*/
 *  <br>
 *  Only limited number of granularities are supported currently.
 */
public void applyBalwinWindow(Granulaarsus field, String soughtValue) {
    if (soughtValue != null) {
        LocalDateTime ajaFookus = getAsLocalDateTime();
        try {
            int soughtValueAsInt = Integer.parseInt(soughtValue);
            // Only some date fields currently supported
            LocalDateTime uusFookus = SemLeidmiseAbimeetodid.applyBaldwinWindow(field, ajaFookus,
                    soughtValueAsInt);
            this.underlyingTime = uusFookus.toLocalTime();
            this.underlyingDate = uusFookus.toLocalDate();
            if (field == Granulaarsus.DAY_OF_WEEK) {
                // Force the usage of month, in order to get canonical form in output 
                field = Granulaarsus.DAY_OF_MONTH;
            }
            updateDateRepresentation(field, null, false, ADD_TYPE_OPERATION);
            functionOtherThanSetUsed = true;
            this.dateModified = true;
        } catch (NumberFormatException e) {
            LocalDateTime uusFookus = SemLeidmiseAbimeetodid.applyBaldwinWindow(field, ajaFookus, soughtValue);
            if (uusFookus != null) {
                // NB! Currently only season labels and quarter labels are supported
                if (field == Granulaarsus.MONTH) {
                    this.underlyingTime = uusFookus.toLocalTime();
                    this.underlyingDate = uusFookus.toLocalDate();
                    openedFields.put(VALUE_FIELD.MONTH_OR_WEEK, soughtValue);
                    updateDateRepresentation(Granulaarsus.MONTH, soughtValue, true, ADD_TYPE_OPERATION);
                    functionOtherThanSetUsed = true;
                    this.dateModified = true;
                }
            }
        }
    }
}

From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java

License:Open Source License

/**
 *  Applies method {@link SemLeidmiseAbimeetodid#findNthSubpartOfGranularity(Granulaarsus, Granulaarsus, int, int, LocalDateTime)}}. 
 *///from  ww  w.j  av  a2  s  . c o  m
public void findNthSubpartOfGranularity(Granulaarsus superField, Granulaarsus subField,
        int soughtValueOfSubField, int n) {
    LocalDateTime ajaFookus = getAsLocalDateTime();
    LocalDateTime uusFookus = SemLeidmiseAbimeetodid.findNthSubpartOfGranularity(superField, subField,
            soughtValueOfSubField, n, ajaFookus);
    if (uusFookus != null) {
        if (superField == Granulaarsus.MONTH) {
            this.underlyingTime = uusFookus.toLocalTime();
            this.underlyingDate = uusFookus.toLocalDate();
            if (subField == Granulaarsus.DAY_OF_WEEK) {
                if (!(this.maskedFields).containsKey(VALUE_FIELD.MONTH_OR_WEEK)) {
                    // open month and dayOfMonth, otherwise fields will remain closed
                    manageMaskedFields(Granulaarsus.MONTH, null, false, SET_TYPE_OPERATION);
                }
                updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION);
                functionOtherThanSetUsed = true;
                this.dateModified = true;
            } else if (subField == Granulaarsus.WEEK_OF_YEAR) {
                if (!(this.maskedFields).containsKey(VALUE_FIELD.MONTH_OR_WEEK)) {
                    // open month and dayOfMonth, otherwise fields will remain closed
                    manageMaskedFields(Granulaarsus.MONTH, null, false, SET_TYPE_OPERATION);
                }
                updateDateRepresentation(Granulaarsus.WEEK_OF_YEAR, null, false, ADD_TYPE_OPERATION);
                functionOtherThanSetUsed = true;
                this.dateModified = true;
            }
        }
    }
}