Example usage for org.joda.time MutableDateTime toDateTime

List of usage examples for org.joda.time MutableDateTime toDateTime

Introduction

In this page you can find the example usage for org.joda.time MutableDateTime toDateTime.

Prototype

DateTime toDateTime();

Source Link

Document

Get this object as a DateTime.

Usage

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 w w  .jav  a2  s .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:net.naonedbus.rest.controller.impl.HoraireController.java

License:Open Source License

/**
 * Rcuprer les horaires depuis le WebService.
 * //w  w w.  j  a v a  2  s . com
 * @throws IOException
 * @throws MalformedURLException
 */
public synchronized List<Horaire> getAllFromWeb(final Arret arret, final DateMidnight date) throws IOException {
    final UrlBuilder url = new UrlBuilder(PATH);
    final List<HoraireNode> horaires;
    List<Horaire> result = null;

    url.addSegment(arret.getCodeArret());
    url.addSegment(arret.getCodeLigne());
    url.addSegment(arret.getCodeSens());
    url.addSegment(mDateFormat.format(date.toDate()));
    final HoraireContainer content = parseJsonObject(url.getUrl());

    MutableDateTime mutableDateTime = new MutableDateTime(date);

    if (content != null) {
        horaires = content.horaires;
        result = new ArrayList<Horaire>();

        int lastHour = Integer.MIN_VALUE;

        // Transformation des horaires TAN en horaire naonedbus.
        for (final HoraireNode horaireTan : horaires) {
            final int hour = Integer.parseInt(horaireTan.heure.replaceAll("[^\\d.]", ""));

            mutableDateTime.setHourOfDay(hour);

            // Changement de jour
            if (hour < lastHour) {
                mutableDateTime.addDays(1);
            }
            lastHour = hour;

            for (final String passage : horaireTan.passages) {
                int minute = Integer.parseInt(passage.replaceAll("[^\\d.]", ""));

                mutableDateTime.setMinuteOfHour(minute);

                final Horaire horaire = new Horaire();
                horaire.setJour(date);
                horaire.setHoraire(mutableDateTime.toDateTime());
                horaire.setTerminus(parseTerminus(passage, content.notes));
                horaire.setSection(new DateMidnight(horaire.getHoraire()));
                result.add(horaire);
            }
        }
    }

    return result;
}

From source file:net.solarnetwork.central.dras.mock.biz.MockDRASObserverBiz.java

License:Open Source License

public MockDRASObserverBiz() {
    TimeZone tz = TimeZone.getTimeZone("Pacific/Auckland");

    uniLocation = new SolarLocation();
    uniLocation.setId(counter.decrementAndGet());
    uniLocation.setCountry("NZ");
    uniLocation.setCreated(new DateTime());
    uniLocation.setName("Mock Location");
    uniLocation.setRegion("UNI");
    uniLocation.setTimeZoneId(tz.getID());
    uniLocation.setLatitude(groupLatitude);
    uniLocation.setLongitude(groupLongitude);

    uniLocations = new LinkedHashMap<Long, SolarLocation>();
    uniLocations.put(uniLocation.getId(), uniLocation);

    uniGroups = new ArrayList<SolarNodeGroup>(numGroups);
    addGroup(new SolarNodeGroup(counter.decrementAndGet(), uniLocation.getId(), "Mock Group A"));
    addGroup(new SolarNodeGroup(counter.decrementAndGet(), uniLocation.getId(), "Mock Group B"));
    participantGroups = new ArrayList<CapabilityInformation>(numGroups);
    for (SolarNodeGroup group : uniGroups) {
        SimpleCapabilityInformation groupInfo = new SimpleCapabilityInformation();
        groupInfo.setId(group.getId());// www.  j a  v  a  2  s.com
        groupInfo.setLocation(uniLocation);
        groupInfo.setGenerationCapacityWatts(participantGenerationCapacity);
        groupInfo.setStorageCapacityWattHours(participantStorageCapacity);
        participantGroups.add(groupInfo);
    }

    uniProgramParticipants = new LinkedHashSet<Identity<Long>>(numNodes);
    participantGroupMemebers = new LinkedHashMap<Long, Set<CapabilityInformation>>(numGroups);
    for (int i = 0; i < numNodes; i++) {
        SolarNode participant = new SolarNode(counter.decrementAndGet(), createRandomLocation().getId());
        uniProgramParticipants.add(participant);
        int groupIndex = (i % numGroups);
        SimpleCapabilityInformation group = (SimpleCapabilityInformation) participantGroups.get(groupIndex);
        Set<CapabilityInformation> groupMembers = participantGroupMemebers.get(group.getId());
        if (groupMembers == null) {
            groupMembers = new LinkedHashSet<CapabilityInformation>(numNodes);
            participantGroupMemebers.put(group.getId(), groupMembers);
        }
        SimpleCapabilityInformation info = new SimpleCapabilityInformation();
        info.setId(participant.getId());
        info.setLocation(uniLocations.get(participant.getLocationId()));
        info.setGenerationCapacityWatts(participantGenerationCapacity);
        info.setStorageCapacityWattHours(participantStorageCapacity);
        groupMembers.add(info);
        group.addGenerationCapacityWatts(participantGenerationCapacity);
        group.addStorageCapacityWattHours(participantStorageCapacity);
    }
    uniProgram = new Program(counter.decrementAndGet(), "UNI Program", 1);

    MutableDateTime mdt = new MutableDateTime(2011, 1, 1, 8, 0, 0, 0, DateTimeZone.forTimeZone(tz));
    uniEvents = new ArrayList<Event>(numEvents);
    uniEventParticipants = new LinkedHashMap<Long, EventParticipants>(numEvents);
    uniEventTargets = new LinkedHashMap<Long, EventTargets>(numEvents);

    EventRule eventRule = new EventRule(counter.decrementAndGet(), EventRule.RuleKind.LOAD_AMOUNT,
            EventRule.ScheduleKind.DYNAMIC);
    addEventRule(eventRule);

    for (int i = 0; i < numEvents; i++) {
        Event event = new Event(counter.decrementAndGet(), uniProgram.getId(),
                String.format("Mock Event %d", (i + 1)), mdt.toDateTime(),
                mdt.toDateTime().plus(Period.hours(2)));

        Set<Identity<Long>> groupSet = new LinkedHashSet<Identity<Long>>(2);
        switch (i % 3) {
        case 0:
            groupSet.add(participantGroups.get(0));
            break;

        case 1:
            groupSet.add(participantGroups.get(1));
            break;

        case 2:
            groupSet.add(participantGroups.get(0));
            groupSet.add(participantGroups.get(1));
            break;
        }
        EventParticipants ep = new EventParticipants(counter.decrementAndGet(), event.getId(), null, groupSet);
        uniEventParticipants.put(event.getId(), ep);

        // give each event a load shed target of 1kW
        EventTargets et = new EventTargets(counter.decrementAndGet(), eventRule.getId(),
                new TreeSet<EventTarget>(Arrays.asList(new EventTarget(Duration.ZERO, 1000D))));

        addEvent(event, ep, et);
        mdt.addWeeks(1);
    }
}

From source file:net.solarnetwork.central.dras.mock.biz.MockDRASQueryBiz.java

License:Open Source License

@Override
public List<? extends NodeDatum> getAggregatedDatum(Class<? extends NodeDatum> datumClass,
        DatumQueryCommand criteria) {//from  w w  w . j  av a  2  s  .  c  o m
    MutableDateTime mdt = new MutableDateTime(criteria.getStartDate());
    Period period;
    switch (criteria.getAggregate()) {
    case Hour:
        period = Period.hours(1);
        break;

    case Day:
        period = Period.days(1);
        break;

    case Week:
        period = Period.weeks(1);
        break;

    case Month:
        period = Period.months(1);
        break;

    default:
        period = Period.minutes(1);
    }
    List<NodeDatum> results = new ArrayList<NodeDatum>();
    do {
        NodeDatum datum = null;
        if (ConsumptionDatum.class.isAssignableFrom(datumClass)) {
            ReportingConsumptionDatum d = new ReportingConsumptionDatum();
            d.setNodeId(criteria.getNodeId());
            d.setCreated(mdt.toDateTime());
            Duration dur = period.toDurationFrom(mdt);
            float hours = (float) ((double) dur.getMillis() / (double) (1000 * 60 * 60));
            d.setWattHours(Double.valueOf(hours * consumptionWattHours));
            datum = d;
        } else if (PowerDatum.class.isAssignableFrom(datumClass)) {
            ReportingPowerDatum d = new ReportingPowerDatum();
            d.setNodeId(criteria.getNodeId());
            d.setCreated(mdt.toDateTime());
            Duration dur = period.toDurationFrom(mdt);
            float hours = (float) ((double) dur.getMillis() / (double) (1000 * 60 * 60));
            d.setWattHours(Double.valueOf(hours * generationWattHours));
            datum = d;
        }
        if (datum != null) {
            results.add(datum);
        }
        mdt.add(period);
    } while (mdt.isBefore(criteria.getEndDate()));
    return results;
}

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);//  ww  w  .  ja v  a  2  s .  c  om
    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.agatom.springatom.data.hades.model.appointment.NAppointment.java

License:Open Source License

public NAppointment setBeginTime(final LocalTime localTime) {
    this.requireBeginDate();
    final MutableDateTime mutableDateTime = this.begin.toMutableDateTime();
    mutableDateTime.setTime(localTime.toDateTimeToday());
    this.begin = mutableDateTime.toDateTime();
    return this;
}

From source file:org.agatom.springatom.data.hades.model.appointment.NAppointment.java

License:Open Source License

public NAppointment setEndTime(final LocalTime localTime) {
    this.requireEndDate();
    final MutableDateTime mutableDateTime = this.end.toMutableDateTime();
    mutableDateTime.setTime(localTime.toDateTimeToday());
    this.end = mutableDateTime.toDateTime();
    return this;
}

From source file:org.agatom.springatom.data.hades.model.appointment.NAppointment.java

License:Open Source License

public NAppointment setBeginDate(final LocalDate localDate) {
    this.requireBeginDate();
    final MutableDateTime mutableDateTime = this.begin.toMutableDateTime();
    mutableDateTime.setDate(localDate.getYear(), localDate.getMonthOfYear(), localDate.getDayOfMonth());
    this.begin = mutableDateTime.toDateTime();
    return this;
}

From source file:org.agatom.springatom.data.hades.model.appointment.NAppointment.java

License:Open Source License

public NAppointment setEndDate(final LocalDate localDate) {
    this.requireEndDate();
    final MutableDateTime mutableDateTime = this.end.toMutableDateTime();
    mutableDateTime.setDate(localDate.getYear(), localDate.getMonthOfYear(), localDate.getDayOfMonth());
    this.end = mutableDateTime.toDateTime();
    return this;
}

From source file:org.efaps.ui.wicket.components.date.DateTimePanel.java

License:Apache License

/**
 * Method to get for the parameters returned from the form as a datetimes.
 *
 * @param _date date/*  w  w  w  .ja  v  a  2s. co m*/
 * @param _hour hour
 * @param _minute minutes
 * @param _ampm am/pm
 * @return valid string
 * @throws EFapsException on error
 */
public List<DateTime> getDateList(final List<StringValue> _date, final List<StringValue> _hour,
        final List<StringValue> _minute, final List<StringValue> _ampm) throws EFapsException {
    final List<DateTime> ret = new ArrayList<>();
    if (_date != null) {
        Iterator<StringValue> hourIter = null;
        Iterator<StringValue> minuteIter = null;
        Iterator<StringValue> ampmIter = null;
        if (_hour != null) {
            hourIter = _hour.iterator();
        }
        if (_minute != null) {
            minuteIter = _minute.iterator();
        }
        if (_ampm != null) {
            ampmIter = _ampm.iterator();
        }

        for (final StringValue date : _date) {
            if (!date.isNull() && !date.isEmpty()) {
                final DateTimeFormatter fmt = DateTimeFormat
                        .forPattern(this.converter.getDatePattern(Context.getThreadContext().getLocale()))
                        .withChronology(Context.getThreadContext().getChronology());
                fmt.withLocale(getLocale());
                final MutableDateTime mdt = fmt.parseMutableDateTime(date.toString());
                if (hourIter != null) {
                    final StringValue hourStr = hourIter.next();
                    final int hour = Integer.parseInt(hourStr.toString("0"));
                    mdt.setHourOfDay(hour);
                    if (ampmIter != null) {
                        final StringValue ampmStr = ampmIter.next();
                        if ("am".equals(ampmStr.toString("am"))) {
                            if (hour == 12) {
                                mdt.setHourOfDay(0);
                            }
                        } else {
                            if (hour != 12) {
                                mdt.setHourOfDay(hour + 12);
                            }
                        }
                    }
                    if (minuteIter != null) {
                        final StringValue minuteStr = minuteIter.next();
                        final int minute = Integer.parseInt(minuteStr.toString("0"));
                        mdt.setMinuteOfHour(minute);
                    }
                }
                ret.add(mdt.toDateTime());
            }
        }
    }
    return ret;
}