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:com.tmathmeyer.sentinel.utils.Months.java

License:Open Source License

public static DateTime nextWeek(DateTime time) {
    MutableDateTime mdt = new MutableDateTime(time);
    mdt.addDays(7);//from  ww  w  .j  a v  a2 s.  co  m
    return mdt.toDateTime();
}

From source file:com.tmathmeyer.sentinel.utils.Months.java

License:Open Source License

public static DateTime prevWeek(DateTime time) {
    MutableDateTime mdt = new MutableDateTime(time);
    mdt.addDays(-7);//w  w w . j  a  v  a2 s.  c  om
    return mdt.toDateTime();
}

From source file:com.tmathmeyer.sentinel.utils.Months.java

License:Open Source License

/**
 * //from ww w.  j a  v  a 2 s .  c om
 * @param d any DateTime
 * @return get's the Sundae of the provided day's week
 */
public static DateTime getWeekStart(DateTime d) {
    MutableDateTime t = new MutableDateTime(d);
    t.addDays(-(d.getDayOfWeek() % 7));
    return t.toDateTime();
}

From source file:com.yahoo.bard.webservice.sql.helper.SqlTimeConverter.java

License:Apache License

/**
 * Given an array of strings (a row from a {@link java.sql.ResultSet}) and the
 * {@link Granularity} used to make groupBy statements on time, it will parse out a {@link DateTime}
 * for the row which represents the beginning of the interval it was grouped on.
 *
 * @param offset the last column before the date fields.
 * @param recordValues  The results returned by Sql needed to read the time columns.
 * @param druidQuery  The original druid query which was made using calling
 * {@link #buildGroupBy(RelBuilder, Granularity, String)}.
 *
 * @return the datetime for the start of the interval.
 *//*from   w  ww . j a  va  2  s  .  c  om*/
public DateTime getIntervalStart(int offset, String[] recordValues, DruidAggregationQuery<?> druidQuery) {
    List<SqlDatePartFunction> times = timeGrainToDatePartFunctions(druidQuery.getGranularity());

    DateTimeZone timeZone = getTimeZone(druidQuery);

    if (times.isEmpty()) {
        throw new UnsupportedOperationException("Can't parse dateTime for if no times were grouped on.");
    }

    MutableDateTime mutableDateTime = new MutableDateTime(0, 1, 1, 0, 0, 0, 0, timeZone);

    for (int i = 0; i < times.size(); i++) {
        int value = Integer.parseInt(recordValues[offset + i]);
        SqlDatePartFunction fn = times.get(i);
        setDateTime(value, fn, mutableDateTime);
    }

    return mutableDateTime.toDateTime();
}

From source file:de.ifgi.airbase.feeder.io.csv.EEARawDataParser.java

License:Open Source License

static EEARawDataFile parseFile(File f, EEAStation station) throws IOException {
    log.debug("Parsing {}", f.getName());
    CSVReader reader = null;/*from w w  w . ja v a  2s  .  c o m*/
    try {
        reader = new CSVReader(new FileReader(f), '\t');
        String[] line = null;
        EEARawDataFile file = parseFileName(f, station);
        while ((line = reader.readNext()) != null) {
            Period period = file.getType().getPeriod();
            MutableDateTime lineStart = Utils.parseDateReverse(line[0]).toMutableDateTime();
            for (int i = 1; i < line.length; i += 2) {
                EEAMeasurement m = new EEAMeasurement(Double.parseDouble(line[i]),
                        Integer.parseInt(line[i + 1]), lineStart.toDateTime());
                file.addMeasurement(m);
                lineStart.add(period);
            }
        }
        reader.close();
        return file;
    } finally {
        if (reader != null) {
            reader.close();
        }
        reader = null;
    }
}

From source file:edu.wpi.cs.wpisuitetng.modules.cal.models.data.Commitment.java

License:Open Source License

/**
 * this is primarily used for multiday events
 * /* www. j a v a  2 s.  c om*/
 * @param givenDay gets the time that this event starts on a given day
 * @return when this event starts
 */
public DateTime getStartTimeOnDay(DateTime givenDay) {
    MutableDateTime mDisplayedDay = new MutableDateTime(givenDay);
    mDisplayedDay.setMillisOfDay(1);
    //if it starts before the beginning of the day then its a multi day event, or all day event
    if (this.getStart().isBefore(mDisplayedDay)) {
        mDisplayedDay.setMillisOfDay(0);
        return (mDisplayedDay.toDateTime());
    } else
        return this.getStart();
}

From source file:edu.wpi.cs.wpisuitetng.modules.cal.ui.navigation.GoToPanel.java

License:Open Source License

/**
 * Parses the input to the goTo field to ensure proper formatting and handle
 * syntax errors/*from   w  ww  . java  2  s . c  o m*/
 * @param text string to parse
 */
public void parseGoto(String text) {

    DateTime dt;
    boolean isValidYear = true;

    try {
        dt = gotoField.parseDateTime(text);
        if (dt.getYear() < 1900 || dt.getYear() > 2100) {
            isValidYear = false;
            dt = null;
        }
    }

    catch (IllegalArgumentException illArg) {
        try {
            MutableDateTime mdt = gotoFieldShort.parseMutableDateTime(text);
            mdt.setYear(currentDate.getYear()); // this format does not provide years. add it
            dt = mdt.toDateTime();
        } catch (IllegalArgumentException varArg) {
            dt = null;
        }
    }
    if (dt != null) {
        MainPanel.getInstance().display(dt);
        MainPanel.getInstance().refreshView();
        gotoErrorText.setText(" ");
    } else {
        if (isValidYear)
            gotoErrorText.setText("* Use format: mm/dd/yyyy");
        else
            gotoErrorText.setText("* Year out of range (1900-2100)");
    }
}

From source file:edu.wpi.cs.wpisuitetng.modules.cal.ui.navigation.MiniMonth.java

License:Open Source License

public MiniMonth(DateTime time, final MiniCalendarHostIface mc, boolean monthOnly) {
    this.setLayout(new GridLayout(7, 7));
    MutableDateTime prevMonth = new MutableDateTime(time);
    prevMonth.setDayOfMonth(1);/* ww  w.j  av a 2  s.c o m*/
    prevMonth.addMonths(-1); // What is prevMonth for?
    String[] dayLabel = { "S", "M", "T", "W", "R", "F", "S" };

    MouseListener monthChanger = new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent me) {
        }

        @Override
        public void mouseEntered(MouseEvent me) {
        }

        @Override
        public void mouseExited(MouseEvent me) {
        }

        @Override
        public void mousePressed(MouseEvent me) {
        }

        @Override
        public void mouseReleased(MouseEvent me) {
            DayLabel d = (DayLabel) (me.getSource());
            if (!(d instanceof DescriptiveDayLabel)) {
                mc.display(d.getMonth());
            }
        }
    };

    MutableDateTime referenceDay = new MutableDateTime(time);
    // reset to the first of the month at midnight, then find Sunday
    referenceDay.setDayOfMonth(1);
    referenceDay.setMillisOfDay(0);
    int first = referenceDay.getDayOfWeek();
    referenceDay.addDays(-first);
    boolean flipFlop = false;

    // add day labels
    for (int i = 0; i < 7; i++) {
        DayLabel day = new DescriptiveDayLabel(dayLabel[i], time);
        day.borderize((i % 7) == 0, i >= 5 * 7, (i % 7) == 6);
        add(day);
        day.addMouseListener(monthChanger);
    }

    // generate days, 6*7 covers all possible months, so we just loop
    // through and add each day
    for (int i = 0; i < (6 * 7); i++) {
        DayLabel day;
        if (monthOnly || MainPanel.getInstance().getView() == ViewSize.Month) {
            if (referenceDay.getDayOfMonth() == 1)
                flipFlop ^= true; // flops the flip flop flappity flip
        } else if (MainPanel.getInstance().getView() == ViewSize.Day)
            flipFlop = referenceDay.getDayOfYear() == time.getDayOfYear()
                    && referenceDay.getYear() == time.getYear();
        else if (MainPanel.getInstance().getView() == ViewSize.Week) {
            if (Months.getWeekStart(time).getMonthOfYear() == 12
                    && Months.getWeekStart(time).getDayOfMonth() >= 26) // Exception case for weeks between years
                flipFlop = time.getMonthOfYear() == 12 ? i >= 35 : i <= 6;
            else
                flipFlop = referenceDay.getDayOfYear() >= Months.getWeekStart(time).getDayOfYear()
                        && referenceDay.getDayOfYear() <= Months.getWeekStart(time).getDayOfYear() + 6;
        }

        if (flipFlop)
            day = new ActiveDayLabel(referenceDay.toDateTime());
        else
            day = new InactiveDayLabel(referenceDay.toDateTime());

        day.borderize((i % 7) == 0, i >= 5 * 7, (i % 7) == 6);
        add(day);
        day.addMouseListener(monthChanger);
        referenceDay.addDays(1); // go to next day
    }
}

From source file:edu.wpi.cs.wpisuitetng.modules.cal.ui.views.day.collisiondetection.DayItem.java

License:Open Source License

public void addMinutesToEnd(int minutes) {
    MutableDateTime d = displayable.getEnd().toMutableDateTime();
    d.addMinutes(minutes);//from  w ww. ja v  a2s .  c o m
    if (displayable instanceof Event)
        ((Event) displayable).setEnd(d.toDateTime());
    length = new Interval(displayable.getStart(), displayable.getEnd());
    height = Math.max(45, height + minutes);
    firstDraw = true;
    isBeingDragged = true;
    putTimeOn();
    revalidate();
    repaint();
}

From source file:edu.wpi.cs.wpisuitetng.modules.cal.ui.views.day.collisiondetection.DayItem.java

License:Open Source License

public void addMinutesToStart(int minutes) {
    MutableDateTime d = displayable.getStart().toMutableDateTime();
    d.addMinutes(minutes);/*from  w ww  .  java2s  . com*/
    displayable.setStart(d.toDateTime());
    length = new Interval(displayable.getStart(), displayable.getEnd());
    height += minutes;
    firstDraw = true;
    isBeingDragged = true;
    putTimeOn();
    getParent().revalidate();
    getParent().repaint();
}