Example usage for org.joda.time DateTime plusDays

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

Introduction

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

Prototype

public DateTime plusDays(int days) 

Source Link

Document

Returns a copy of this datetime plus the specified number of days.

Usage

From source file:org.mifos.test.acceptance.framework.loan.ViewInstallmentDetailsPage.java

License:Open Source License

private void validateInvalidDateFormat(int noOfInstallments, DateTime disbursalDate, String dateFormat,
        int minGap) {
    DateTime nextInstallment = disbursalDate;
    for (int installment = 0; installment < noOfInstallments; installment++) {
        nextInstallment = nextInstallment.plusDays(minGap);
        setInstallmentDate(String.valueOf(installment),
                DateTimeFormat.forPattern(dateFormat).print(nextInstallment));
    }//from w w  w .  ja v  a  2  s .c  o  m
    clickValidateAndWaitForPageToLoad();
    for (int installment = 0; installment < noOfInstallments; installment++) {
        // Assert.assertTrue(selenium.isTextPresent("Installment " + (installment+1) +" has an invalid due date. An example due date is 23-Apr-2010"));
    }
}

From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisNotificationsDao.java

License:Open Source License

@Override
public List<Notification> getNotificationsByMessageDate(final DateTime messageDate) {
    final Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("start_date", messageDate.toDate());
    parameters.put("end_date", messageDate.plusDays(1).toDate());
    return getNotifications(namespace + "getNotificationsByMessageDate", parameters);
}

From source file:org.mobicents.servlet.sip.restcomm.dao.mongodb.MongoCallDetailRecordsDao.java

License:Open Source License

@Override
public List<CallDetailRecord> getCallDetailRecordsByStartTime(final DateTime startTime) {
    final BasicDBObject query = new BasicDBObject();
    final BasicDBObject startQuery = new BasicDBObject();
    startQuery.put("$gte", startTime.toDate());
    query.put("start_time", startQuery);
    final DateTime endTime = startTime.plusDays(1);
    final BasicDBObject endQuery = new BasicDBObject();
    endQuery.put("$lt", endTime.toDate());
    query.put("start_time", endQuery);
    return getCallDetailRecords(query);
}

From source file:org.mulgara.util.LexicalDateTime.java

License:Apache License

/**
 * Parse a dateTime string. It <strong>must</strong> be of the form:
 * ('-')? yyyy '-' MM '-' dd 'T' hh ':' mm ':' ss ( '.' s+ )? ( ( ('+'|'-')? hh ':' mm ) | 'Z' )?
 * @param dt The dateTime string to parse.
 * @return a new LexcalDateTime value.//from w w w  .j  a v a2  s. c o  m
 * @throws ParseException If a character that doesn't match the above pattern is discovered.
 */
public static LexicalDateTime parseDateTime(String dt) throws ParseException {
    int pos = 0;
    try {
        boolean negative = dt.charAt(pos) == '-';
        if (negative)
            pos++;
        int year = d(dt, pos++) * 1000 + d(dt, pos++) * 100 + d(dt, pos++) * 10 + d(dt, pos++);
        while (dt.charAt(pos) != DATE_SEPARATOR)
            year = year * 10 + d(dt, pos++);
        if (negative)
            year = -year;
        if (dt.charAt(pos++) != DATE_SEPARATOR)
            throw new ParseException(BAD_FORMAT + "date: " + dt, pos - 1);
        int month = d(dt, pos++) * 10 + d(dt, pos++);
        if (dt.charAt(pos++) != DATE_SEPARATOR)
            throw new ParseException(BAD_FORMAT + "date: " + dt, pos - 1);
        int day = d(dt, pos++) * 10 + d(dt, pos++);

        if (dt.charAt(pos++) != DATE_TIME_SEPARATOR)
            throw new ParseException(BAD_FORMAT + "date/time: " + dt, pos - 1);

        int hour = d(dt, pos++) * 10 + d(dt, pos++);
        if (dt.charAt(pos++) != TIME_SEPARATOR)
            throw new ParseException(BAD_FORMAT + "time: " + dt, pos - 1);
        int minute = d(dt, pos++) * 10 + d(dt, pos++);
        if (dt.charAt(pos++) != TIME_SEPARATOR)
            throw new ParseException(BAD_FORMAT + "time: " + dt, pos - 1);
        int second = d(dt, pos++) * 10 + d(dt, pos++);

        int millisecs = 0;
        byte milliPlaces = 0;
        int lastPos = dt.length() - 1;
        if (pos < lastPos) {
            if (dt.charAt(pos) == MILLI_SEPARATOR) {
                int place = MILLIS / 10;
                int digit;
                while (isDecimal((digit = dt.charAt(++pos) - '0'))) {
                    millisecs += digit * place;
                    if (milliPlaces++ > 3)
                        throw new ParseException(BAD_FORMAT + "milliseconds: " + dt, pos);
                    place /= 10;
                    if (pos == lastPos) {
                        pos++;
                        break;
                    }
                }
            }
        }

        boolean midnightFlag = false;
        if (hour == MIDNIGHT) {
            midnightFlag = true;
            hour = 0;
        }
        if (midnightFlag && (minute > 0 || second > 0 || millisecs > 0))
            throw new ParseException(BAD_FORMAT + "time: " + dt, pos);

        boolean local = false;
        int tzHour = 0;
        int tzMinute = 0;
        boolean zuluFlag = false;
        DateTimeZone timezone = null;
        if (pos <= lastPos) {
            char tz = dt.charAt(pos++);
            if (tz == ZULU) {
                if (pos != lastPos + 1)
                    throw new ParseException(BAD_FORMAT + "timezone: " + dt, pos);
                timezone = UTC;
                zuluFlag = true;
            } else {
                if (pos != lastPos - 4 || (tz != NEG_TZ && tz != POS_TZ))
                    throw new ParseException(BAD_FORMAT + "timezone: " + dt, pos);
                tzHour = d(dt, pos++) * 10 + d(dt, pos++);
                if (dt.charAt(pos++) != TIME_SEPARATOR)
                    throw new ParseException(BAD_FORMAT + "timezone: " + dt, pos - 1);
                tzMinute = d(dt, pos++) * 10 + d(dt, pos++);
                if (tz == NEG_TZ)
                    tzHour = -tzHour;
                timezone = DateTimeZone.forOffsetHoursMinutes(tzHour, tzMinute);
            }
        } else {
            local = true;
        }

        DateTime dateTime = new DateTime(year, month, day, hour, minute, second, millisecs, timezone);
        if (midnightFlag)
            dateTime = dateTime.plusDays(1);
        return new LexicalDateTime(dateTime, tzHour, tzMinute, midnightFlag, milliPlaces, local, zuluFlag);
    } catch (StringIndexOutOfBoundsException e) {
        throw new IllegalArgumentException(BAD_FORMAT + "date: " + dt);
    }
}

From source file:org.mythtv.client.ui.dvr.GuideDataFragment.java

License:Open Source License

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Log.v(TAG, "onCreateLoader : enter");

    String[] projection = null;/*  w ww.ja v a  2 s .  c  o m*/
    String selection = null;
    String[] selectionArgs = null;
    String sortOrder = null;

    switch (id) {
    case 0:
        Log.v(TAG, "onCreateLoader : getting prorgrams for channel");

        int channelId = args.getInt(ProgramConstants.FIELD_CHANNEL_ID);
        long date = args.getLong(ProgramConstants.FIELD_END_TIME);

        DateTime start = new DateTime(date).withTimeAtStartOfDay();
        DateTime end = start.plusDays(1);
        Log.v(TAG, "onCreateLoader : getting prorgrams for channel " + channelId + " on " + start.toString()
                + " until " + end.toString());

        start = start.withZone(DateTimeZone.UTC);
        end = end.withZone(DateTimeZone.UTC);

        projection = new String[] { ProgramConstants._ID,
                ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_TITLE,
                ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_SUB_TITLE,
                ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_CATEGORY,
                ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_START_TIME,
                ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_END_TIME,
                ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_RECORD_ID,
                RecordingConstants.ContentDetails.GUIDE + "_" + RecordingConstants.FIELD_RECORD_ID,
                RecordingConstants.ContentDetails.GUIDE + "_" + RecordingConstants.FIELD_STATUS };
        selection = ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_CHANNEL_ID + " = ? AND "
                + ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_END_TIME + " > ? AND "
                + ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_START_TIME + " < ? AND "
                + ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_MASTER_HOSTNAME + " = ?";
        selectionArgs = new String[] { String.valueOf(channelId), String.valueOf(start.getMillis()),
                String.valueOf(end.getMillis()), mLocationProfile.getHostname() };
        sortOrder = ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_START_TIME;

        Log.v(TAG, "onCreateLoader : exit");
        return new CursorLoader(getActivity(), ProgramConstants.CONTENT_URI_GUIDE, projection, selection,
                selectionArgs, sortOrder);

    default:
        Log.v(TAG, "onCreateLoader : exit, invalid id");

        return null;
    }

}

From source file:org.mythtv.client.ui.dvr.GuideDatePickerFragment.java

License:Open Source License

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Log.v(TAG, "onCreate : enter");

    if (null == listener) {
        throw new IllegalArgumentException("OnDialogResultListener is required!");
    }//w  ww  . j ava  2  s .c  o  m

    Bundle args = getArguments();
    selectedDate = new DateTime(args.getLong("selectedDate"));
    downloadDays = args.getInt("downloadDays");
    Log.v(TAG, "onCreate : selectedDate=" + selectedDate.toString() + ", downloadDays=" + downloadDays);

    // Create a new instance of DatePickerDialog and return it
    DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), this, selectedDate.getYear(),
            selectedDate.getMonthOfYear() - 1, selectedDate.getDayOfMonth());

    if (null != datePickerDialog.getDatePicker()) {
        DateTime today = new DateTime().withTimeAtStartOfDay();
        Log.v(TAG, "onCreate : today=" + today.toString());
        //         datePickerDialog.getDatePicker().setMinDate( today.getMillis() );
        Log.v(TAG, "onCreate : today+downloadDays=" + today.plusDays(downloadDays).toString());
        //         datePickerDialog.getDatePicker().setMaxDate( today.plusDays( downloadDays ).getMillis() );
    }

    Log.v(TAG, "onCreate : exit");
    return datePickerDialog;
}

From source file:org.mythtv.client.ui.dvr.UpcomingFragment.java

License:Open Source License

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Log.v(TAG, "onCreateLoader : enter");

    String startDate = args.getString(START_DATE_KEY);
    Log.v(TAG, "onCreateLoader : startDate=" + startDate);

    DateTime startDay = new DateTime(startDate).withTimeAtStartOfDay();
    DateTime endDay = startDay.plusDays(1);
    DateTime now = new DateTime(System.currentTimeMillis());

    //mainApplication = getMainApplication();

    LocationProfile locationProfile = mLocationProfileDaoHelper.findConnectedProfile(getActivity());
    Log.v(TAG, "onCreateLoader : loading upcoming for profile " + locationProfile.getHostname() + " ["
            + locationProfile.getUrl() + "]");

    String[] projection = { ProgramConstants._ID, ProgramConstants.FIELD_TITLE,
            ProgramConstants.FIELD_SUB_TITLE, ProgramConstants.FIELD_START_TIME,
            ProgramConstants.FIELD_CATEGORY };

    String selection = ProgramConstants.TABLE_NAME_UPCOMING + "." + ProgramConstants.FIELD_START_TIME
            + " >= ? AND " + ProgramConstants.TABLE_NAME_UPCOMING + "." + ProgramConstants.FIELD_START_TIME
            + " < ? AND " + ProgramConstants.TABLE_NAME_UPCOMING + "." + ProgramConstants.FIELD_START_TIME
            + " >= ? AND " + ProgramConstants.TABLE_NAME_UPCOMING + "." + ProgramConstants.FIELD_MASTER_HOSTNAME
            + " = ?";

    String[] selectionArgs = new String[] { String.valueOf(startDay.getMillis()),
            String.valueOf(endDay.getMillis()), String.valueOf(now.getMillis()),
            locationProfile.getHostname() };

    CursorLoader cursorLoader = new CursorLoader(getActivity(), ProgramConstants.CONTENT_URI_UPCOMING,
            projection, selection, selectionArgs,
            ProgramConstants.TABLE_NAME_UPCOMING + "." + ProgramConstants.FIELD_START_TIME);

    Log.v(TAG, "onCreateLoader : exit");
    return cursorLoader;
}

From source file:org.mythtv.db.dvr.ProgramGuideDaoHelper.java

License:Open Source License

public List<Program> findAll(final Context context, final LocationProfile locationProfile, int channelId,
        DateTime date) {//from   w ww  .java 2s.  c om
    //      Log.d( TAG, "findAll : enter" );

    DateTime start = date.withZone(DateTimeZone.UTC);

    String[] projection = new String[] { ProgramConstants._ID, ProgramConstants.FIELD_TITLE,
            ProgramConstants.FIELD_SUB_TITLE, ProgramConstants.FIELD_CATEGORY,
            ProgramConstants.FIELD_START_TIME, ProgramConstants.FIELD_END_TIME };
    String selection = ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_CHANNEL_ID + " = ? AND "
            + ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_END_TIME + " >= ? AND "
            + ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_START_TIME + " < ?";
    String[] selectionArgs = new String[] { String.valueOf(channelId), String.valueOf(start.getMillis()),
            String.valueOf(start.plusDays(1).getMillis()) };
    String sortOrder = ProgramConstants.TABLE_NAME_GUIDE + "." + ProgramConstants.FIELD_START_TIME;

    selection = appendLocationHostname(context, locationProfile, selection, ProgramConstants.TABLE_NAME_GUIDE);

    //      for( String p : projection ) {
    //         Log.v( TAG, "projection=" + p );
    //      }
    //      Log.v( TAG, "selection=" + selection );
    //      for( String arg : selectionArgs ) {
    //         Log.v( TAG, "arg=" + arg );
    //      }
    //      Log.v( TAG, "sortOrder=" + sortOrder );

    List<Program> programs = findAll(context, ProgramConstants.CONTENT_URI_GUIDE, projection, selection,
            selectionArgs, sortOrder, ProgramConstants.TABLE_NAME_GUIDE);

    //      Log.d( TAG, "findAll : exit" );
    return programs;
}

From source file:org.n52.iceland.util.DateTimeHelper.java

License:Open Source License

/**
 * Set the time object to the end values (seconds, minutes, hours, days,..)
 * if the time Object has not all values
 *
 * @param dateTime/*from   w  w  w  .  j  a v a 2 s . c om*/
 *            Time object
 * @param isoTimeLength
 *            Length of the time object
 * @return Modified time object.
 */
public static DateTime setDateTime2EndOfMostPreciseUnit4RequestedEndPosition(final DateTime dateTime,
        final int isoTimeLength) {
    switch (isoTimeLength) {
    // year
    case YEAR:
        return dateTime.plusYears(ONE_VALUE).minusMillis(ONE_VALUE);
    // year, month
    case YEAR_MONTH:
        return dateTime.plusMonths(ONE_VALUE).minusMillis(ONE_VALUE);
    // year, month, day
    case YEAR_MONTH_DAY:
        return dateTime.plusDays(ONE_VALUE).minusMillis(ONE_VALUE);
    // year, month, day, hour
    case YEAR_MONTH_DAY_HOUR:
        return dateTime.plusHours(ONE_VALUE).minusMillis(ONE_VALUE);
    // year, month, day, hour, minute
    case YEAR_MONTH_DAY_HOUR_MINUTE:
        return dateTime.plusMinutes(ONE_VALUE).minusMillis(ONE_VALUE);
    // year, month, day, hour, minute, second
    case YEAR_MONTH_DAY_HOUR_MINUTE_SECOND:
        return dateTime.plusSeconds(ONE_VALUE).minusMillis(ONE_VALUE);
    default:
        return dateTime;
    }
}

From source file:org.n52.shetland.util.DateTimeHelper.java

License:Apache License

/**
 * Set the time object to the end values (seconds, minutes, hours, days,..)
 * if the time Object has not all values
 *
 * @param dateTime/*from   w w w  .j a  v  a  2 s .  c o  m*/
 *            Time object
 * @param isoTimeLength
 *            Length of the time object
 * @return Modified time object.
 */
public static DateTime setDateTime2EndOfMostPreciseUnit4RequestedEndPosition(DateTime dateTime,
        int isoTimeLength) {
    switch (isoTimeLength) {
    case YEAR:
        return dateTime.plusYears(1).minusMillis(1);
    case YEAR_MONTH:
        return dateTime.plusMonths(1).minusMillis(1);
    case YEAR_MONTH_DAY:
        return dateTime.plusDays(1).minusMillis(1);
    case YEAR_MONTH_DAY_HOUR:
        return dateTime.plusHours(1).minusMillis(1);
    case YEAR_MONTH_DAY_HOUR_MINUTE:
        return dateTime.plusMinutes(1).minusMillis(1);
    case YEAR_MONTH_DAY_HOUR_MINUTE_SECOND:
        return dateTime.plusSeconds(1).minusMillis(1);
    default:
        return dateTime;
    }
}