Example usage for org.joda.time DateTime dayOfMonth

List of usage examples for org.joda.time DateTime dayOfMonth

Introduction

In this page you can find the example usage for org.joda.time DateTime dayOfMonth.

Prototype

public Property dayOfMonth() 

Source Link

Document

Get the day of month property which provides access to advanced functionality.

Usage

From source file:com.cronutils.model.time.ExecutionTime.java

License:Apache License

private List<Integer> generateDayCandidatesQuestionMarkSupported(int year, int month, WeekDay mondayDoWValue) {
    DateTime date = new DateTime(year, month, 1, 1, 1);
    Set<Integer> candidates = Sets.newHashSet();
    if (daysOfMonthCronField.getExpression() instanceof Always
            && daysOfWeekCronField.getExpression() instanceof Always) {
        candidates.addAll(FieldValueGeneratorFactory
                .createDayOfMonthValueGeneratorInstance(daysOfMonthCronField, year, month)
                .generateCandidates(1, date.dayOfMonth().getMaximumValue()));
    } else {//from   ww w .jav  a  2  s . com
        if (daysOfMonthCronField.getExpression() instanceof QuestionMark) {
            // the day of week calculator must get a -1 value to indicate its generating the first value of the month
            candidates.addAll(FieldValueGeneratorFactory
                    .createDayOfWeekValueGeneratorInstance(daysOfWeekCronField, year, month, mondayDoWValue)
                    .generateCandidates(-1, date.dayOfMonth().getMaximumValue()));
        } else {
            if (daysOfWeekCronField.getExpression() instanceof QuestionMark) {
                candidates.addAll(FieldValueGeneratorFactory
                        .createDayOfMonthValueGeneratorInstance(daysOfMonthCronField, year, month)
                        .generateCandidates(1, date.dayOfMonth().getMaximumValue()));
            } else {
                candidates.addAll(FieldValueGeneratorFactory
                        .createDayOfWeekValueGeneratorInstance(daysOfWeekCronField, year, month, mondayDoWValue)
                        .generateCandidates(1, date.dayOfMonth().getMaximumValue()));
                candidates.addAll(FieldValueGeneratorFactory
                        .createDayOfMonthValueGeneratorInstance(daysOfMonthCronField, year, month)
                        .generateCandidates(1, date.dayOfMonth().getMaximumValue()));
            }
        }
    }
    List<Integer> candidatesList = Lists.newArrayList(candidates);
    Collections.sort(candidatesList);
    return candidatesList;
}

From source file:com.cronutils.model.time.generator.OnDayOfMonthValueGenerator.java

License:Apache License

private int generateValue(On on, int year, int month) throws NoSuchValueException {
    int time = on.getTime().getValue();
    switch (on.getSpecialChar().getValue()) {
    case L:/* www .  j  a  v a  2s  . c om*/
        return new DateTime(year, month, 1, 1, 1).dayOfMonth().getMaximumValue();
    case W:
        DateTime doM = new DateTime(year, month, time, 1, 1);
        if (doM.getDayOfWeek() == 6) {//dayOfWeek is Saturday!
            if (time == 1) {//first day in month is Saturday! We execute on Monday
                return 3;
            }
            return time - 1;
        }
        if (doM.getDayOfWeek() == 7) {
            if ((time + 1) <= doM.dayOfMonth().getMaximumValue()) {
                return time + 1;
            }
        }
        break;
    case LW:
        DateTime lastDayOfMonth = new DateTime(year, month,
                new DateTime(year, month, 1, 1, 1).dayOfMonth().getMaximumValue(), 1, 1);
        int dow = lastDayOfMonth.getDayOfWeek();
        int diff = dow - 5;
        if (diff > 0) {
            return lastDayOfMonth.minusDays(diff).dayOfMonth().get();
        }
        return lastDayOfMonth.dayOfMonth().get();
    }
    throw new NoSuchValueException();
}

From source file:com.cronutils.model.time.generator.OnDayOfWeekValueGenerator.java

License:Apache License

private int generateLValues(On on, int year, int month) throws NoSuchValueException {
    int lastDoM = new DateTime(year, month, 1, 1, 1).dayOfMonth().getMaximumValue();
    DateTime lastDoMDateTime = new DateTime(year, month, lastDoM, 1, 1);
    int dowForLastDoM = lastDoMDateTime.getDayOfWeek();//1-7
    int requiredDoW = ConstantsMapper.weekDayMapping(mondayDoWValue, ConstantsMapper.JODATIME_WEEK_DAY,
            on.getTime().getValue());//to normalize to joda-time value
    int dowDiff = dowForLastDoM - requiredDoW;

    if (dowDiff == 0) {
        return lastDoMDateTime.dayOfMonth().get();
    }/*from ww w.ja  v a  2  s . c  o  m*/
    if (dowDiff < 0) {
        return lastDoMDateTime.minusDays(dowForLastDoM + (7 - requiredDoW)).dayOfMonth().get();
    }
    if (dowDiff > 0) {
        return lastDoMDateTime.minusDays(dowDiff).dayOfMonth().get();
    }
    throw new NoSuchValueException();
}

From source file:com.google.android.apps.paco.EsmGenerator2.java

License:Open Source License

private DateTime adjustStartDateToBeginningOfPeriod(DateTime startDate) {
    switch (schedule.getEsmPeriodInDays()) {
    case SignalSchedule.ESM_PERIOD_DAY:
        return startDate;
    case SignalSchedule.ESM_PERIOD_WEEK:
        return startDate.dayOfWeek().withMinimumValue();
    case SignalSchedule.ESM_PERIOD_MONTH:
        return startDate.dayOfMonth().withMinimumValue();
    default://  www  .jav a 2s.  c  o  m
        throw new IllegalStateException("Cannot get here.");
    }
}

From source file:com.google.android.apps.paco.EsmGenerator2.java

License:Open Source License

private List<Integer> getPeriodDaysForMonthOf(DateTime startDate) {
    int dow = startDate.getDayOfWeek();
    int day = 1;//w  w w  .jav a2s.  c o m
    int lastDayOfMonth = startDate.dayOfMonth().withMaximumValue().getDayOfMonth();
    List<Integer> validPeriods = new ArrayList<Integer>();
    while (day < lastDayOfMonth + 1) {
        if (schedule.getEsmWeekends() || !TimeUtil.isWeekend(dow)) {
            validPeriods.add(day);
        }
        dow++;
        if (dow == 8) {
            dow = 1;
        }
        day++;
    }
    return validPeriods;
}

From source file:com.google.android.apps.paco.Experiment.java

License:Open Source License

@JsonIgnore
DateMidnight getPeriodStart(DateTime now) {
    switch (((SignalSchedule) getSignalingMechanisms().get(0)).getEsmPeriodInDays()) {
    case SignalSchedule.ESM_PERIOD_DAY:
        return now.toDateMidnight();
    case SignalSchedule.ESM_PERIOD_WEEK:
        return now.dayOfWeek().withMinimumValue().toDateMidnight();
    case SignalSchedule.ESM_PERIOD_MONTH:
        return now.dayOfMonth().withMinimumValue().toDateMidnight();
    default:/*  www.jav a  2 s  .  c  o  m*/
        throw new IllegalStateException("Cannot get here.");
    }
}

From source file:com.idylwood.yahoo.Date.java

License:Open Source License

private Date(final DateTime dt) {
    this(dt.year().get(), dt.monthOfYear().get(), dt.dayOfMonth().get());
}

From source file:com.linkedin.cubert.utils.DateTimeUtilities.java

License:Open Source License

public static int asInt(DateTime dt) {
    return dt.year().get() * 100 * 100 + dt.monthOfYear().get() * 100 + dt.dayOfMonth().get();
}

From source file:com.linkedin.cubert.utils.DateTimeUtilities.java

License:Open Source License

public static String getHyphenated(int dateInt) {
    DateTime dt = getDateTime(Integer.toString(dateInt));
    return String.format("%04d-%02d-%02d", dt.year().get(), dt.monthOfYear().get(), dt.dayOfMonth().get());
}

From source file:com.pacoapp.paco.shared.scheduling.EsmGenerator2.java

License:Open Source License

private DateTime adjustStartDateToBeginningOfPeriod(DateTime startDate) {
    switch (schedule.getEsmPeriodInDays()) {
    case Schedule.ESM_PERIOD_DAY:
        return startDate;
    case Schedule.ESM_PERIOD_WEEK:
        return startDate.dayOfWeek().withMinimumValue();
    case Schedule.ESM_PERIOD_MONTH:
        return startDate.dayOfMonth().withMinimumValue();
    default://from   w w w.j  a  va 2 s . c o  m
        throw new IllegalStateException("Cannot get here.");
    }
}