private CategoryDataset getDatasetFromDateTime(TreeMap<Date,ArrayList<Timestamp>> dateTimeForMAC) {
        final int timeRange = 120; //time range in seconds
        try
        {
            int timeOnDates = 0, totalTimeByDay, seriesTime = 0, timeInSeries = 0;
            long seconds1, seconds2, delta;
            DefaultCategoryDataset ds = new DefaultCategoryDataset();
            String time1 = "", time2 = "";
            DateFormat df = new SimpleDateFormat("HH:mm:ss");
            
            for ( Map.Entry<Date, ArrayList<Timestamp>> entry : dateTimeForMAC.entrySet() )
            {
                Date entryDate = entry.getKey();
                ArrayList<Timestamp> entryTimes = entry.getValue();
                totalTimeByDay = 0;
                
                if (entryTimes.size() > 1)
                {
                    for(int i=1; i<entryTimes.size(); i++)
                    {
                        seconds1 = entryTimes.get(i).getTime()/1000;
                        seconds2 = entryTimes.get(i-1).getTime()/1000;
                        delta = seconds1 - seconds2;
                        if (delta < timeRange)
                        {
                            seriesTime = seriesTime + (int)delta;
                            if (timeInSeries == 0)
                                time1 = df.format(entryTimes.get(i-1));
                            timeInSeries++;
                            if (!(i == entryTimes.size()-1)) //if we are at last entry, end the series
                                continue;
                        }
                        //series ends
                        if (seriesTime > 0)
                        {
                            if (entryTimes.size() == 2) //if list contains only 2 entries and those are inside timeRange, get second time (at position 1)
                                time2 = df.format(entryTimes.get(i));
                            else
                                time2 = df.format(entryTimes.get(i-1));
                            ds.addValue(((double)seriesTime)/60, time1+"-"+time2, entryDate.toString().substring(5));
                            totalTimeByDay = totalTimeByDay + seriesTime;
                            seriesTime = 0; timeInSeries = 0; //finished with this interval
                        }
                    }
                }
                //ds.addValue(totalTimeByDay/60, "Minutes", date.toString().substring(5,date.toString().length())); // /60 -> time in minutes
                timeOnDates = timeOnDates + totalTimeByDay;
            }
            this.totalTime = timeOnDates/60; //fast hack /60 to get minutes
            return ds;
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE);
            return null;
        }
    }