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:com.inkubator.common.util.DateTimeUtil.java

/**
 * get total SaturDay and Monday between two date
 *
 * @param startDate Date reference//www.  j a v  a 2 s. c  om
 * @return Integer
 * @param endDate Date reference
 * @throws java.lang.Exception
 */
public static Integer getTotalSaturdayAndMonday(Date startDate, Date endDate) throws Exception {
    if (startDate.after(endDate)) {
        throw new Exception("Mr. DHFR say :End Date must be newer than Start Date");
    } else {
        DateTime start = new DateTime(startDate);
        DateTime end = new DateTime(endDate);
        int totalSaturdayAndMonday = 0;
        DateTime iterate = start;
        while (iterate.isBefore(end) | iterate.isEqual(end)) {
            if (iterate.getDayOfWeek() == 6 | iterate.getDayOfWeek() == 7) {
                ++totalSaturdayAndMonday;
            }
            iterate = iterate.plusDays(1);
        }
        return totalSaturdayAndMonday;
    }
}

From source file:com.inspireon.dragonfly.common.logging.ExtendedDailyRollingFileAppender.java

License:Apache License

/**
 * This method checks to see if we're exceeding the number of log backups that we are supposed to keep, and if so,
 * deletes the offending files. It then delegates to the rollover method to rollover to a new file if required.
 *///from   www. ja va  2 s .  c o m
protected void cleanupAndRollOver() throws IOException {
    // Check to see if there are already 5 files
    File file = new File(fileName);
    //        Calendar cal = Calendar.getInstance();
    //        cal.add(Calendar.DATE, -getMaxDays());

    DateTime dateTime = new DateTime();
    dateTime = dateTime.plusDays(-getMaxDays());

    //        Date cutoffDate = cal.getTime();
    Date cutoffDate = dateTime.toDate();

    if (file.getParentFile().exists()) {
        File[] files = file.getParentFile().listFiles(new StartsWithFileFilter(file.getName(), false));
        int nameLength = file.getName().length();

        for (int i = 0; i < files.length; i++) {
            String datePart = null;

            try {
                // The datePart is appended to the end, so everything that
                // is not the fixed name part is the DF.
                datePart = files[i].getName().substring(nameLength);

                Date date = datePatternFormat.parse(datePart);

                if (date.before(cutoffDate)) {
                    files[i].delete();
                }
                // If we're supposed to zip files and this isn't already a
                // zip
                else if (shouldCompress()) {
                    zipAndDelete(files[i]);
                }
            } catch (Exception pe) {
                // This isn't a file we should touch (it isn't named
                // correctly)
            }
        }
    }

    rollOver();
}

From source file:com.intuit.wasabi.tests.service.IntegrationPages.java

License:Apache License

/**
 * Returns date n days later in UTC timezone as string
 *
 * @return string//from www  .j a va2s.co m
 */
private String getDatePlusDays(int days) {
    DateTime dt = new DateTime();
    dt = dt.plusDays(days);
    final DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
    sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
    return sdf.format(dt.toDate());
}

From source file:com.jay.pea.mhealthapp2.model.MedicationManager.java

License:Open Source License

/**
 * Method to build the first dose map which holds the dose due time and the dose taken time.
 * If not taken the dose taken time is recorded as epoch 01-01-70.
 *
 * @param med/*from www.  j  a va 2 s .  c  o m*/
 * @param context
 * @return
 */
public HashMap<DateTime, DateTime> buildDoseMap1(Medication med, Context context) {
    //get a db object
    dbOpenHelper = new MedDBOpenHelper(context);

    //get final med
    final Medication medication = med;

    //hash map to map doses to taken bool
    HashMap<DateTime, DateTime> doseMap1 = new HashMap();

    //get existing hashMap details if exist
    doseMap1 = dbOpenHelper.getDoseMaps(medication)[0];

    //erase all future dose data, retain past data

    //get inclusive start and end date
    DateTime startDate = new DateTime(med.getMedStart() * 1000l);
    DateTime endDate = new DateTime(med.getMedEnd() * 1000l);

    //set hashStart date as today
    DateTime hashStart = today;

    //if medication is in future set hashStart to future date, if med start is in the past, set hashStart to today (for update to HashMap)
    if (hashStart.isBefore(startDate))
        hashStart = startDate;

    //get alarm times
    DateTime alert1 = new DateTime(med.getAlert1() * 1000l);
    DateTime alert2 = new DateTime(med.getAlert2() * 1000l);
    DateTime alert3 = new DateTime(med.getAlert3() * 1000l);
    DateTime alert4 = new DateTime(med.getAlert4() * 1000l);
    DateTime alert5 = new DateTime(med.getAlert5() * 1000l);
    DateTime alert6 = new DateTime(med.getAlert6() * 1000l);

    DateTime[] dtArray = new DateTime[] { alert1, alert2, alert3, alert4, alert5, alert6 };

    //get the number of days of med prescription
    int days = Days.daysBetween(hashStart.toLocalDate(), endDate.toLocalDate()).getDays() + 1;

    //get Frequency for alerts to ignore non required alerts.
    int freq = med.getFreq();

    //build the hashmap for daily dose due dates and bool for taken, if in the past exclude the reminder
    for (int i = 0; i < days; i++) {
        DateTime thisDay = hashStart.plusDays(i);
        //for the freq setup all alerts
        for (int j = 0; j < freq; j++) {
            DateTime alertTime = thisDay.withHourOfDay(dtArray[j].getHourOfDay())
                    .withMinuteOfHour(dtArray[j].getMinuteOfHour()).withSecondOfMinute(0);
            final DateTime zeroDate = new DateTime(0);
            doseMap1.put(alertTime, zeroDate);
            Log.d(TAG, alertTime + " Time" + dtArray[j].getHourOfDay() + " zero date  " + zeroDate);
        }

    }
    //get existing hashMap details if exist
    HashMap<DateTime, DateTime> tempDoseMap1 = dbOpenHelper.getDoseMaps(medication)[0];

    //add all past dose data,
    if (!tempDoseMap1.isEmpty()) {
        for (DateTime dateTime : tempDoseMap1.keySet()) {

            if (dateTime.isBefore(today)) {
                doseMap1.put(dateTime, tempDoseMap1.get(dateTime));
            }
        }
    }
    Log.d(TAG, doseMap1.size() + " doseMap1 size");
    return doseMap1;
}

From source file:com.jay.pea.mhealthapp2.model.MedicationManager.java

License:Open Source License

/**
 * Method to build the second dose map which holds the dose due time and an int for if an alert
 * has been set.//from ww  w.j  a  v a2  s.c  o  m
 *
 * @param med
 * @param context
 * @return
 */
public HashMap<DateTime, Integer> buildDoseMap2(Medication med, Context context) {

    //get a db object
    dbOpenHelper = new MedDBOpenHelper(context);

    //get final med
    final Medication medication = med;

    //hash map to map doses to taken bool
    HashMap<DateTime, Integer> doseMap2 = new HashMap();

    //set hashStart date as today
    DateTime hashStart = today;

    //get inclusive start and end date
    DateTime startDate = new DateTime(med.getMedStart() * 1000l);
    DateTime endDate = new DateTime(med.getMedEnd() * 1000l);

    //if medication is in future set hashStart to future date, if med start is in the past, set hashStart to today (for update to HashMap)
    if (hashStart.isBefore(startDate))
        hashStart = startDate;

    //get alarm times
    DateTime alert1 = new DateTime(med.getAlert1() * 1000l);
    DateTime alert2 = new DateTime(med.getAlert2() * 1000l);
    DateTime alert3 = new DateTime(med.getAlert3() * 1000l);
    DateTime alert4 = new DateTime(med.getAlert4() * 1000l);
    DateTime alert5 = new DateTime(med.getAlert5() * 1000l);
    DateTime alert6 = new DateTime(med.getAlert6() * 1000l);

    DateTime[] dtArray = new DateTime[] { alert1, alert2, alert3, alert4, alert5, alert6 };
    Log.d(TAG, Arrays.toString(dtArray));

    //get the number of days of med prescription
    int days = Days.daysBetween(hashStart.toLocalDate(), endDate.toLocalDate()).getDays() + 1;

    //get Frequency for alerts to ignore non required alerts.
    int freq = med.getFreq();
    Log.d(TAG, freq + " Days =" + days + " " + med.getMedName());

    //build the hashmap for daily dose due dates and alertsOn Integer, if in the past exclude the reminder
    for (int i = 0; i < days; i++) {
        DateTime thisDay = hashStart.plusDays(i);

        //for the freq setup all alertsOn
        for (int j = 0; j < freq; j++) {
            DateTime alertTime = thisDay.withHourOfDay(dtArray[j].getHourOfDay())
                    .withMinuteOfHour(dtArray[j].getMinuteOfHour()).withSecondOfMinute(0);
            if (alertTime.isAfter(today))
                doseMap2.put(alertTime, medication.getAlertsOn());

        }
        Log.d(TAG, doseMap2.size() + " doseMap2 size");

    }

    //get existing hashMap details if exist
    HashMap<DateTime, Integer> tempDoseMap2 = dbOpenHelper.getDoseMaps(medication)[1];

    //add all past dose data,
    if (!tempDoseMap2.isEmpty()) {
        for (DateTime dateTime : tempDoseMap2.keySet()) {

            if (dateTime.isBefore(today)) {
                doseMap2.put(dateTime, tempDoseMap2.get(dateTime));
            }
        }
    }
    Log.d(TAG, doseMap2.size() + " doseMap2 size");
    return doseMap2;
}

From source file:com.jgoetsch.tradeframework.marketdata.HistoricalMarketDataFeed.java

License:Apache License

/**
 * Overridable method to adjust a timestamp to the next regular trading session
 * of the given contract if it falls outside of the contract's regular trading hours.
 * /*from   w w  w . j  av  a 2s  . c om*/
 * @param timestamp
 * @param contract
 * @return millisecond timestamp adjusted up to a regular trading session.
 */
protected long adjustTimestampToRTH(long timestamp, Contract contract) {
    if ("STK".equals(contract.getType()) && "USD".equals(contract.getCurrency())) {
        DateTime dt = new DateTime(timestamp, DateTimeZone.forID("America/New_York"));
        LocalTime time = new LocalTime(dt);
        if (time.compareTo(new LocalTime(9, 30)) < 0)
            dt = dt.withHourOfDay(9).withMinuteOfHour(30);
        else if (time.compareTo(new LocalTime(16, 0)) >= 0) {
            dt = dt.plusDays(1).withHourOfDay(9).withMinuteOfHour(30);
        }
        if (dt.getDayOfWeek() == DateTimeConstants.SATURDAY)
            dt = dt.plusDays(2);
        else if (dt.getDayOfWeek() == DateTimeConstants.SUNDAY)
            dt = dt.plusDays(1);
        return dt.getMillis();
    } else if ("FUT".equals(contract.getType()) && "USD".equals(contract.getCurrency())) {
        DateTime dt = new DateTime(timestamp, DateTimeZone.forID("America/Chicago"));
        if (dt.getDayOfWeek() == DateTimeConstants.SATURDAY)
            dt = dt.plusDays(2).withHourOfDay(9).withMinuteOfHour(0);
        else if (dt.getDayOfWeek() == DateTimeConstants.SUNDAY)
            dt = dt.plusDays(1).withHourOfDay(9).withMinuteOfHour(0);
        return dt.getMillis();
    } else
        return timestamp;
}

From source file:com.jk.examples.dropwizard.beans.UserVisitLog.java

License:Apache License

/**
 * This method checks if this visit is expired . The Page is considered
 * expired if its recorded for more than {VisitListMaxDays} variable which
 * is defined in AssignmentConfigurations#getVisitListMaxDays() method
 *
 * @return wheather outdated or not/* ww w .j  a  v  a 2 s .  c  o  m*/
 */
public boolean isOutDated() {
    final DateTime timeStamp = new DateTime(getTimeStamp());
    final DateTime expiryDate = timeStamp.plusDays(LocalRegistry.getConfigurations().getVisitListMaxDays());

    final DateTime now = new DateTime();
    return now.isAfter(expiryDate);
}

From source file:com.kopysoft.chronos.activities.Editors.NewPunchActivity.java

License:Open Source License

private void updateDatabase() {
    int hour, min;
    TimePicker inTime = (TimePicker) findViewById(R.id.TimePicker1);
    Spinner taskSpinnerIn = (Spinner) findViewById(R.id.taskSpinnerIn);
    inTime.clearFocus();/*from   www. jav  a 2  s.  c  om*/
    hour = inTime.getCurrentHour();
    min = inTime.getCurrentMinute();

    Task inTask = tasks.get(taskSpinnerIn.getSelectedItemPosition());

    DateTime date1 = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), hour, min);

    Chronos chrono = new Chronos(this);
    Job thisJob = null;
    List<Job> jobs = chrono.getAllJobs();
    for (Job job : jobs) {
        if (job.getID() == jobID)
            thisJob = job;
    }

    DateTime startOfPP = thisJob.getStartOfPayPeriod();
    if (startOfPP.getSecondOfDay() > date1.getSecondOfDay()) {
        date1 = date1.plusDays(1);
        Log.d(TAG, "Pay Period start " + startOfPP);
        Log.d(TAG, "insert date " + date1);
        Log.d(TAG, "Start Second of Day: " + startOfPP.getSecondOfDay());
        Log.d(TAG, "This Second of Day: " + date1.getSecondOfDay());
    }
    Punch newPunch = new Punch(thisJob, inTask, date1);
    if (enableLog)
        Log.d(TAG, "Date Time: " + newPunch.getTime().getMillis());
    Log.d(TAG, "Date Time: " + newPunch.getTime());

    chrono.insertPunch(newPunch);
    chrono.close();
    //int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour

}

From source file:com.kopysoft.chronos.activities.Editors.PairEditorActivity.java

License:Open Source License

private void updateDatabase() {
    int hour, min;
    TimePicker inTime = (TimePicker) findViewById(R.id.TimePicker1);
    Spinner taskSpinnerIn = (Spinner) findViewById(R.id.taskSpinnerIn);
    inTime.clearFocus();//from   w ww. j  a v a 2s . c o m
    hour = inTime.getCurrentHour();
    min = inTime.getCurrentMinute();

    Task inTask = tasks.get(taskSpinnerIn.getSelectedItemPosition());

    DateTime date1 = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), hour, min);

    Chronos chrono = new Chronos(this);
    Job thisJob = chrono.getAllJobs().get(0);

    DateTime startOfPP = thisJob.getStartOfPayPeriod();
    if (startOfPP.getSecondOfDay() > date1.getSecondOfDay()) {
        date1 = date1.plusDays(1);
        Log.d(TAG, "Moved Date1 foward one day");
    }

    Log.d(TAG, "Date1: " + date1);

    p1.setTime(date1);
    p1.setTask(inTask);
    chrono.updatePunch(p1);
    //int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour

    if (p2 != null) {
        TimePicker outTime = (TimePicker) findViewById(R.id.TimePicker2);
        Spinner taskSpinnerOut = (Spinner) findViewById(R.id.taskSpinnerOut);
        outTime.clearFocus();
        hour = outTime.getCurrentHour();
        min = outTime.getCurrentMinute();

        Task outTask = tasks.get(taskSpinnerOut.getSelectedItemPosition());

        DateTime date2 = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), hour, min);

        if (startOfPP.getSecondOfDay() > date2.getSecondOfDay()) {
            date2 = date2.plusDays(1);
            Log.d(TAG, "Moved Date2 foward one day");
        }

        Log.d(TAG, "Date2: " + date2);

        p2.setTime(date2);
        p2.setTask(outTask);
        chrono.updatePunch(p2);
    }
    chrono.close();
}

From source file:com.kopysoft.chronos.activities.QuickBreakActivity.java

License:Open Source License

private void updateDatabase() {
    int hour, min;
    TimePicker inTime = (TimePicker) findViewById(R.id.timePicker);
    Spinner timeSpinner = (Spinner) findViewById(R.id.timeSpinner);
    Spinner taskSpinner = (Spinner) findViewById(R.id.spinner);
    inTime.clearFocus();/*from w  ww. jav  a  2 s. c  om*/
    hour = inTime.getCurrentHour();
    min = inTime.getCurrentMinute();

    Task inTask = tasks.get(taskSpinner.getSelectedItemPosition());

    DateTime date1 = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), hour, min);

    Chronos chrono = new Chronos(this);
    Job thisJob = chrono.getAllJobs().get(0);

    DateTime startOfPP = thisJob.getStartOfPayPeriod();
    if (startOfPP.getSecondOfDay() > date1.getSecondOfDay()) {
        date1 = date1.plusDays(1);
    }
    Punch startPunch = new Punch(thisJob, inTask, date1);

    DateTime endDate;
    switch (timeSpinner.getSelectedItemPosition()) {
    case (0):
        endDate = date1.plusMinutes(5);
        break;
    case (1):
        endDate = date1.plusMinutes(10);
        break;
    case (2):
        endDate = date1.plusMinutes(15);
        break;
    case (3):
        endDate = date1.plusMinutes(30);
        break;
    case (4):
        endDate = date1.plusMinutes(45);
        break;
    case (5):
        endDate = date1.plusMinutes(60);
        break;
    default:
        endDate = date1.plusMinutes(1);
    }
    Punch endPunch = new Punch(thisJob, inTask, endDate);
    if (enableLog)
        Log.d(TAG, "Date Time: " + startPunch.getTime().getMillis());

    Log.d(TAG, "Start Punch" + startPunch.getTime());
    Log.d(TAG, "End Punch" + endPunch.getTime());

    chrono.insertPunch(startPunch);
    chrono.insertPunch(endPunch);
    chrono.close();
    //int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour

}