Example usage for org.joda.time Interval Interval

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

Introduction

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

Prototype

public Interval(Object interval, Chronology chronology) 

Source Link

Document

Constructs a time interval by converting or copying from another object, overriding the chronology.

Usage

From source file:edu.illinois.cs.cogcomp.temporal.normalizer.main.timex2interval.TimexConverter.java

License:Open Source License

/**
 * Convert a timex3 format to a range/interval
 * @param tc//from  www  .ja  va2 s . c om
 * @return
 */
public static Interval timeConverter(TimexChunk tc) {
    String patternStr = "\\s*([\\w]*)[-]([\\w]*)[-](.*)";
    Pattern pattern = Pattern.compile(patternStr);
    HashMap<String, String> attrMap = tc.getAttributes();
    if (attrMap.get("type") != "TIME") {
        System.out.println("Couldn't convert type other than TIME");
        return null;
    }
    String normString = attrMap.get("value");
    Matcher matcher = pattern.matcher(normString);
    boolean matchFound = matcher.find();
    if (matchFound) {
        String year = matcher.group(1);
        String month = matcher.group(2);
        String day = matcher.group(3);

        // We will not deal with any vague norm value; if such exists, return [0/1/1-9999/1/1]
        // and always mark as correct in normalization, as long as our system didn't return null
        if (year.contains("X") | month.contains("X") | day.contains("X")) {
            DateTime start = new DateTime(0, 1, 1, 0, 0, 0, 0);
            DateTime finish = new DateTime(9999, 1, 1, 0, 0, 0, 0);
            return new Interval(start, finish);
        }
        int yearInt = Integer.parseInt(year);
        int monthInt = Integer.parseInt(month);
        String time = "";

        if (day.indexOf("T") != -1) {
            int pos = day.indexOf("T");
            time = day.substring(pos + 1);
            day = day.substring(0, pos);
        }
        int dayInt = Integer.parseInt(day);
        if (time.length() == 0) {
            DateTime start = new DateTime(yearInt, monthInt, dayInt, 0, 0, 0, 0);
            DateTime finish = new DateTime(yearInt, monthInt, dayInt, 23, 59, 59, 0);
            return new Interval(start, finish);
        } else if (time == "MO") {
            DateTime start = new DateTime(yearInt, monthInt, dayInt, 7, 0, 0, 0);
            DateTime finish = new DateTime(yearInt, monthInt, dayInt, 10, 59, 59, 59);
            return new Interval(start, finish);
        } else if (time == "MD") {
            DateTime start = new DateTime(yearInt, monthInt, dayInt, 11, 0, 0, 0);
            DateTime finish = new DateTime(yearInt, monthInt, dayInt, 13, 59, 59, 59);
            return new Interval(start, finish);
        } else if (time == "AF") {
            DateTime start = new DateTime(yearInt, monthInt, dayInt, 14, 0, 0, 0);
            DateTime finish = new DateTime(yearInt, monthInt, dayInt, 17, 59, 59, 59);
            return new Interval(start, finish);
        } else if (time == "EV") {
            DateTime start = new DateTime(yearInt, monthInt, dayInt, 18, 0, 0, 0);
            DateTime finish = new DateTime(yearInt, monthInt, dayInt, 20, 59, 59, 59);
            return new Interval(start, finish);
        } else if (time == "NI") {
            DateTime start = new DateTime(yearInt, monthInt, dayInt, 21, 0, 0, 0);
            DateTime finish = new DateTime(yearInt, monthInt, dayInt, 23, 59, 59, 59);
            return new Interval(start, finish);
        }

        String hmsPatternStr = "\\s*(\\d{2})(?:[:])*(\\d{2})*(?:[:])*(\\d{2})*";
        Pattern hmsPattern = Pattern.compile(hmsPatternStr);
        Matcher hmsMatcher = hmsPattern.matcher(time);
        boolean hmsMatchFound = hmsMatcher.find();
        if (hmsMatchFound) {
            // System.out.println(matcher.group(1));
            int i;
            for (i = 1; i <= 3; i++) {
                if (hmsMatcher.group(i) == null) {
                    i--;
                    break;
                }
            }
            if (i == 4) {
                i--;
            }
            int numterm = i;

            // This means we have all HH:MM:SS
            if (numterm == 3) {
                int hour = Integer.parseInt(hmsMatcher.group(1));
                int minute = Integer.parseInt(hmsMatcher.group(2));
                int second = Integer.parseInt(hmsMatcher.group(3));
                DateTime start = new DateTime(yearInt, monthInt, dayInt, hour, minute, second, 0);
                DateTime finish = new DateTime(yearInt, monthInt, dayInt, hour, minute, second, 59);
                return new Interval(start, finish);
            }

            // Only have HH:MM
            else if (numterm == 2) {
                int hour = Integer.parseInt(hmsMatcher.group(1));
                int minute = Integer.parseInt(hmsMatcher.group(2));
                DateTime start = new DateTime(yearInt, monthInt, dayInt, hour, minute, 0, 0);
                DateTime finish = new DateTime(yearInt, monthInt, dayInt, hour, minute, 59, 59);
                return new Interval(start, finish);
            }

            // Only have HH
            else if (numterm == 1) {
                int hour = Integer.parseInt(hmsMatcher.group(1));
                DateTime start = new DateTime(yearInt, monthInt, dayInt, hour, 0, 0, 0);
                DateTime finish = new DateTime(yearInt, monthInt, dayInt, hour, 59, 59, 59);
                return new Interval(start, finish);
            }
        } else {
            DateTime start = new DateTime(yearInt, monthInt, dayInt, 0, 0, 0, 0);
            DateTime finish = new DateTime(yearInt, monthInt, dayInt, 23, 59, 59, 59);
            return new Interval(start, finish);
        }
    }

    return null;

}

From source file:edu.wpi.cs.wpisuitetng.modules.cal.models.client.CachingDisplayableClient.java

License:Open Source License

/**
 * Gets all visible events in the range [from..to]
 * @param from//from   ww w. jav  a  2 s.com
 * @param to
 * @return list of visible events
 */
protected List<T> getRange(DateTime from, DateTime to) {
    validateCache();
    // set up to filter events based on booleans in MainPanel
    List<T> filteredEvents = new ArrayList<T>();
    final Interval range = new Interval(from, to);

    // loop through and add only if isProjectEvent() matches corresponding
    // boolean
    for (T e : cache.values()) {
        if (range.overlaps(e.getInterval()) && filter(e)) {
            filteredEvents.add(e);
        }
    }
    return filteredEvents;
}

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

License:Open Source License

@Override
public void setTime(DateTime newTime) {
    if (new Interval(new DateTime(this.start), new DateTime(this.end)).contains(newTime)) {
        //this is what stops the events from being dragged to the next day. leaving it in case we might want it later
        //return;
    }/*www .j  av  a 2 s  . c o m*/

    Interval i;
    int daysBetween = 0;
    if (new DateTime(this.start).isAfter(newTime)) {
        i = new Interval(newTime, new DateTime(this.start));
        daysBetween = 0 - (int) i.toDuration().getStandardDays();
    } else {
        i = new Interval(new DateTime(this.start), newTime);
        daysBetween = (int) i.toDuration().getStandardDays();
    }

    MutableDateTime newEnd = new MutableDateTime(this.end);
    newEnd.addDays(daysBetween);

    MutableDateTime newStart = new MutableDateTime(this.start);
    newStart.addDays(daysBetween);

    this.end = newEnd.toDate();
    this.start = newStart.toDate();

}

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

License:Open Source License

/**
 * Creates a DayItem (drawable) based on an overlapping Displayable (Information) on the given day
 * // w w  w  . j ava  2  s.com
 * @param eventPositionalInformation the positional information for the Displayable
 * @param displayedDay the day to display this panel on
 */
public DayItem(OverlappedDisplayable eventPositionalInformation, DateTime displayedDay) {
    bottom = new ResizingHandle(this, false);
    top = new ResizingHandle(this, true);
    top.setMinimumSize(new Dimension(0, 6));
    top.setMaximumSize(new Dimension(10000, 6));
    top.setPreferredSize(new Dimension(10000, 6));
    top.setCursor(new Cursor(Cursor.S_RESIZE_CURSOR));
    this.add(top);
    isBeingDragged = false;
    this.displayedDay = displayedDay;
    this.eventPositionalInformation = eventPositionalInformation;
    height = 25;
    displayable = eventPositionalInformation.getEvent();
    length = new Interval(displayable.getStart(), displayable.getEnd());

    Color bg = Colors.TABLE_GRAY_HEADER;

    if (displayable instanceof Event) {
        bg = displayable.getColor();
        setBorder(new CompoundBorder(new LineBorder(Colors.TABLE_BACKGROUND),
                new CompoundBorder(new LineBorder(bg.darker()), new EmptyBorder(6, 6, 6, 6))));
    } else if (displayable instanceof Commitment) {
        Color b;
        Commitment.Status s = ((Commitment) displayable).getStatus();
        switch (s) {
        case COMPLETE:
            b = new Color(192, 255, 192);
            break;
        case IN_PROGRESS:
            b = new Color(255, 255, 192);
            break;
        case NOT_STARTED:
            b = new Color(240, 110, 110);
            break;
        default:
            b = Color.BLACK;
            break;
        }
        setBorder(new CompoundBorder(new LineBorder(Colors.TABLE_BACKGROUND),
                new CompoundBorder(new MatteBorder(1, 0, 0, 0, b),
                        new CompoundBorder(new LineBorder(bg.darker()), new EmptyBorder(0, 6, 0, 6)))));
        top.setEnabled(false);
        bottom.setEnabled(false);
    }
    setBackground(bg);
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    lblEventTitle = new JLabel();
    add(lblEventTitle);
    lblEventTitle.setFont(new Font("Tahoma", Font.BOLD, 14));
    lblEventTitle.putClientProperty("html.disable", true); //prevents html parsing
    lblEventTitle.setText(displayable.getName());
    lblTimeInfo = new JLabel();
    putTimeOn();
    lblTimeInfo.setBorder(new EmptyBorder(0, 0, 3, 0));
    lblTimeInfo.setMaximumSize(new Dimension(32767, 20));
    lblTimeInfo.setFont(new Font("DejaVu Sans", Font.ITALIC, 14));
    add(lblTimeInfo);
    lblStarryNightdutch = new JLabel();
    add(lblStarryNightdutch);
    lblStarryNightdutch.setVerticalAlignment(SwingConstants.TOP);
    lblStarryNightdutch.setBackground(bg);
    lblStarryNightdutch.setFont(new Font("Tahoma", Font.PLAIN, 14));
    lblStarryNightdutch.setMinimumSize(new Dimension(0, 0));
    bottom.setMinimumSize(new Dimension(0, 6));
    bottom.setMaximumSize(new Dimension(10000, 6));
    bottom.setPreferredSize(new Dimension(10000, 6));
    this.add(Box.createVerticalGlue());
    bottom.setCursor(new Cursor(Cursor.S_RESIZE_CURSOR));
    this.add(bottom);
    addMouseListener(new MouseListener() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (isBeingDragged) {
                if (puppet != null) {
                    day = puppet.day;
                    int previous = displayable.getStart().getDayOfWeek() % 7;
                    if (day > previous)
                        updateTime(displayable.getStart().plusDays(day - previous));
                    if (previous > day)
                        updateTime(displayable.getStart().minusDays(previous - day));
                }
                displayable.update();
                MainPanel.getInstance().display(displayable.getStart());
            }
            getParent().dispatchEvent(e);
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.getClickCount() > 1) {
                MainPanel.getInstance().editSelectedDisplayable(displayable);
            } else {
                MainPanel.getInstance().updateSelectedDisplayable(displayable);
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            getParent().dispatchEvent(e);
        }

        @Override
        public void mouseEntered(MouseEvent e) {

        }

        @Override
        public void mouseClicked(MouseEvent e) {

        }
    });

    this.addMouseMotionListener(new MouseMotionListener() {
        @Override
        public void mouseMoved(MouseEvent e) {
            getParent().dispatchEvent(e);
        }

        @Override
        public void mouseDragged(MouseEvent arg0) {
            isBeingDragged = true;
            getParent().dispatchEvent(arg0);
        }
    });
    width = new Rational(((eventPositionalInformation.getCollisions() > 1) ? 2 : 1),
            1 + eventPositionalInformation.getCollisions());
    x = eventPositionalInformation.getXpos();
    description = Arrays.asList(eventPositionalInformation.getEvent().getDescription().split(" "));
    if (x.toInt(10000) + width.toInt(10000) > 10000)
        width = width.multiply(new Rational(1, 2));
    recalcBounds(200, FIXED_HEIGHT);
}

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);/*  w w w .  j ava 2  s . 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 w  w . java 2  s. c om*/
    displayable.setStart(d.toDateTime());
    length = new Interval(displayable.getStart(), displayable.getEnd());
    height += minutes;
    firstDraw = true;
    isBeingDragged = true;
    putTimeOn();
    getParent().revalidate();
    getParent().repaint();
}

From source file:edu.wpi.cs.wpisuitetng.modules.cal.ui.views.week.WeekCalendar.java

License:Open Source License

/**
 * Adds all multiday event items into grids corresponding to the days of the week
 * then adds them to the top bar display
 *//*  ww  w  . j  av  a2 s .  c om*/
private void populateMultidayEventGrid() {
    List<Event> multidayEvents = getMultidayEvents();
    multidayItemList.clear();
    Collections.sort(multidayEvents, new Comparator<Event>() {

        @Override
        public int compare(Event o1, Event o2) {
            return o1.getEnd().compareTo(o2.getEnd());
        }

    });
    int rows = 0;

    while (!multidayEvents.isEmpty()) {
        JPanel multiGrid = new JPanel();
        multiGrid.setBorder(BorderFactory.createEmptyBorder());
        multiGrid.setLayout(new MigLayout("insets 0,gap 0",
                "[sizegroup a,grow][sizegroup a,grow][sizegroup a,grow][sizegroup a,grow][sizegroup a,grow][sizegroup a,grow][sizegroup a,grow]",
                "[]"));

        int gridIndex = 0;

        next: while (gridIndex < 7) {
            Interval mInterval = new Interval(daysOfWeekArray[gridIndex].getDisplayDate(),
                    daysOfWeekArray[gridIndex].getDisplayDate().plusDays(1));

            for (Event currEvent : multidayEvents) {
                if (isDisplayableInInterval(currEvent, mInterval)) {
                    boolean firstPanel = true;
                    WeekMultidayEventItem multidayPanel;
                    do {
                        if (firstPanel) {
                            multidayPanel = new WeekMultidayEventItem(currEvent, MultidayEventItemType.Start,
                                    " " + currEvent.getName());
                            multidayPanel.setMinimumSize(new Dimension(0, 0));
                            multidayPanel.setBackground(currEvent.getColor());
                            if (multiGrid.getComponentCount() > 0)
                                ((JComponent) multiGrid.getComponents()[multiGrid.getComponentCount() - 1])
                                        .setBorder(BorderFactory.createMatteBorder(rows == 0 ? 1 : 0,
                                                (gridIndex == 1) ? 1 : 0, 1, 0, Colors.BORDER));
                            multidayPanel.setRows(rows);
                            multidayPanel.setDynamicBorder(currEvent.getColor().darker(), false);
                            multiGrid.add(multidayPanel, "cell " + gridIndex + " 0, grow");
                            multidayItemList.add(multidayPanel);
                            firstPanel = false;
                        } else {
                            multidayPanel = new WeekMultidayEventItem(currEvent, MultidayEventItemType.Middle);
                            multidayPanel.setBackground(currEvent.getColor());
                            multidayPanel.setRows(rows);
                            multidayPanel.setDynamicBorder(currEvent.getColor().darker(), false);
                            multiGrid.add(multidayPanel, "cell " + gridIndex + " 0, grow");
                            multidayItemList.add(multidayPanel);
                        }
                        gridIndex++;
                    } while (gridIndex < 7
                            && daysOfWeekArray[gridIndex].getDisplayDate().isBefore(currEvent.getEnd()));

                    if (multidayPanel.getType() == MultidayEventItemType.Start)
                        multidayPanel.setType(MultidayEventItemType.Single);
                    else
                        multidayPanel.setType(MultidayEventItemType.End);

                    multidayPanel.setDynamicBorder(currEvent.getColor().darker(), false);
                    multidayEvents.remove(currEvent);
                    continue next;
                }
            }

            // if we don't find anything, add spacer and go to next day
            gridIndex++;
            WeekMultidayEventItem spacer = new WeekMultidayEventItem(null,
                    gridIndex == 1 ? MultidayEventItemType.Start
                            : gridIndex == 7 ? MultidayEventItemType.End : MultidayEventItemType.Middle);
            spacer.setBackground(Colors.TABLE_BACKGROUND);
            spacer.setRows(rows);
            spacer.setSpacer(true);
            spacer.setDynamicBorder(Colors.BORDER, false);
            multiGrid.add(spacer, "cell " + (gridIndex - 1) + " 0, grow");
        }

        if (multiGrid.getComponentCount() > 0)
            headerBox.add(multiGrid);
        rows++;
    }
    // need to set this manually, silly because scrollpanes are silly and don't resize
    if (rows > 3) {
        add(headerScroller, "cell 1 2 8 1,grow");
        rows = 3;
    } else {
        add(headerScroller, "cell 1 2 7 1,grow");
    }
    ((MigLayout) getLayout()).setRowConstraints(
            "[][][" + (rows * 23 + 1) + "px:n:80px,grow]" + (rows > 0 ? "6" : "") + "[grow]");
}

From source file:edu.wpi.cs.wpisuitetng.modules.cal.ui.views.week.WeekCalendar.java

License:Open Source License

/**
 * Selects an event's corresponding Displayable
 * // www .  j  a v a2 s.  c  o  m
 * @param on
 *            Event being selected
 * @param setTo
 *            Displayable of Event being selected
 */
private void selectEvents(Event on, Displayable setTo) {
    // TODO: refactor this pattern
    DayPanel mLouvreTour;
    MutableDateTime startDay = new MutableDateTime(on.getStart());
    MutableDateTime endDay = new MutableDateTime(on.getEnd());

    endDay.setMillisOfDay(0);
    endDay.addDays(1);
    endDay.addMillis(-1);
    startDay.setMillisOfDay(0);

    Interval eventLength = new Interval(startDay, endDay);
    if (setTo == null || eventLength.toDuration().getStandardHours() > 24) {
        for (WeekMultidayEventItem multidayItem : multidayItemList) {
            if (setTo != null && multidayItem.getEvent().getUuid().equals(((Event) on).getUuid()))
                multidayItem.setSelected(true);
            else
                multidayItem.setSelected(false);
        }
        return;
    }

    //TODO: can be simplified now that multiday events are handled elsewhere
    int index = 0;
    for (int i = 0; i < 7; i++) {
        if (startDay.getDayOfYear() == daysOfWeekArray[i].getDisplayDate().getDayOfYear()) {
            index = i;
            break;
        }
    }

    while (index < 7 && !endDay.isBefore(daysOfWeekArray[index].getDisplayDate())) {
        mLouvreTour = daysOfWeekArray[index];
        try {
            mLouvreTour.select(setTo);
        } catch (NullPointerException ex) {
            // silently ignore as this is apparently not in the view
        }
        index++;
    }
}

From source file:emhs.db.model.GBEntryBook.java

public ArrayList<String[]> getEntries() {
    ArrayList<String[]> entries = new ArrayList<>();

    for (int i = guestSheet.getPhysicalNumberOfRows() - 1; i > 0; i--) {
        Row r = guestSheet.getRow(i);/*from  w  ww .  java  2  s  .c  om*/
        if (isRowEmpty(r, 4) || !isRowSafe(r, new int[] { 0, 2, 3 }))
            continue;

        DateTime startOfToday = DateTime.now().withTimeAtStartOfDay();

        DateTime entryTime = DateTimeFormat.forPattern("MMM d yyyy HH:mm:ss")
                .parseDateTime(r.getCell(3).getStringCellValue().replaceAll("(\\d{1,2})(?:st|nd|rd|th)", "$1"));
        DateTime returnTime = null;
        if (r.getCell(4) != null && r.getCell(4).getStringCellValue().trim().length() != 0)
            returnTime = DateTimeFormat.forPattern("MMM d yyyy HH:mm:ss").parseDateTime(
                    r.getCell(4).getStringCellValue().replaceAll("(\\d{1,2})(?:st|nd|rd|th)", "$1"));

        if (!new Interval(startOfToday, startOfToday.plusDays(1)).contains(entryTime))
            break;

        entries.add(new String[] { r.getCell(0).getStringCellValue(), "Guest",
                DateTimeFormat.forPattern("HH:mm").print(entryTime), i + "",
                r.getCell(1) == null ? "" : r.getCell(1).getStringCellValue(),
                r.getCell(2).getStringCellValue(),
                returnTime == null ? "" : DateTimeFormat.forPattern("HH:mm").print(returnTime) });
    }

    for (int i = staffSheet.getPhysicalNumberOfRows() - 1; i > 0; i--) {
        Row r = staffSheet.getRow(i);
        if (isRowEmpty(r, 3) || !isRowSafe(r, new int[] { 0, 1, 2 }))
            continue;

        DateTime startOfToday = DateTime.now().withTimeAtStartOfDay();

        DateTime entryTime = DateTimeFormat.forPattern("MMM d yyyy HH:mm:ss")
                .parseDateTime(r.getCell(2).getStringCellValue().replaceAll("(\\d{1,2})(?:st|nd|rd|th)", "$1"));
        DateTime returnTime = null;
        if (r.getCell(3) != null && r.getCell(3).getStringCellValue().trim().length() != 0)
            returnTime = DateTimeFormat.forPattern("MMM d yyyy HH:mm:ss").parseDateTime(
                    r.getCell(3).getStringCellValue().replaceAll("(\\d{1,2})(?:st|nd|rd|th)", "$1"));

        if (!new Interval(startOfToday, startOfToday.plusDays(1)).contains(entryTime))
            break;
        entries.add(new String[] { r.getCell(0).getStringCellValue(), "Staff",
                DateTimeFormat.forPattern("HH:mm").print(entryTime), i + "", r.getCell(1).getStringCellValue(),
                returnTime == null ? "" : DateTimeFormat.forPattern("HH:mm").print(returnTime) });
    }

    for (int i = substituteSheet.getPhysicalNumberOfRows() - 1; i > 0; i--) {
        Row r = substituteSheet.getRow(i);
        if (isRowEmpty(r, 6) || !isRowSafe(r, new int[] { 0, 1, 2, 3, 4, 5 }))
            continue;
        DateTime startOfToday = DateTime.now().withTimeAtStartOfDay();

        DateTime entryTime = DateTimeFormat.forPattern("MMM d yyyy HH:mm:ss")
                .parseDateTime(r.getCell(6).getStringCellValue().replaceAll("(\\d{1,2})(?:st|nd|rd|th)", "$1"));

        if (!new Interval(startOfToday, startOfToday.plusDays(1)).contains(entryTime))
            break;
        entries.add(new String[] { r.getCell(0).getStringCellValue(), "Substitute",
                DateTimeFormat.forPattern("HH:mm").print(entryTime), i + "", r.getCell(1).getStringCellValue(),
                r.getCell(2).getStringCellValue(), r.getCell(3).getStringCellValue(),
                r.getCell(4).getStringCellValue(),
                r.getCell(5) == null ? "" : r.getCell(5).getStringCellValue() });
    }

    return entries;
}

From source file:energy.usef.core.util.DateTimeUtil.java

License:Apache License

/**
 * Calculate the number of minutes from midnight to now. The number of minutes depends on summer- and winter time.
 *
 * @param dateTime the date time which includes the timezone. When setting the DateTime with the default constructor, the
 * default timezone where the application runs, is used.
 * @return the number of minutes from midnight.
 */// w  ww.  j a v a  2s .  com
public static Integer getElapsedMinutesSinceMidnight(LocalDateTime dateTime) {
    DateTime midnight = dateTime.toLocalDate().toDateMidnight().toDateTime();
    Duration duration = new Interval(midnight, dateTime.toDateTime()).toDuration();
    return (int) duration.getStandardSeconds() / SECONDS_PER_MINUTE;
}