Example usage for org.joda.time DateTime toMutableDateTime

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

Introduction

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

Prototype

MutableDateTime toMutableDateTime();

Source Link

Document

Get this object as a MutableDateTime, always returning a new instance.

Usage

From source file:DDTDate.java

License:Apache License

public MutableDateTime getReferenceDateAdjustedForTimeZone() {
    DateTime result = getReferenceDate().toDateTime();
    int timeZoneAdjustmentInHours = DDTSettings.Settings().getTimeZoneAdjustmentInHours();
    result = result.plusHours(timeZoneAdjustmentInHours);
    return result.toMutableDateTime();
}

From source file:com.alliander.osgp.adapter.protocol.oslp.elster.application.mapping.OslpGetConfigurationResponseToConfigurationConverter.java

License:Open Source License

/**
 * For a given Month of this year, find the date for the weekday {@link day}
 * ./*from   w ww  .  ja va 2s.co  m*/
 */
private int getLastDayOfMonth(final int month, final int day) {
    final DateTime dateTime = DateTime.now();
    MutableDateTime x = dateTime.toMutableDateTime();
    x.set(DateTimeFieldType.monthOfYear(), month);
    x.set(DateTimeFieldType.dayOfMonth(), 31);

    x = this.findLastDayOfOfMonth(day, x);
    return x.getDayOfMonth();
}

From source file:com.google.gerrit.server.config.ScheduleConfig.java

License:Apache License

private static long initialDelay(Config rc, String section, String subsection, String keyStartTime,
        DateTime now, long interval) {
    long delay = MISSING_CONFIG;
    String start = rc.getString(section, subsection, keyStartTime);
    try {/*from www.  j  a  va  2 s.  c  o m*/
        if (start != null) {
            DateTimeFormatter formatter;
            MutableDateTime startTime = now.toMutableDateTime();
            try {
                formatter = ISODateTimeFormat.hourMinute();
                LocalTime firstStartTime = formatter.parseLocalTime(start);
                startTime.hourOfDay().set(firstStartTime.getHourOfDay());
                startTime.minuteOfHour().set(firstStartTime.getMinuteOfHour());
            } catch (IllegalArgumentException e1) {
                formatter = DateTimeFormat.forPattern("E HH:mm").withLocale(Locale.US);
                LocalDateTime firstStartDateTime = formatter.parseLocalDateTime(start);
                startTime.dayOfWeek().set(firstStartDateTime.getDayOfWeek());
                startTime.hourOfDay().set(firstStartDateTime.getHourOfDay());
                startTime.minuteOfHour().set(firstStartDateTime.getMinuteOfHour());
            }
            startTime.secondOfMinute().set(0);
            startTime.millisOfSecond().set(0);
            long s = startTime.getMillis();
            long n = now.getMillis();
            delay = (s - n) % interval;
            if (delay <= 0) {
                delay += interval;
            }
        } else {
            log.info(MessageFormat.format("{0} schedule parameter \"{0}.{1}\" is not configured", section,
                    keyStartTime));
        }
    } catch (IllegalArgumentException e2) {
        log.error(MessageFormat.format("Invalid {0} schedule parameter \"{0}.{1}\"", section, keyStartTime),
                e2);
        delay = INVALID_CONFIG;
    }
    return delay;
}

From source file:com.sos.jobnet.utils.TimeKeyCalculator.java

License:Apache License

public TimeKeyCalculator(DateTime timeValue, DateTimeFormatter format, DurationFieldType type) {
    this.timeValue = timeValue;
    this.format = format;
    this.type = type;
    this.timeKey = timeValue.toString(format);
    this.calculatedTimeValue = timeValue.toMutableDateTime();
}

From source file:model.SqlInterface.java

/**
 * Get all the issues for a specified period to display in a report.
 * //from   w w w .  j  a  v a  2s.  c  o  m
 * @param startDate The start date of the period.
 * @param endDate The end date of the period.
 * 
 * @return The total time spent on tasks this within the given period.
 */
public String[][] getWeekEntries(DateTime startDate, DateTime endDate) {
    // Need mutable to perform arithmetic
    MutableDateTime start = startDate.toMutableDateTime();
    // Need mutable to perform arithmetic
    MutableDateTime end = endDate.toMutableDateTime();
    // Only have 'isBefore' so add one day to make it equivalent to
    // 'isBeforeOrOnThisDay'
    end.addDays(1);

    List<String[]> weekEntries = new ArrayList<String[]>();
    int runningCount = 0;
    while (start.isBefore(end)) {
        try {
            String date = Time.getReferableDate(start.toDateTime());

            for (String[] dayEntries : getEntriesByDate(date)) {
                weekEntries.add(dayEntries);
                runningCount++;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        start.addDays(1);
    }

    String[][] weekEntriesArray = new String[runningCount][6];
    int counter = 0;
    for (String[] entry : weekEntries) {
        weekEntriesArray[counter] = entry;
        counter++;
    }
    return weekEntriesArray;
}

From source file:model.SqlInterface.java

/**
 * Using today's date and the date of the start of the week, determine how
 * much time has been spent on tasks so far this week.
 * /*from   w w  w . j a  v a 2  s.c  o m*/
 * @param startDate The start date of the period.
 * @param endDate The end date of the period.
 * 
 * @return The total time spent on tasks this within the given period.
 */
public Period getWeekTally(DateTime startDate, DateTime endDate) {
    Period tally = new Period();
    // Need mutable to perform arithmetic
    MutableDateTime start = startDate.toMutableDateTime();
    // Need mutable to perform arithmetic
    MutableDateTime end = endDate.toMutableDateTime();
    // Only have 'isBefore' so add one day to make it equivalent to
    // 'isBeforeOrOnThisDay'
    end.addDays(1);

    ResultSet rs;

    while (start.isBefore(end)) {
        try {
            rs = statementHandler.executeQuery(
                    "select * from timelord where date = '" + Time.getReferableDate(start.toDateTime()) + "';");
            while (rs.next()) {
                // There should only be one for day and 7 for week
                tally = new Period(tally).plus(new Period(rs.getObject(4)));
            }

            rs.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        start.addDays(1);
    }

    return tally;
}

From source file:model.SqlInterface.java

/**
 * Use this method to get all the values from the database corresponding to
 * the given JIRA project for the time period specified.
 * //from   w ww .  jav  a  2s . c  o m
 * @param startDate The start date of the period to report on.
 * @param interval The length of time from the start date to report on.
 * @param jiraCode The Jira issue to report on.
 * 
 * @return ArrayList where each entry is an array containing the
 *         contents of each row from the database that was found: date,
 *         start, stop, delta, jira, description, dayTally.
 */
public Object[][] generateReport(DateTime startDate, Period interval, String jiraCode) {
    int taskCount = 0;
    String[][] tableData = null;

    MutableDateTime start = startDate.toMutableDateTime();
    // Need mutable to perform arithmetic
    MutableDateTime end = startDate.plus(interval).toMutableDateTime();
    // Only have 'isBefore' so add one day to make it equivalent to
    // 'isBeforeOrOnThisDay'
    end.addDays(1);

    ResultSet rs;
    try {
        rs = statementHandler.executeQuery("select * from timelord where date = '"
                + Time.getReferableDate(start.toDateTime()) + "' and jira = '" + jiraCode + "';");

        while (rs.next()) {
            taskCount++;
        }
        rs = statementHandler.executeQuery("select * from timelord where date = '"
                + Time.getReferableDate(start.toDateTime()) + "' and jira = '" + jiraCode + "';");

        tableData = new String[taskCount][6];

        taskCount = 0;
        while (start.isBefore(end)) {
            while (rs.next()) {
                tableData[taskCount][0] = Time.getFormattedDate(new DateTime(rs.getObject("start")));
                tableData[taskCount][1] = Time.getFormattedTime(new DateTime(rs.getObject("start")));
                tableData[taskCount][2] = Time.getFormattedTime(new DateTime(rs.getObject("stop")));
                tableData[taskCount][3] = Time.displayDelta(new Period(rs.getObject("delta")));
                tableData[taskCount][4] = rs.getString("jira");
                tableData[taskCount][5] = rs.getString("description");

                taskCount++;
            }
            start.addDays(1);
        }
    } catch (SQLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    return tableData;
}

From source file:nz.al4.airclock.MainActivity.java

License:Open Source License

@Override
public void onAlarmTimePicked(int hour, int minute) {

    DateTime currentTime = DateTime.now().toDateTime(mTimeCalculator.getTimeZone());
    Log.v("alarmCalc", "current time" + currentTime.toString());
    MutableDateTime desiredTime = currentTime.toMutableDateTime();
    desiredTime.setHourOfDay(hour);/*from   ww  w  . jav a 2 s.co  m*/
    desiredTime.setMinuteOfHour(minute);

    // if after we set the hour + minute we get an earlier time, user probably means next day
    if (desiredTime.isBefore(currentTime)) {
        desiredTime.addDays(1);
    }

    DateTime alarmTime = mTimeCalculator.timeForAlarm(desiredTime.toDateTime().toLocalDateTime());

    DateTime originAlarm = alarmTime.toDateTime(mTimeCalculator.mOriginTime.getZone());
    DateTime destAlarm = alarmTime.toDateTime(mTimeCalculator.mDestTime.getZone());

    String msg = String.format("You should set your alarm for:\n%s (origin)\nor\n%s (destination)",
            dateTimeFormatter.print(originAlarm) + " " + originAlarm.getZone().toString(),
            dateTimeFormatter.print(destAlarm) + " " + destAlarm.getZone().toString());

    new AlertDialog.Builder(this).setTitle("Alarm").setMessage(msg).setCancelable(false)
            .setPositiveButton("ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Whatever...
                }
            }).show();
}

From source file:org.joda.example.time.Examples.java

License:Apache License

private void runDateTime() {
    System.out.println("DateTime");
    System.out.println("=======");
    System.out.println(/*from  www .  j  a va  2 s  . co m*/
            "DateTime stores a the date and time using millisecs from 1970-01-01T00:00:00Z internally");
    System.out.println("DateTime is immutable and thread-safe");
    System.out.println("                      in = new DateTime()");
    DateTime in = new DateTime();
    System.out.println("Millisecond time:     in.getMillis():           " + in.getMillis());
    System.out.println("ISO string version:   in.toString():            " + in.toString());
    System.out.println("ISO chronology:       in.getChronology():       " + in.getChronology());
    System.out.println("Your time zone:       in.getDateTimeZone():     " + in.getZone());
    System.out.println("Change millis:        in.withMillis(0):         " + in.withMillis(0L));
    System.out.println("");
    System.out.println("Get year:             in.getYear():             " + in.getYear());
    System.out.println("Get monthOfYear:      in.getMonthOfYear():      " + in.getMonthOfYear());
    System.out.println("Get dayOfMonth:       in.getDayOfMonth():       " + in.getDayOfMonth());
    System.out.println("...");
    System.out.println("Property access:      in.dayOfWeek().get():                   " + in.dayOfWeek().get());
    System.out.println(
            "Day of week as text:  in.dayOfWeek().getAsText():             " + in.dayOfWeek().getAsText());
    System.out.println(
            "Day as short text:    in.dayOfWeek().getAsShortText():        " + in.dayOfWeek().getAsShortText());
    System.out.println("Day in french:        in.dayOfWeek().getAsText(Locale.FRENCH):"
            + in.dayOfWeek().getAsText(Locale.FRENCH));
    System.out.println("Max allowed value:    in.dayOfWeek().getMaximumValue():       "
            + in.dayOfWeek().getMaximumValue());
    System.out.println("Min allowed value:    in.dayOfWeek().getMinimumValue():       "
            + in.dayOfWeek().getMinimumValue());
    System.out.println(
            "Copy & set to Jan:    in.monthOfYear().setCopy(1):            " + in.monthOfYear().setCopy(1));
    System.out.println(
            "Copy & add 14 months: in.monthOfYear().addCopy(14):           " + in.monthOfYear().addToCopy(14));
    System.out.println("Add 14 mnths in field:in.monthOfYear().addWrapFieldCopy(14):  "
            + in.monthOfYear().addWrapFieldToCopy(14));
    System.out.println("...");
    System.out.println("Convert to Instant:   in.toInstant():           " + in.toInstant());
    System.out.println("Convert to DateTime:  in.toDateTime():          " + in.toDateTime());
    System.out.println("Convert to MutableDT: in.toMutableDateTime():   " + in.toMutableDateTime());
    System.out.println("Convert to Date:      in.toDate():              " + in.toDate());
    System.out.println("Convert to Calendar:  in.toCalendar(Locale.UK): "
            + in.toCalendar(Locale.UK).toString().substring(0, 46));
    System.out.println("Convert to GregCal:   in.toGregorianCalendar(): "
            + in.toGregorianCalendar().toString().substring(0, 46));
    System.out.println("");
    System.out.println("                      in2 = new DateTime(in.getMillis() + 10)");
    DateTime in2 = new DateTime(in.getMillis() + 10);
    System.out.println("Equals ms and chrono: in.equals(in2):           " + in.equals(in2));
    System.out.println("Compare millisecond:  in.compareTo(in2):        " + in.compareTo(in2));
    System.out.println("Compare millisecond:  in.isEqual(in2):          " + in.isEqual(in2));
    System.out.println("Compare millisecond:  in.isAfter(in2):          " + in.isAfter(in2));
    System.out.println("Compare millisecond:  in.isBefore(in2):         " + in.isBefore(in2));
}

From source file:org.mongoste.util.DateUtil.java

License:Open Source License

public static DateTime trimTime(DateTime dateTime) {
    MutableDateTime mdt = dateTime.toMutableDateTime();
    mdt.setTime(0, 0, 0, 0);//w w  w.  j a v  a 2 s. c om
    return mdt.toDateTime();
}