Example usage for org.joda.time DateTime getMonthOfYear

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

Introduction

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

Prototype

public int getMonthOfYear() 

Source Link

Document

Get the month of year field value.

Usage

From source file:com.core.meka.Util.java

public static String fecha(Date fechaAdquisicion) {
    String result = "Sin especificar";
    if (fechaAdquisicion != null) {
        DateTime d = new DateTime(fechaAdquisicion);
        result = d.getDayOfMonth() + "/" + d.getMonthOfYear() + "/" + d.getYear();
    }// www.  j a v a2s  . c  o m
    return result;
}

From source file:com.core.meka.Util.java

public static String fechaLarga(Date fecha) {
    String result = "Sin especificar";
    if (fecha != null) {
        DateTime d = new DateTime(fecha);
        result = d.getDayOfMonth() + "/" + d.getMonthOfYear() + "/" + d.getYear() + " "
                + (d.getHourOfDay() < 10 ? "0" : "") + d.getHourOfDay() + ":"
                + (d.getMinuteOfHour() < 10 ? "0" : "") + d.getMinuteOfHour() + ":"
                + (d.getSecondOfMinute() < 10 ? "0" : "") + d.getSecondOfMinute();
    }//from  w ww. ja  v  a2s.c o m
    return result;
}

From source file:com.core.meka.Util.java

public static String fechaYhora(Date d) {
    DateTime n = new DateTime(d);
    return n.getDayOfMonth() + "/" + n.getMonthOfYear() + "/" + n.getYear() + " "
            + (n.getHourOfDay() < 10 ? "0" + n.getHourOfDay() : n.getHourOfDay()) + ":"
            + (n.getMinuteOfHour() < 10 ? "0" + n.getMinuteOfHour() : n.getMinuteOfHour());
}

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

License:Apache License

/**
 * If date is not match, will return next closest match.
 * If date is match, will return this date.
 * @param date - reference DateTime instance - never null;
 * @return DateTime instance, never null. Value obeys logic specified above.
 * @throws NoSuchValueException//w  w w  .ja va  2 s .c  o m
 */
DateTime nextClosestMatch(DateTime date) throws NoSuchValueException {
    List<Integer> year = yearsValueGenerator.generateCandidates(date.getYear(), date.getYear());
    TimeNode days = null;
    int lowestMonth = months.getValues().get(0);
    int lowestHour = hours.getValues().get(0);
    int lowestMinute = minutes.getValues().get(0);
    int lowestSecond = seconds.getValues().get(0);

    NearestValue nearestValue;
    DateTime newDate;
    if (year.isEmpty()) {
        int newYear = yearsValueGenerator.generateNextValue(date.getYear());
        days = generateDays(cronDefinition, new DateTime(newYear, lowestMonth, 1, 0, 0));
        return initDateTime(yearsValueGenerator.generateNextValue(date.getYear()), lowestMonth,
                days.getValues().get(0), lowestHour, lowestMinute, lowestSecond, date.getZone());
    }
    if (!months.getValues().contains(date.getMonthOfYear())) {
        nearestValue = months.getNextValue(date.getMonthOfYear(), 0);
        int nextMonths = nearestValue.getValue();
        if (nearestValue.getShifts() > 0) {
            newDate = new DateTime(date.getYear(), 1, 1, 0, 0, 0, date.getZone())
                    .plusYears(nearestValue.getShifts());
            return nextClosestMatch(newDate);
        }
        if (nearestValue.getValue() < date.getMonthOfYear()) {
            date = date.plusYears(1);
        }
        days = generateDays(cronDefinition, new DateTime(date.getYear(), nextMonths, 1, 0, 0));
        return initDateTime(date.getYear(), nextMonths, days.getValues().get(0), lowestHour, lowestMinute,
                lowestSecond, date.getZone());
    }
    days = generateDays(cronDefinition, date);
    if (!days.getValues().contains(date.getDayOfMonth())) {
        nearestValue = days.getNextValue(date.getDayOfMonth(), 0);
        if (nearestValue.getShifts() > 0) {
            newDate = new DateTime(date.getYear(), date.getMonthOfYear(), 1, 0, 0, 0, date.getZone())
                    .plusMonths(nearestValue.getShifts());
            return nextClosestMatch(newDate);
        }
        if (nearestValue.getValue() < date.getDayOfMonth()) {
            date = date.plusMonths(1);
        }
        return initDateTime(date.getYear(), date.getMonthOfYear(), nearestValue.getValue(), lowestHour,
                lowestMinute, lowestSecond, date.getZone());
    }
    if (!hours.getValues().contains(date.getHourOfDay())) {
        nearestValue = hours.getNextValue(date.getHourOfDay(), 0);
        int nextHours = nearestValue.getValue();
        if (nearestValue.getShifts() > 0) {
            newDate = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), 0, 0, 0,
                    date.getZone()).plusDays(nearestValue.getShifts());
            return nextClosestMatch(newDate);
        }
        if (nearestValue.getValue() < date.getHourOfDay()) {
            date = date.plusDays(1);
        }
        return initDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), nextHours,
                lowestMinute, lowestSecond, date.getZone());
    }
    if (!minutes.getValues().contains(date.getMinuteOfHour())) {
        nearestValue = minutes.getNextValue(date.getMinuteOfHour(), 0);
        int nextMinutes = nearestValue.getValue();
        if (nearestValue.getShifts() > 0) {
            newDate = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(),
                    date.getHourOfDay(), 0, 0, date.getZone()).plusHours(nearestValue.getShifts());
            return nextClosestMatch(newDate);
        }
        if (nearestValue.getValue() < date.getMinuteOfHour()) {
            date = date.plusHours(1);
        }
        return initDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(),
                nextMinutes, lowestSecond, date.getZone());
    }
    if (!seconds.getValues().contains(date.getSecondOfMinute())) {
        nearestValue = seconds.getNextValue(date.getSecondOfMinute(), 0);
        int nextSeconds = nearestValue.getValue();
        if (nearestValue.getShifts() > 0) {
            newDate = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(),
                    date.getHourOfDay(), date.getMinuteOfHour(), 0, date.getZone())
                            .plusMinutes(nearestValue.getShifts());
            return nextClosestMatch(newDate);
        }
        if (nearestValue.getValue() < date.getSecondOfMinute()) {
            date = date.plusMinutes(1);
        }
        return initDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(),
                date.getMinuteOfHour(), nextSeconds, date.getZone());
    }
    return date;
}

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

License:Apache License

/**
 * If date is not match, will return previous closest match.
 * If date is match, will return this date.
 * @param date - reference DateTime instance - never null;
 * @return DateTime instance, never null. Value obeys logic specified above.
 * @throws NoSuchValueException//  w  w w. j  av  a2 s.  c o m
 */
DateTime previousClosestMatch(DateTime date) throws NoSuchValueException {
    List<Integer> year = yearsValueGenerator.generateCandidates(date.getYear(), date.getYear());
    TimeNode days = generateDays(cronDefinition, date);
    int highestMonth = months.getValues().get(months.getValues().size() - 1);
    int highestDay = days.getValues().get(days.getValues().size() - 1);
    int highestHour = hours.getValues().get(hours.getValues().size() - 1);
    int highestMinute = minutes.getValues().get(minutes.getValues().size() - 1);
    int highestSecond = seconds.getValues().get(seconds.getValues().size() - 1);

    NearestValue nearestValue;
    DateTime newDate;
    if (year.isEmpty()) {
        int previousYear = yearsValueGenerator.generatePreviousValue(date.getYear());
        if (highestDay > 28) {
            int highestDayOfMonth = new DateTime(previousYear, highestMonth, 1, 0, 0).dayOfMonth()
                    .getMaximumValue();
            if (highestDay > highestDayOfMonth) {
                nearestValue = days.getPreviousValue(highestDay, 1);
                if (nearestValue.getShifts() > 0) {
                    newDate = new DateTime(previousYear, highestMonth, 1, 23, 59, 59)
                            .minusMonths(nearestValue.getShifts()).dayOfMonth().withMaximumValue();
                    return previousClosestMatch(newDate);
                } else {
                    highestDay = nearestValue.getValue();
                }
            }
        }
        return initDateTime(previousYear, highestMonth, highestDay, highestHour, highestMinute, highestSecond,
                date.getZone());
    }
    if (!months.getValues().contains(date.getMonthOfYear())) {
        nearestValue = months.getPreviousValue(date.getMonthOfYear(), 0);
        int previousMonths = nearestValue.getValue();
        if (nearestValue.getShifts() > 0) {
            newDate = new DateTime(date.getYear(), 12, 31, 23, 59, 59).minusYears(nearestValue.getShifts());
            return previousClosestMatch(newDate);
        }
        return initDateTime(date.getYear(), previousMonths, highestDay, highestHour, highestMinute,
                highestSecond, date.getZone());
    }
    if (!days.getValues().contains(date.getDayOfMonth())) {
        nearestValue = days.getPreviousValue(date.getDayOfMonth(), 0);
        if (nearestValue.getShifts() > 0) {
            newDate = new DateTime(date.getYear(), date.getMonthOfYear(), 1, 23, 59, 59)
                    .minusMonths(nearestValue.getShifts()).dayOfMonth().withMaximumValue();
            return previousClosestMatch(newDate);
        }
        return initDateTime(date.getYear(), date.getMonthOfYear(), nearestValue.getValue(), highestHour,
                highestMinute, highestSecond, date.getZone());
    }
    if (!hours.getValues().contains(date.getHourOfDay())) {
        nearestValue = hours.getPreviousValue(date.getHourOfDay(), 0);
        if (nearestValue.getShifts() > 0) {
            newDate = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), 23, 59, 59)
                    .minusDays(nearestValue.getShifts());
            return previousClosestMatch(newDate);
        }
        return initDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(),
                nearestValue.getValue(), highestMinute, highestSecond, date.getZone());
    }
    if (!minutes.getValues().contains(date.getMinuteOfHour())) {
        nearestValue = minutes.getPreviousValue(date.getMinuteOfHour(), 0);
        if (nearestValue.getShifts() > 0) {
            newDate = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(),
                    date.getHourOfDay(), 59, 59).minusHours(nearestValue.getShifts());
            return previousClosestMatch(newDate);
        }
        return initDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(),
                nearestValue.getValue(), highestSecond, date.getZone());
    }
    if (!seconds.getValues().contains(date.getSecondOfMinute())) {
        nearestValue = seconds.getPreviousValue(date.getSecondOfMinute(), 0);
        int previousSeconds = nearestValue.getValue();
        if (nearestValue.getShifts() > 0) {
            newDate = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(),
                    date.getHourOfDay(), date.getMinuteOfHour(), 59).minusMinutes(nearestValue.getShifts());
            return previousClosestMatch(newDate);
        }
        return initDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(),
                date.getMinuteOfHour(), previousSeconds, date.getZone());
    }
    return date;
}

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

License:Apache License

TimeNode generateDays(CronDefinition cronDefinition, DateTime date) {
    boolean questionMarkSupported = cronDefinition.getFieldDefinition(DAY_OF_WEEK).getConstraints()
            .isSpecialCharAllowed(QUESTION_MARK);
    if (questionMarkSupported) {
        return new TimeNode(generateDayCandidatesQuestionMarkSupported(date.getYear(), date.getMonthOfYear(),
                ((DayOfWeekFieldDefinition) cronDefinition.getFieldDefinition(DAY_OF_WEEK))
                        .getMondayDoWValue()));
    } else {/* w  ww.j av  a 2  s.  com*/
        return new TimeNode(generateDayCandidatesQuestionMarkNotSupported(date.getYear(), date.getMonthOfYear(),
                ((DayOfWeekFieldDefinition) cronDefinition.getFieldDefinition(DAY_OF_WEEK))
                        .getMondayDoWValue()));
    }
}

From source file:com.digitald4.iis.servlet.DashboardServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    try {/*from  w  ww . jav a  2  s. c  o  m*/
        if (!checkLoginAutoRedirect(request, response))
            return;
        EntityManager entityManager = getEntityManager();
        for (GenData gd : GenData.values()) {
            gd.get(entityManager);
        }
        String action = request.getParameter("action");
        if (action != null && action.equalsIgnoreCase("cal")) {
            processCalendarRequest(request, response);
            return;
        }
        PendingAssServlet.setupTable(entityManager, request);
        PendingIntakeServlet.setupTable(entityManager, request);
        PendingReviewServlet.setupTable(entityManager, request);
        PendingPaymentServlet.setupTable(entityManager, request);
        BillableServlet.setupTable(entityManager, request);
        UnpaidInvoicesServlet.setupTable(request);
        LicenseAlertServlet.setupTable(entityManager, request);
        UnconfirmedAppsServlet.setupTable(request);
        request.setAttribute("upComingUnconfirmed", Appointment.getUpComingUnconfirmed(entityManager));
        DateTime now = DateTime.now();
        request.setAttribute("calendar",
                getCalendar(getEntityManager(), now.getYear(), now.getMonthOfYear()).getOutput());
        getLayoutPage(request, "/WEB-INF/jsp/dashboard.jsp").forward(request, response);
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:com.edoli.calendarlms.CalendarAdapter.java

License:Apache License

@Override
public boolean isEnabled(int position) {
    DateTime date = mDate.plusDays(position);
    if (date.getMonthOfYear() != mMonth) {
        return false;
    }//from  ww w .j  a va2s .com
    return true;
}

From source file:com.edoli.calendarlms.CalendarAdapter.java

License:Apache License

@SuppressWarnings("deprecation")
@Override//from   www .j av a  2  s. c om
public View getView(int position, View convertView, ViewGroup parent) {
    Context context = parent.getContext();
    RelativeLayout view = new RelativeLayout(context);

    DateTime date = mDate.plusDays(position);
    AbsListView.LayoutParams layoutParams = null;

    int gHeight = mGridView.getMeasuredHeight();
    int cHeight = gHeight / 6;
    int gWidth = mGridView.getMeasuredWidth();
    int cWidth = gWidth / 7;
    int row = position / 7;
    int column = position % 7;

    layoutParams = new AbsListView.LayoutParams(cWidth, cHeight);

    if (column == 6) {
        layoutParams.width = gWidth - cWidth * 6;
    }
    if (row == 5) {
        layoutParams.height = gHeight - cHeight * 5;
    }

    view.setLayoutParams(layoutParams);

    int day = date.getDayOfMonth();

    TextView dayView = new TextView(context);
    RelativeLayout.LayoutParams dayParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    dayParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    dayParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    dayView.setLayoutParams(dayParams);
    dayView.setText(day + "");
    dayView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);

    if (column == 0) {
        dayView.setTextColor(Color.RED);
    }

    // Set Background of cell

    int fillColor = 0;
    int strokeColor = 0;

    if (date.getMonthOfYear() != mMonth) {
        fillColor = Color.argb(51, 0, 0, 0);
        strokeColor = Color.GRAY;
        dayView.setTextColor(Color.GRAY);
    } else {
        fillColor = Color.argb(51, 238, 238, 230);
        strokeColor = Color.GRAY;
    }

    // Set different color or event cell
    if (mCalendarEvents != null) {
        for (CalendarEvent event : mCalendarEvents) {
            DateTime eventDate = event.getDate();
            if (eventDate.getDayOfYear() == date.getDayOfYear()) {
                fillColor = Color.argb(51, 205, 92, 92);
            }
        }
    }

    ShapeDrawable drawable = new CellShapeDrawable(fillColor, strokeColor, row, column);
    view.setBackgroundDrawable(drawable);

    view.addView(dayView);

    return view;
}

From source file:com.enitalk.configs.DateCache.java

public NavigableSet<DateTime> days(JsonNode tree, String tz, JsonNode teacherNode) {
    ConcurrentSkipListSet<DateTime> dates = new ConcurrentSkipListSet<>();

    Iterator<JsonNode> els = tree.elements();
    DateTimeZone dz = DateTimeZone.forID(tz);
    DateTimeFormatter hour = DateTimeFormat.forPattern("HH:mm").withZone(dz);

    DateTime today = DateTime.now().millisOfDay().setCopy(0);
    while (els.hasNext()) {

        JsonNode el = els.next();//from   ww  w . j  a  v a 2  s . c  om
        String day = el.path("day").asText();

        boolean plus = today.getDayOfWeek() > days.get(day);
        if (el.has("start") && el.has("end")) {
            DateTime start = hour.parseDateTime(el.path("start").asText()).dayOfMonth()
                    .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year()
                    .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);
            DateTime end = hour.parseDateTime(el.path("end").asText()).dayOfMonth()
                    .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year()
                    .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);

            Hours hours = Hours.hoursBetween(start, end);
            int hh = hours.getHours() + 1;

            while (hh-- > 0) {
                dates.add(start.plusHours(hh).toDateTime(DateTimeZone.UTC));
            }
        } else {
            List<String> datesAv = jackson.convertValue(el.path("times"), List.class);
            logger.info("Array of dates {} {}", datesAv, day);

            datesAv.forEach((String dd) -> {
                DateTime date = hour.parseDateTime(dd).dayOfMonth().setCopy(today.getDayOfMonth()).monthOfYear()
                        .setCopy(today.getMonthOfYear()).year().setCopy(today.getYear())
                        .withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0);
                dates.add(date.toDateTime(DateTimeZone.UTC));
            });

        }

    }

    final TreeSet<DateTime> addWeek = new TreeSet<>();
    for (int i = 1; i < 2; i++) {
        for (DateTime e : dates) {
            addWeek.add(e.plusWeeks(i));

        }
    }

    dates.addAll(addWeek);

    DateTime nowUtc = DateTime.now().toDateTime(DateTimeZone.UTC);
    nowUtc = nowUtc.plusHours(teacherNode.path("notice").asInt(2));

    NavigableSet<DateTime> ss = dates.tailSet(nowUtc, true);

    return ss;

}