Example usage for org.joda.time MutableDateTime MutableDateTime

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

Introduction

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

Prototype

public MutableDateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour,
        int secondOfMinute, int millisOfSecond) 

Source Link

Document

Constructs an instance from datetime field values using ISOChronology in the default time zone.

Usage

From source file:com.almende.eve.agent.MeetingAgent.java

License:Apache License

/**
 * Merge the busy intervals of all attendees, and the preferred intervals
 *//*from ww w  .  j a v a  2s  . c o m*/
private void mergeTimeConstraints() {
    final ArrayList<Interval> infeasibleIntervals = new ArrayList<Interval>();
    final ArrayList<Weight> preferredIntervals = new ArrayList<Weight>();

    final Activity activity = getActivity();
    if (activity != null) {
        // read and merge the stored busy intervals of all attendees
        for (final Attendee attendee : activity.withConstraints().withAttendees()) {
            final String agent = attendee.getAgent();
            if (attendee.getResponseStatus() != RESPONSE_STATUS.declined) {
                if (new Boolean(true).equals(attendee.getOptional())) {
                    // This attendee is optional.
                    // Add its busy intervals to the soft constraints
                    final List<Interval> attendeeBusy = getAgentBusy(agent);
                    if (attendeeBusy != null) {
                        for (final Interval i : attendeeBusy) {
                            final Weight wi = new Weight(i.getStart(), i.getEnd(),
                                    WEIGHT_BUSY_OPTIONAL_ATTENDEE);

                            preferredIntervals.add(wi);
                        }
                    }
                } else {
                    // this attendee is required.
                    // Add its busy intervals to the hard constraints
                    final List<Interval> attendeeBusy = getAgentBusy(agent);
                    if (attendeeBusy != null) {
                        infeasibleIntervals.addAll(attendeeBusy);
                    }
                }
            }
            // else This attendee declined. Ignore this attendees busy
            // interval
        }

        // read the time preferences and add them to the soft constraints
        final List<Preference> preferences = activity.withConstraints().withTime().withPreferences();
        for (final Preference p : preferences) {
            if (p != null) {
                final Weight wi = new Weight(new DateTime(p.getStart()), new DateTime(p.getEnd()),
                        p.getWeight());

                preferredIntervals.add(wi);
            }
        }
    }

    // add office hours profile to the soft constraints
    // TODO: don't include (hardcoded) office hours here, should be handled
    // by a PersonalAgent
    final DateTime timeMin = DateTime.now();
    final DateTime timeMax = timeMin.plusDays(LOOK_AHEAD_DAYS);
    final List<Interval> officeHours = IntervalsUtil.getOfficeHours(timeMin, timeMax);
    for (final Interval i : officeHours) {
        final Weight wi = new Weight(i, WEIGHT_OFFICE_HOURS);
        preferredIntervals.add(wi);
    }

    // add delay penalties to the soft constraints
    final DateTime now = DateTime.now();
    final MutableDateTime d = new MutableDateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), 0,
            0, 0, 0);
    for (int i = 0; i <= LOOK_AHEAD_DAYS; i++) {
        final DateTime start = d.toDateTime();
        final DateTime end = start.plusDays(1);
        final Weight wi = new Weight(start, end, WEIGHT_DELAY_PER_DAY * i);
        preferredIntervals.add(wi);
        d.addDays(1);
    }

    // order and store the aggregated lists with intervals
    IntervalsUtil.order(infeasibleIntervals);
    getState().put("infeasible", infeasibleIntervals);
    WeightsUtil.order(preferredIntervals);
    getState().put("preferred", preferredIntervals);
}

From source file:com.xpn.xwiki.plugin.jodatime.JodaTimePlugin.java

License:Open Source License

/**
 * @see org.joda.time.MutableDateTime#MutableDateTime(int, int, int, int, int, int, int)
 *///from w  w  w  .jav  a 2s.co  m
public MutableDateTime getMutableDateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay,
        int minuteOfHour, int secondOfMinute, int millisOfSecond) {
    return new MutableDateTime(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute,
            millisOfSecond);
}

From source file:org.chaston.oakfunds.model.ModelManagerImpl.java

License:Apache License

private Iterable<Instant> getAllInstantsInRange(Instant start, Instant end) {
    MutableDateTime mutableDateTime = new MutableDateTime(systemPropertiesManager.getCurrentYear(), 1, 1, 0, 0,
            0, 0);//from   w ww .  j a va2  s  .c o  m
    long maxYear = systemPropertiesManager.getCurrentYear() + systemPropertiesManager.getTimeHorizon();
    if (mutableDateTime.isBefore(start)) {
        mutableDateTime = start.toMutableDateTime();
    }
    ImmutableList.Builder<Instant> instants = ImmutableList.builder();
    while (mutableDateTime.isBefore(end) && mutableDateTime.get(DateTimeFieldType.year()) <= maxYear) {
        instants.add(mutableDateTime.toInstant());
        mutableDateTime.add(DurationFieldType.months(), 1);
    }
    return instants.build();
}

From source file:org.chaston.oakfunds.util.DateUtil.java

License:Apache License

public static Instant endOfYear(int year) {
    MutableDateTime mutableDateTime = new MutableDateTime(year, 1, 1, 0, 0, 0, 0);
    mutableDateTime.add(DurationFieldType.years(), 1);
    mutableDateTime.add(DurationFieldType.millis(), -1);
    return mutableDateTime.toInstant();
}

From source file:org.chaston.oakfunds.util.DateUtil.java

License:Apache License

public static Instant endOfMonth(int year, int monthOfYear) {
    MutableDateTime mutableDateTime = new MutableDateTime(year, monthOfYear, 1, 0, 0, 0, 0);
    mutableDateTime.add(DurationFieldType.months(), 1);
    mutableDateTime.add(DurationFieldType.millis(), -1);
    return mutableDateTime.toInstant();
}

From source file:org.chaston.oakfunds.util.DateUtil.java

License:Apache License

public static Instant endOfDay(int year, int monthOfYear, int dayOfMonth) {
    MutableDateTime mutableDateTime = new MutableDateTime(year, monthOfYear, dayOfMonth, 0, 0, 0, 0);
    mutableDateTime.add(DurationFieldType.days(), 1);
    mutableDateTime.add(DurationFieldType.millis(), -1);
    return mutableDateTime.toInstant();
}

From source file:y.elf.DbReader.java

License:Open Source License

public static List<ElfValue> readOldCentralineFile(String filename, int defaultvalue, int fieldnn) {
    final String separatorDate = "/";
    final String separatorTime = ":";
    final int UNUSED = Integer.MIN_VALUE;

    List<ElfValue> list = new ArrayList<ElfValue>();

    BufferedReader reader = null;

    try {//from   ww  w.  j ava2  s. co  m
        reader = new BufferedReader(new FileReader(filename));
        String line;
        MutableDateTime lasttime = new MutableDateTime(0, 1, 1, 0, 0, 0, 0);
        final MutableDateTime invalidtime = new MutableDateTime(0, 1, 1, 0, 0, 0, 0);

        while ((line = reader.readLine()) != null) {
            if (line.isEmpty())
                continue;

            try {
                boolean valid = true;
                final String[] parts = tokenize(line);
                int value = UNUSED;
                int maxvalue = 0;

                for (int i = 0; i < parts.length; i++) {
                    if (parts[i].equals("*"))
                        valid = false;
                    else if (parts[i].contains(separatorDate)) {
                        final String[] date = parts[i].split(separatorDate);

                        lasttime.setDayOfMonth(Integer.parseInt(date[0]));
                        lasttime.setMonthOfYear(Integer.parseInt(date[1]));
                        lasttime.setYear(Integer.parseInt(date[2]));
                    } else if (parts[i].contains(separatorTime)) {
                        final String[] hour = parts[i].split(separatorTime);
                        lasttime.setHourOfDay(Integer.parseInt(hour[0]));
                        lasttime.setMinuteOfHour(Integer.parseInt(hour[1]));
                    } else if (value == UNUSED)
                        value = translateValue(parts[i], defaultvalue);
                    else
                        maxvalue = translateValue(parts[i], defaultvalue);
                }

                if (lasttime.equals(invalidtime)) // invalid line (header)
                    continue;

                final DateTime currentdatetime = lasttime.toDateTime();

                if (value > 0) {
                    if (fieldnn == 2)
                        list.add(new ElfValue(currentdatetime, maxvalue, value, valid));
                    else
                        list.add(new ElfValue(currentdatetime, value, maxvalue, valid));
                } else
                    list.add(new ElfValue(currentdatetime, 0, 0, false));
            } catch (Exception e) {
                continue;
            } // on error, skip line
        }
    } catch (Exception e) {
        //         System.out.println(e.getMessage());
    } finally {
        if (reader != null)
            try {
                reader.close();
            } catch (IOException e) {
            }
    }

    return list;
}