Example usage for org.joda.time DateTime getDayOfMonth

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

Introduction

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

Prototype

public int getDayOfMonth() 

Source Link

Document

Get the day of month field value.

Usage

From source file:org.pidome.server.services.clients.remoteclient.RemoteClient.java

License:Apache License

/**
 * Returns the date since this client connected (From successful login).
 * @return //from   ww  w. ja va2  s.  c  om
 */
public final String getConnectedSinceDateTime() {
    DateTime dt = new DateTime(connectedSince);
    return TimeUtils.composeDDMMYYYYDate(dt.getDayOfMonth(), dt.getMonthOfYear(), dt.getYear()) + " "
            + TimeUtils.compose24Hours(dt.getHourOfDay(), dt.getMinuteOfHour());
}

From source file:org.projectbuendia.client.ui.patientcreation.PatientCreationActivity.java

License:Apache License

@Override
protected void onCreateImpl(Bundle savedInstanceState) {
    super.onCreateImpl(savedInstanceState);

    App.getInstance().inject(this);

    CrudEventBus crudEventBus = mCrudEventBusProvider.get();

    mController = new PatientCreationController(new MyUi(), crudEventBus, mModel);
    mAlertDialog = new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_info)
            .setTitle(R.string.title_add_patient_cancel)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                @Override//  w  w  w.  j  av a2s.c o  m
                public void onClick(DialogInterface dialog, int i) {
                    finish();
                }
            }).setNegativeButton("No", null).create();

    setContentView(R.layout.activity_patient_creation);
    ButterKnife.inject(this);

    DateTime now = DateTime.now();
    mAdmissionDateSetListener = new DateSetListener(mAdmissionDate, LocalDate.now());
    mAdmissionDatePickerDialog = new DatePickerDialog(this, mAdmissionDateSetListener, now.getYear(),
            now.getMonthOfYear() - 1, now.getDayOfMonth());
    mAdmissionDatePickerDialog.setTitle(R.string.admission_date_picker_title);
    mAdmissionDatePickerDialog.getDatePicker().setCalendarViewShown(false);
    mSymptomsOnsetDateSetListener = new DateSetListener(mSymptomsOnsetDate, null);
    mSymptomsOnsetDatePickerDialog = new DatePickerDialog(this, mSymptomsOnsetDateSetListener, now.getYear(),
            now.getMonthOfYear() - 1, now.getDayOfMonth());
    mSymptomsOnsetDatePickerDialog.setTitle(R.string.symptoms_onset_date_picker_title);
    mSymptomsOnsetDatePickerDialog.getDatePicker().setCalendarViewShown(false);

    mLocationSelectedCallback = new AssignLocationDialog.LocationSelectedCallback() {

        @Override
        public boolean onNewTentSelected(String newTentUuid) {
            mLocationUuid = newTentUuid;
            updateLocationUi();
            return true;
        }
    };

    // Pre-populate admission date with today.
    mAdmissionDate.setText(Dates.toMediumString(DateTime.now().toLocalDate()));
}

From source file:org.projectforge.web.address.BirthdayEventsProvider.java

License:Open Source License

/**
 * @see org.projectforge.web.calendar.MyFullCalendarEventsProvider#buildEvents(org.joda.time.DateTime, org.joda.time.DateTime)
 *///from  ww  w  .  ja v  a  2s  . c  o  m
@Override
protected void buildEvents(final DateTime start, final DateTime end) {
    if (filter.isShowBirthdays() == false) {
        // Don't show birthdays.
        return;
    }
    DateTime from = start;
    if (start.getMonthOfYear() == Calendar.MARCH && start.getDayOfMonth() == 1) {
        from = start.minusDays(1);
    }
    final Set<BirthdayAddress> set = addressDao.getBirthdays(from.toDate(), end.toDate(), 1000, true);
    for (final BirthdayAddress birthdayAddress : set) {
        final AddressDO address = birthdayAddress.getAddress();
        final int month = birthdayAddress.getMonth() + 1;
        final int dayOfMonth = birthdayAddress.getDayOfMonth();
        DateTime date = getDate(from, end, month, dayOfMonth);
        // February, 29th fix:
        if (date == null && month == Calendar.FEBRUARY + 1 && dayOfMonth == 29) {
            date = getDate(from, end, month + 1, 1);
        }
        if (date == null && WebConfiguration.isDevelopmentMode() == true) {
            log.info("Date " + birthdayAddress.getDayOfMonth() + "/" + (birthdayAddress.getMonth() + 1)
                    + " not found between " + from + " and " + end);
            continue;
        } else {
            if (dataProtection == false && date != null) {
                birthdayAddress.setAge(date.toDate());
            }
        }
        final Event event = new Event().setAllDay(true);
        event.setClassName(EVENT_CLASS_NAME);
        final String id = "" + address.getId();
        event.setId(id);
        event.setStart(date);
        final StringBuffer buf = new StringBuffer();
        if (dataProtection == false) {
            // Birthday is not visible for all users (age == 0).
            buf.append(DateTimeFormatter.instance().getFormattedDate(address.getBirthday(),
                    DateFormats.getFormatString(DateFormatType.DATE_SHORT))).append(" ");
        }
        buf.append(address.getFirstName()).append(" ").append(address.getName());
        if (dataProtection == false && birthdayAddress.getAge() > 0) {
            // Birthday is not visible for all users (age == 0).
            buf.append(" (").append(birthdayAddress.getAge()).append(" ").append(getString("address.age.short"))
                    .append(")");
        }
        event.setTitle(buf.toString());
        if (birthdayAddress.isFavorite() == true) {
            // Colors of events of birthdays of favorites (for default color see CalendarPanel):
            event.setBackgroundColor("#06790E");
            event.setBorderColor("#06790E");
            event.setTextColor("#FFFFFF");
        }
        events.put(id, event);
    }
}

From source file:org.projectforge.web.address.BirthdayEventsProvider.java

License:Open Source License

private DateTime getDate(final DateTime start, final DateTime end, final int month, final int dayOfMonth) {
    DateTime day = start;
    int paranoiaCounter = 0;
    do {/*  w  ww. ja v a2s  . com*/
        if (day.getMonthOfYear() == month && day.getDayOfMonth() == dayOfMonth) {
            return day;
        }
        day = day.plusDays(1);
        if (++paranoiaCounter > 1000) {
            log.error(
                    "Paranoia counter exceeded! Dear developer, please have a look at the implementation of getDate.");
            break;
        }
    } while (day.isAfter(end) == false);
    return null;
}

From source file:org.projectforge.web.calendar.TimesheetEventsProvider.java

License:Open Source License

/**
 * @see org.projectforge.web.calendar.MyFullCalendarEventsProvider#buildEvents(org.joda.time.DateTime,
 *      org.joda.time.DateTime)//  w w  w  . ja  v a  2s . co m
 */
@Override
protected void buildEvents(final DateTime start, final DateTime end) {
    totalDuration = 0;
    for (int i = 0; i < durationsPerDayOfMonth.length; i++) {
        durationsPerDayOfMonth[i] = 0;
    }
    for (int i = 0; i < durationsPerDayOfYear.length; i++) {
        durationsPerDayOfYear[i] = 0;
    }
    final Integer userId = calFilter.getTimesheetUserId();
    if (userId == null) {
        return;
    }
    breaksMap = new HashMap<String, TimesheetDO>();
    int breaksCounter = 0;
    final TimesheetFilter filter = new TimesheetFilter();
    filter.setUserId(userId);
    filter.setStartTime(start.toDate());
    filter.setStopTime(end.toDate());
    filter.setOrderType(OrderDirection.ASC);
    timesheets = timesheetDao.getList(filter);
    boolean longFormat = false;
    days = Days.daysBetween(start, end).getDays();
    if (days < 10) {
        // Week or day view:
        longFormat = true;
        month = null;
        firstDayOfMonth = null;
    } else {
        // Month view:
        final DateTime currentMonth = new DateTime(start.plusDays(10),
                ThreadLocalUserContext.getDateTimeZone()); // Now we're definitely in the right
        // month.
        month = currentMonth.getMonthOfYear();
        firstDayOfMonth = currentMonth.withDayOfMonth(1);
    }
    if (CollectionUtils.isEmpty(timesheets) == false) {
        DateTime lastStopTime = null;
        for (final TimesheetDO timesheet : timesheets) {
            final DateTime startTime = new DateTime(timesheet.getStartTime(),
                    ThreadLocalUserContext.getDateTimeZone());
            final DateTime stopTime = new DateTime(timesheet.getStopTime(),
                    ThreadLocalUserContext.getDateTimeZone());
            if (stopTime.isBefore(start) == true || startTime.isAfter(end) == true) {
                // Time sheet doesn't match time period start - end.
                continue;
            }
            if (calFilter.isShowBreaks() == true) {
                if (lastStopTime != null && DateHelper.isSameDay(stopTime, lastStopTime) == true
                        && startTime.getMillis() - lastStopTime.getMillis() > 60000) {
                    // Show breaks between time sheets of one day (> 60s).
                    final Event breakEvent = new Event();
                    breakEvent.setEditable(false);
                    final String breakId = String.valueOf(++breaksCounter);
                    breakEvent.setClassName(Const.BREAK_EVENT_CLASS_NAME).setId(breakId).setStart(lastStopTime)
                            .setEnd(startTime).setTitle(getString("timesheet.break"));
                    breakEvent.setTextColor("#666666").setBackgroundColor("#F9F9F9").setColor("#F9F9F9");
                    events.put(breakId, breakEvent);
                    final TimesheetDO breakTimesheet = new TimesheetDO().setStartDate(lastStopTime.toDate())
                            .setStopTime(startTime.getMillis());
                    breaksMap.put(breakId, breakTimesheet);
                }
                lastStopTime = stopTime;
            }
            final long duration = timesheet.getDuration();
            final MyWicketEvent event = new MyWicketEvent();
            final String id = "" + timesheet.getId();
            event.setClassName(Const.EVENT_CLASS_NAME);
            event.setId(id);
            event.setStart(startTime);
            event.setEnd(stopTime);
            final String title = CalendarHelper.getTitle(timesheet);
            if (longFormat == true) {
                // Week or day view:
                event.setTitle(title + "\n" + getToolTip(timesheet) + "\n" + formatDuration(duration, false));
            } else {
                // Month view:
                event.setTitle(title);
            }
            if (month != null && startTime.getMonthOfYear() != month && stopTime.getMonthOfYear() != month) {
                // Display time sheets of other month as grey blue:
                event.setTextColor("#222222").setBackgroundColor("#ACD9E8").setColor("#ACD9E8");
            }
            events.put(id, event);
            if (month == null || startTime.getMonthOfYear() == month) {
                totalDuration += duration;
                addDurationOfDay(startTime.getDayOfMonth(), duration);
            }
            final int dayOfYear = startTime.getDayOfYear();
            addDurationOfDayOfYear(dayOfYear, duration);
            event.setTooltip(getString("timesheet"),
                    new String[][] { { title }, { timesheet.getLocation(), getString("timesheet.location") },
                            { KostFormatter.formatLong(timesheet.getKost2()), getString("fibu.kost2") },
                            { TaskFormatter.getTaskPath(timesheet.getTaskId(), true, OutputType.PLAIN),
                                    getString("task") },
                            { timesheet.getDescription(), getString("description") } });
        }
    }
    if (calFilter.isShowStatistics() == true) {
        // Show statistics: duration of every day is shown as all day event.
        DateTime day = start;
        final Calendar cal = DateHelper.getCalendar();
        cal.setTime(start.toDate());
        final int numberOfDaysInYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
        int paranoiaCounter = 0;
        do {
            if (++paranoiaCounter > 1000) {
                log.error(
                        "Paranoia counter exceeded! Dear developer, please have a look at the implementation of buildEvents.");
                break;
            }
            final int dayOfYear = day.getDayOfYear();
            final long duration = durationsPerDayOfYear[dayOfYear];
            final boolean firstDayOfWeek = day.getDayOfWeek() == ThreadLocalUserContext.getJodaFirstDayOfWeek();
            if (firstDayOfWeek == false && duration == 0) {
                day = day.plusDays(1);
                continue;
            }
            final Event event = new Event().setAllDay(true);
            final String id = "s-" + (dayOfYear);
            event.setId(id);
            event.setStart(day);
            final String durationString = formatDuration(duration, false);
            if (firstDayOfWeek == true) {
                // Show week of year at top of first day of week.
                long weekDuration = 0;
                for (short i = 0; i < 7; i++) {
                    int d = dayOfYear + i;
                    if (d > numberOfDaysInYear) {
                        d -= numberOfDaysInYear;
                    }
                    weekDuration += durationsPerDayOfYear[d];
                }
                final StringBuffer buf = new StringBuffer();
                buf.append(getString("calendar.weekOfYearShortLabel")).append(DateHelper.getWeekOfYear(day));
                if (days > 1 && weekDuration > 0) {
                    // Show total sum of durations over all time sheets of current week (only in week and month view).
                    buf.append(": ").append(formatDuration(weekDuration, false));
                }
                if (duration > 0) {
                    buf.append(", ").append(durationString);
                }
                event.setTitle(buf.toString());
            } else {
                event.setTitle(durationString);
            }
            event.setTextColor("#666666").setBackgroundColor("#F9F9F9").setColor("#F9F9F9");
            event.setEditable(false);
            events.put(id, event);
            day = day.plusDays(1);
        } while (day.isAfter(end) == false);
    }
}

From source file:org.projectforge.web.timesheet.TimesheetEventsProvider.java

License:Open Source License

/**
 * @see org.projectforge.web.calendar.MyFullCalendarEventsProvider#buildEvents(org.joda.time.DateTime, org.joda.time.DateTime)
 *//*from   w ww. j ava  2  s.  c o  m*/
@Override
protected void buildEvents(final DateTime start, final DateTime end) {
    totalDuration = 0;
    for (int i = 0; i < durationsPerDayOfMonth.length; i++) {
        durationsPerDayOfMonth[i] = 0;
    }
    for (int i = 0; i < durationsPerDayOfYear.length; i++) {
        durationsPerDayOfYear[i] = 0;
    }
    final Integer userId = calFilter.getTimesheetUserId();
    if (userId == null) {
        return;
    }
    breaksMap = new HashMap<String, TimesheetDO>();
    int breaksCounter = 0;
    final TimesheetFilter filter = new TimesheetFilter();
    filter.setUserId(userId);
    filter.setStartTime(start.toDate());
    filter.setStopTime(end.toDate());
    filter.setOrderType(OrderDirection.ASC);
    timesheets = timesheetDao.getList(filter);
    boolean longFormat = false;
    days = Days.daysBetween(start, end).getDays();
    if (days < 10) {
        // Week or day view:
        longFormat = true;
        month = null;
        firstDayOfMonth = null;
    } else {
        // Month view:
        final DateTime currentMonth = new DateTime(start.plusDays(10), PFUserContext.getDateTimeZone()); // Now we're definitely in the right
        // month.
        month = currentMonth.getMonthOfYear();
        firstDayOfMonth = currentMonth.withDayOfMonth(1);
    }
    if (CollectionUtils.isEmpty(timesheets) == false) {
        DateTime lastStopTime = null;
        for (final TimesheetDO timesheet : timesheets) {
            final DateTime startTime = new DateTime(timesheet.getStartTime(), PFUserContext.getDateTimeZone());
            final DateTime stopTime = new DateTime(timesheet.getStopTime(), PFUserContext.getDateTimeZone());
            if (stopTime.isBefore(start) == true || startTime.isAfter(end) == true) {
                // Time sheet doesn't match time period start - end.
                continue;
            }
            if (calFilter.isShowBreaks() == true) {
                if (lastStopTime != null && DateHelper.isSameDay(stopTime, lastStopTime) == true
                        && startTime.getMillis() - lastStopTime.getMillis() > 60000) {
                    // Show breaks between time sheets of one day (> 60s).
                    final Event breakEvent = new Event();
                    breakEvent.setEditable(false);
                    final String breakId = String.valueOf(++breaksCounter);
                    breakEvent.setClassName(BREAK_EVENT_CLASS_NAME).setId(breakId).setStart(lastStopTime)
                            .setEnd(startTime).setTitle(getString("timesheet.break"));
                    breakEvent.setTextColor("#666666").setBackgroundColor("#F9F9F9").setColor("#F9F9F9");
                    events.put(breakId, breakEvent);
                    final TimesheetDO breakTimesheet = new TimesheetDO().setStartDate(lastStopTime.toDate())
                            .setStopTime(startTime.getMillis());
                    breaksMap.put(breakId, breakTimesheet);
                }
                lastStopTime = stopTime;
            }
            final long duration = timesheet.getDuration();
            final MyEvent event = new MyEvent();
            final String id = "" + timesheet.getId();
            event.setClassName(EVENT_CLASS_NAME);
            event.setId(id);
            event.setStart(startTime);
            event.setEnd(stopTime);
            final String title = getTitle(timesheet);
            if (longFormat == true) {
                // Week or day view:
                event.setTitle(title + "\n" + getToolTip(timesheet) + "\n" + formatDuration(duration, false));
            } else {
                // Month view:
                event.setTitle(title);
            }
            if (month != null && startTime.getMonthOfYear() != month && stopTime.getMonthOfYear() != month) {
                // Display time sheets of other month as grey blue:
                event.setTextColor("#222222").setBackgroundColor("#ACD9E8").setColor("#ACD9E8");
            }
            events.put(id, event);
            if (month == null || startTime.getMonthOfYear() == month) {
                totalDuration += duration;
                addDurationOfDay(startTime.getDayOfMonth(), duration);
            }
            final int dayOfYear = startTime.getDayOfYear();
            addDurationOfDayOfYear(dayOfYear, duration);
            event.setTooltip(getString("timesheet"),
                    new String[][] { { title }, { timesheet.getLocation(), getString("timesheet.location") },
                            { KostFormatter.formatLong(timesheet.getKost2()), getString("fibu.kost2") },
                            { TaskFormatter.instance().getTaskPath(timesheet.getTaskId(), true,
                                    OutputType.PLAIN), getString("task") },
                            { timesheet.getDescription(), getString("description") } });
        }
    }
    if (calFilter.isShowStatistics() == true) {
        // Show statistics: duration of every day is shown as all day event.
        DateTime day = start;
        final Calendar cal = DateHelper.getCalendar();
        cal.setTime(start.toDate());
        final int numberOfDaysInYear = cal.getActualMaximum(Calendar.DAY_OF_YEAR);
        int paranoiaCounter = 0;
        do {
            if (++paranoiaCounter > 1000) {
                log.error(
                        "Paranoia counter exceeded! Dear developer, please have a look at the implementation of buildEvents.");
                break;
            }
            final int dayOfYear = day.getDayOfYear();
            final long duration = durationsPerDayOfYear[dayOfYear];
            final boolean firstDayOfWeek = day.getDayOfWeek() == PFUserContext.getJodaFirstDayOfWeek();
            if (firstDayOfWeek == false && duration == 0) {
                day = day.plusDays(1);
                continue;
            }
            final Event event = new Event().setAllDay(true);
            final String id = "s-" + (dayOfYear);
            event.setId(id);
            event.setStart(day);
            final String durationString = formatDuration(duration, false);
            if (firstDayOfWeek == true) {
                // Show week of year at top of first day of week.
                long weekDuration = 0;
                for (short i = 0; i < 7; i++) {
                    int d = dayOfYear + i;
                    if (d > numberOfDaysInYear) {
                        d -= numberOfDaysInYear;
                    }
                    weekDuration += durationsPerDayOfYear[d];
                }
                final StringBuffer buf = new StringBuffer();
                buf.append(getString("calendar.weekOfYearShortLabel")).append(DateHelper.getWeekOfYear(day));
                if (days > 1 && weekDuration > 0) {
                    // Show total sum of durations over all time sheets of current week (only in week and month view).
                    buf.append(": ").append(formatDuration(weekDuration, false));
                }
                if (duration > 0) {
                    buf.append(", ").append(durationString);
                }
                event.setTitle(buf.toString());
            } else {
                event.setTitle(durationString);
            }
            event.setTextColor("#666666").setBackgroundColor("#F9F9F9").setColor("#F9F9F9");
            event.setEditable(false);
            events.put(id, event);
            day = day.plusDays(1);
        } while (day.isAfter(end) == false);
    }
}

From source file:org.richfaces.fragment.calendar.DayPicker.java

License:Open Source License

public void selectDayInMonth(DateTime dateTime) {
    selectDayInMonth(dateTime.getDayOfMonth());
}

From source file:org.richfaces.tests.page.fragments.impl.calendar.common.dayPicker.RichFacesDayPicker.java

License:Open Source License

@Override
public void selectDayInMonth(DateTime dateTime) {
    selectDayInMonth(dateTime.getDayOfMonth());
}

From source file:org.rockholla.date.DateUtility.java

License:Open Source License

/**
 * Formats a datetime for use in a MySQL datetime field
 * //  w w w .j  av  a2 s .  c o  m
 * @param dateTime   the org.joda.time.DateTime value to format
 * @param offset   offset the input datetime by this amount of hours
 * @return         the formatted datetime
 */
public static String getMySqlDate(DateTime dateTime, int offset) {

    if (offset > 0 || offset < 0) {
        dateTime = dateTime.plusHours(offset);
    }

    String result = String.valueOf(dateTime.getYear()) + "-"
            + NumberUtility.format(dateTime.getMonthOfYear(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + "-"
            + NumberUtility.format(dateTime.getDayOfMonth(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + " "
            + NumberUtility.format(dateTime.getHourOfDay(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + ":"
            + NumberUtility.format(dateTime.getMinuteOfHour(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + ":"
            + NumberUtility.format(dateTime.getSecondOfMinute(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER);

    return result;

}

From source file:org.rockholla.date.DateUtility.java

License:Open Source License

/**
 * Returns a unique string based on a timestamp (DateTime must be precise to the second
 * to ensure uniqueness)// w ww  . ja  v a 2 s  .c  o  m
 * 
 * @param dateTime   the org.joda.time.DateTime to use to create the ID
 * @return         a unique string representation of the date
 */
public static String getTimestampId(DateTime dateTime) {

    String id = "";

    id = NumberUtility.format(dateTime.getYear(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER)
            + NumberUtility.format(dateTime.getMonthOfYear(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER)
            + NumberUtility.format(dateTime.getDayOfMonth(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER)
            + NumberUtility.format(dateTime.getHourOfDay(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER)
            + NumberUtility.format(dateTime.getMinuteOfHour(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER)
            + NumberUtility.format(dateTime.getSecondOfMinute(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER)
            + NumberUtility.format(dateTime.getMillisOfSecond(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER);

    return id;

}