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:org.wso2.analytics.esb.util.TimeRangeUtils.java

License:Open Source License

public static int getNoOfSecondForMonthInGivenTimestamp(long timestamp) {
    DateTime time = new DateTime(timestamp);
    return time.dayOfMonth().getMaximumValue() * DateTimeConstants.SECONDS_PER_DAY;
}

From source file:pt.ist.fenixedu.integration.api.OldNewsSyncService.java

License:Open Source License

@GET
@Produces("application/xml")
public Response get(@QueryParam("announcementBoardId") String announcementBoardId,
        @QueryParam("selectedYear") int selectedYear, @QueryParam("selectedMonth") int selectedMonth,
        @QueryParam("language") String language) {
    Set<Post> posts;//  w ww . j  ava2  s  .  c om
    if (announcementBoardId.equals(EVENTS)) {
        posts = Site.fromSlug("tecnicolisboa").categoryForSlug("eventos").getPostsSet();
    } else {
        posts = Site.fromSlug("tecnicolisboa").categoryForSlug("noticias").getPostsSet();
    }
    Locale locale;
    if ("pt".equals(language)) {
        locale = PT;
    } else {
        locale = EN;
    }

    DateTime begin = new DateTime().toDateMidnight().withYear(selectedYear).withMonthOfYear(selectedMonth)
            .withDayOfMonth(1).toDateTime();
    DateTime end = begin.dayOfMonth().withMaximumValue().hourOfDay().withMaximumValue().minuteOfHour()
            .withMaximumValue().secondOfMinute().withMaximumValue();
    Interval i = new Interval(begin, end);

    Category stickyCategory = Bennu.getInstance().getDefaultSite().categoryForSlug("sticky");

    String result = "SUCCESS\n";
    result += "<list>\n";
    int index = 1;
    for (Post post : posts.stream().sorted(Post.CREATION_DATE_COMPARATOR)
            .filter(x -> i.contains(x.getPublicationBegin())).filter(x -> x.getActive())
            .collect(Collectors.toList())) {
        result += "  <net.sourceforge.fenixedu.presentationTier.Action.externalServices.AnnouncementDTO>\n";
        result += "    <creationDate>" + post.getCreationDate().toString("dd/MM/yyyy HH:mm:ss")
                + "</creationDate>\n";
        result += "    <referedSubjectBegin>" + (post.getPublicationBegin() != null
                ? post.getPublicationBegin().toString("dd/MM/yyyy HH:mm:ss")
                : "") + "</referedSubjectBegin>\n";
        result += "    <publicationBegin>" + (post.getPublicationBegin() != null
                ? post.getPublicationBegin().toString("dd/MM/yyyy HH:mm:ss")
                : "") + "</publicationBegin>\n";
        result += "    <publicationEnd>"
                + (post.getPublicationEnd() != null ? post.getPublicationEnd().toString("dd/MM/yyyy HH:mm:ss")
                        : "")
                + "</publicationEnd>\n";
        result += "    <lastModification>" + (post.getModificationDate() != null
                ? post.getModificationDate().toString("dd/MM/yyyy HH:mm:ss")
                : "") + "</lastModification>\n";

        result += "    <subject><![CDATA[" + post.getName().getContent(locale) + "]]></subject>\n";
        result += "    <keywords></keywords>\n";
        result += "    <body><![CDATA[" + post.getBody().getContent(locale) + "]]></body>\n";
        result += "    <author>GCRP</author>\n";
        result += "    <authorEmail>gcrp@ist.utl.pt</authorEmail>\n";
        result += "    <place></place>";
        result += "    <visible>" + post.isVisible() + "</visible>\n";
        result += "    <id>" + post.getExternalId() + "</id>\n";
        result += "    <photoUrl></photoUrl>\n";
        result += "    <campus>Alameda</campus>\n";
        result += "    <categories/>\n";
        result += "    <pressRelease>false</pressRelease>\n";
        result += "    <sticky>" + post.getCategoriesSet().contains(stickyCategory) + "</sticky>\n";
        result += "    <priority>" + index++ + "</priority>\n";
        result += "  </net.sourceforge.fenixedu.presentationTier.Action.externalServices.AnnouncementDTO>\n";
    }

    result += "</list>";
    return Response.ok(result).build();

}

From source file:rapternet.irc.bots.thetardis.listeners.TvSchedule.java

private String todayPlus(int n) {
    DateTime today = new DateTime().plusDays(n);
    String day = today.dayOfMonth().getAsString();
    String month = String.valueOf(today.getMonthOfYear());
    String year = String.valueOf(today.getYear());
    return (year + "-" + month + "-" + day);
}

From source file:ru.touchin.templates.calendar.CalendarUtils.java

License:Apache License

/**
 * Create list of {@link CalendarItem} according to start and end Dates.
 *
 * @param startDate Start date of the range;
 * @param endDate   End date of the range;
 * @return List of CalendarItems that could be one of these: {@link CalendarHeaderItem}, {@link CalendarDayItem} or {@link CalendarEmptyItem}.
 *///from  w ww .  ja  va  2  s .c o  m
@NonNull
@SuppressWarnings("checkstyle:MethodLength")
public static List<CalendarItem> fillRanges(@NonNull final DateTime startDate,
        @NonNull final DateTime endDate) {
    final DateTime cleanStartDate = startDate.withTimeAtStartOfDay();
    final DateTime cleanEndDate = endDate.plusDays(1).withTimeAtStartOfDay();

    DateTime tempTime = cleanStartDate;

    final List<CalendarItem> calendarItems = fillCalendarTillCurrentDate(cleanStartDate, tempTime);

    tempTime = tempTime.plusDays(Days.ONE.getDays());

    final int totalDaysCount = Days.daysBetween(tempTime, cleanEndDate).getDays();
    int shift = calendarItems.get(calendarItems.size() - 1).getEndRange();
    int firstDate = tempTime.getDayOfMonth() - 1;
    int daysEnded = 1;

    while (true) {
        final int daysInCurrentMonth = tempTime.dayOfMonth().getMaximumValue();
        final long firstRangeDate = tempTime.getMillis();

        if ((daysEnded + (daysInCurrentMonth - firstDate)) <= totalDaysCount) {
            tempTime = tempTime.plusMonths(1).withDayOfMonth(1);

            calendarItems.add(new CalendarDayItem(firstRangeDate, firstDate + 1, shift + daysEnded,
                    shift + daysEnded + (daysInCurrentMonth - firstDate) - 1, ComparingToToday.AFTER_TODAY));
            daysEnded += daysInCurrentMonth - firstDate;
            if (daysEnded == totalDaysCount) {
                break;
            }
            firstDate = 0;

            final int firstDayInWeek = tempTime.getDayOfWeek() - 1;

            if (firstDayInWeek != 0) {
                calendarItems.add(new CalendarEmptyItem(shift + daysEnded,
                        shift + daysEnded + (DAYS_IN_WEEK - firstDayInWeek - 1)));
                shift += (DAYS_IN_WEEK - firstDayInWeek);
            }

            calendarItems.add(new CalendarHeaderItem(tempTime.getYear(), tempTime.getMonthOfYear() - 1,
                    shift + daysEnded, shift + daysEnded));
            shift += 1;

            if (firstDayInWeek != 0) {
                calendarItems
                        .add(new CalendarEmptyItem(shift + daysEnded, shift + daysEnded + firstDayInWeek - 1));
                shift += firstDayInWeek;
            }

        } else {
            calendarItems.add(new CalendarDayItem(firstRangeDate, firstDate + 1, shift + daysEnded,
                    shift + totalDaysCount, ComparingToToday.AFTER_TODAY));
            break;
        }
    }

    return calendarItems;
}

From source file:ru.touchin.templates.calendar.CalendarUtils.java

License:Apache License

@NonNull
private static List<CalendarItem> fillCalendarTillCurrentDate(@NonNull final DateTime cleanStartDate,
        @NonNull final DateTime startDate) {
    DateTime temp = startDate;
    final List<CalendarItem> calendarItems = new ArrayList<>();
    int shift = 0;
    final int firstDate = temp.getDayOfMonth() - 1; //?? - 1 ?

    // add first month header
    calendarItems.add(new CalendarHeaderItem(temp.getYear(), temp.get(DateTimeFieldType.monthOfYear()) - 1,
            shift, shift)); // is Month starts from 1 or 0 ?
    temp = temp.withDayOfMonth(1);/*from   www  .j a v  a  2  s .  c o m*/
    shift += 1;

    final int firstDayInTheWeek = temp.getDayOfWeek() - 1;

    // check if first day is Monday. If not - add empty items. Otherwise do nothing
    if (firstDayInTheWeek != 0) {
        calendarItems.add(new CalendarEmptyItem(shift, shift + firstDayInTheWeek - 1));
    }
    shift += firstDayInTheWeek;

    // add range with days before today
    calendarItems.add(new CalendarDayItem(temp.getMillis(), 1, shift, shift + firstDate - 1,
            ComparingToToday.BEFORE_TODAY));
    shift += firstDate;

    // add today item
    temp = cleanStartDate;
    calendarItems
            .add(new CalendarDayItem(temp.getMillis(), firstDate + 1, shift, shift, ComparingToToday.TODAY));

    //add empty items and header if current day the last day in the month
    if (temp.getDayOfMonth() == temp.dayOfMonth().getMaximumValue()) {
        addItemsIfCurrentDayTheLastDayInTheMonth(startDate, calendarItems);
    }

    return calendarItems;
}

From source file:test.sql.CustomerDataManager.java

License:Apache License

public String makeSubject() {
    // String sub = LINKAGE_SUBJECT_PREFIX + StressTester.randomString(8);

    DateTime now = new DateTime();
    int year, month, day, hour, minute, second;
    year = now.year().get();/*from  w w  w  .j a va 2  s. c  o m*/
    month = now.monthOfYear().get();
    day = now.dayOfMonth().get();
    hour = now.getHourOfDay();
    minute = now.getMinuteOfHour();
    second = now.getSecondOfMinute();

    StringBuilder sb = new StringBuilder();
    sb.append(LINKAGE_SUBJECT_PREFIX);
    sb.append(StressTester.randomString(8));
    sb.append("_");
    sb.append(Integer.toString(year));
    if (month < 10)
        sb.append("0");
    sb.append(Integer.toString(month));
    if (day < 10)
        sb.append("0");
    sb.append(Integer.toString(day));
    sb.append("_");
    if (hour < 10)
        sb.append("0");
    sb.append(Integer.toString(hour));
    if (minute < 10)
        sb.append("0");
    sb.append(Integer.toString(minute));
    if (second < 10)
        sb.append("0");
    sb.append(Integer.toString(second));

    return sb.toString();
}

From source file:test.sql.TrackingDataManager.java

License:Apache License

public String makeSubject() {
    String sub = LINKAGE_SUBJECT_PREFIX + StressTester.randomString(8);

    DateTime now = new DateTime();
    int year, month, day, hour, minute, second;
    year = now.year().get();//from  www  . j  a  v a2s. c  om
    month = now.monthOfYear().get();
    day = now.dayOfMonth().get();
    hour = now.getHourOfDay();
    minute = now.getMinuteOfHour();
    second = now.getSecondOfMinute();

    StringBuilder sb = new StringBuilder();
    sb.append(LINKAGE_SUBJECT_PREFIX);
    sb.append(StressTester.randomString(8));
    sb.append("_");
    sb.append(Integer.toString(year));
    if (month < 10)
        sb.append("0");
    sb.append(Integer.toString(month));
    if (day < 10)
        sb.append("0");
    sb.append(Integer.toString(day));
    sb.append("_");
    if (hour < 10)
        sb.append("0");
    sb.append(Integer.toString(hour));
    if (minute < 10)
        sb.append("0");
    sb.append(Integer.toString(minute));
    if (second < 10)
        sb.append("0");
    sb.append(Integer.toString(second));

    return sb.toString();
}

From source file:TVShowTimelineMaker.timeConstraints.dayAcceptors.SameTimeAsDayAcceptor.java

public boolean accept2(DateTime inDateTime) {
    boolean rValue = true;
    for (DayEvent<?, ?> curEvent : this.Events) {
        boolean foundMatch = false;
        if (curEvent instanceof OnceDayEvent) {
            NavigableSet<DateTime> curPossibleDays = ((OnceDayEvent) curEvent).getPossibleDays();
            for (DateTime curDateTime : curPossibleDays) {
                if ((inDateTime.monthOfYear().get() == curDateTime.monthOfYear().get())
                        && (inDateTime.dayOfMonth().get() == curDateTime.dayOfMonth().get())) {
                    foundMatch = true;//from   w  w  w .j  a  va 2s  .c om
                    break;
                }
            }
        } else if (curEvent instanceof YearlyDayEvent) {
            NavigableSet<DayOfYear> curPossibleDays = ((YearlyDayEvent) curEvent).getPossibleDays();
            for (DayOfYear curDateTime : curPossibleDays) {
                if ((inDateTime.monthOfYear().get() == curDateTime.getMonth())
                        && (inDateTime.dayOfMonth().get() == curDateTime.getDay())) {
                    foundMatch = true;
                    break;
                }
            }
        }
        if (!foundMatch) {
            rValue = false;
            break;
        }
    }
    return rValue;
}

From source file:TVShowTimelineMaker.timeConstraints.dayAcceptors.SameTimeAsDayAcceptor.java

public boolean accept2(DayOfYear inDateTime) {
    boolean rValue = true;
    for (DayEvent<?, ?> curEvent : this.Events) {
        boolean foundMatch = false;
        if (curEvent instanceof OnceDayEvent) {
            NavigableSet<DateTime> curPossibleDays = ((OnceDayEvent) curEvent).getPossibleDays();
            for (DateTime curDateTime : curPossibleDays) {
                if ((inDateTime.getMonth() == curDateTime.monthOfYear().get())
                        && (inDateTime.getDay() == curDateTime.dayOfMonth().get())) {
                    foundMatch = true;//w  ww. ja va 2 s  . c o m
                    break;
                }
            }

        } else if (curEvent instanceof YearlyDayEvent) {
            NavigableSet<DayOfYear> curPossibleDays = ((YearlyDayEvent) curEvent).getPossibleDays();
            for (DayOfYear curDateTime : curPossibleDays) {
                if ((inDateTime.getMonth() == curDateTime.getMonth())
                        && (inDateTime.getDay() == curDateTime.getDay())) {
                    foundMatch = true;
                    break;
                }
            }
        }
        if (!foundMatch) {
            rValue = false;
            break;
        }
    }
    return rValue;
}