List of usage examples for org.joda.time MutableDateTime toDateTime
DateTime toDateTime();
From source file:edu.wpi.cs.wpisuitetng.modules.cal.ui.views.day.DayCalendar.java
License:Open Source License
public DayCalendar(DateTime on) { this.time = on; MutableDateTime mdt = time.toMutableDateTime(); mdt.setMillis(0);// w w w. j a v a 2s. co m this.dayStart = mdt.toDateTime(); mdt.addDays(1); mdt.addMillis(-1); this.dayEnd = mdt.toDateTime(); scroll.setBackground(Colors.TABLE_BACKGROUND); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scroll.getVerticalScrollBar().setUnitIncrement(20); scroll.setAutoscrolls(true); scroll.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); holder.setBackground(Colors.TABLE_BACKGROUND); this.setLayout(new BorderLayout()); this.holder.setLayout(new BorderLayout()); generateDay(); }
From source file:edu.wpi.cs.wpisuitetng.modules.cal.ui.views.day.DayCalendar.java
License:Open Source License
/** * Get visible events for the current day view * @return returns the list of events to display *//* w w w. j a v a 2 s.c om*/ private List<Displayable> getVisibleDisplayables() { // Set up from and to datetime for search MutableDateTime f = new MutableDateTime(time); f.setMillisOfDay(0); DateTime from = f.toDateTime(); f.addDays(1); DateTime to = f.toDateTime(); // Return list of events to be displayed List<Displayable> visibleDisplayables = new ArrayList<Displayable>(); visibleDisplayables.addAll(EventClient.getInstance().getEvents(from, to)); visibleDisplayables.addAll(CommitmentClient.getInstance().getCommitments(from, to)); Collections.sort(visibleDisplayables, new Comparator<Displayable>() { public int compare(Displayable d1, Displayable d2) { return d1.getStart().getMinuteOfDay() < d2.getStart().getMinuteOfDay() ? -1 : d1.getStart().getMinuteOfDay() > d2.getStart().getMinuteOfDay() ? 1 : 0; } }); return visibleDisplayables; }
From source file:edu.wpi.cs.wpisuitetng.modules.cal.ui.views.month.MonthDay.java
License:Open Source License
public MonthDay(DateTime initDay, DayStyle style, final MonthCalendar parent) { this.day = initDay; this.parent = parent; this.style = style; Color grayit = Colors.TABLE_GRAY_HEADER, textit = Colors.TABLE_TEXT, bg = Colors.TABLE_BACKGROUND; switch (style) { case Normal://from w w w . j a va 2s .co m grayit = Colors.TABLE_GRAY_HEADER; textit = Colors.TABLE_GRAY_TEXT; break; case OutOfMonth: grayit = bg; break; case Today: grayit = Colors.TABLE_GRAY_HEADER; textit = Colors.TABLE_GRAY_TEXT; break; default: throw new IllegalStateException("DayStyle is not a valid DayStyle!"); } setBackground(bg); setForeground(textit); borderTop = grayit.equals(bg); setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS)); header.setBackground(grayit); header.setForeground(textit); header.setFont(new java.awt.Font("DejaVu Sans", style == DayStyle.Today ? Font.BOLD : Font.PLAIN, 12)); header.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); header.setText(Integer.toString(initDay.getDayOfMonth())); header.setAutoscrolls(true); header.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); header.setMaximumSize(new java.awt.Dimension(10000, 17)); header.setOpaque(true); if (style == DayStyle.Today) { Font font = header.getFont(); Map attributes = font.getAttributes(); attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); header.setFont(font.deriveFont(attributes)); } add(header); addMouseListener(new MouseListener() { @Override public void mousePressed(MouseEvent e) { parent.dispatchEvent(e); MainPanel.getInstance().setSelectedDay(day); MainPanel.getInstance().clearSelected(); parent.setEscaped(false); } @Override public void mouseClicked(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { if (parent.isEscaped()) { MonthDay releasedDay = parent.getMonthDayAtCursor(); Displayable selected = MainPanel.getInstance().getSelectedEvent(); if (selected != null) { MutableDateTime newTime = new MutableDateTime(selected.getStart()); newTime.setYear(releasedDay.day.getYear()); newTime.setDayOfYear(releasedDay.day.getDayOfYear()); selected.setTime(newTime.toDateTime()); selected.update(); } } parent.dispatchEvent(e); } @Override public void mouseEntered(MouseEvent e) { parent.dispatchEvent(e); } @Override public void mouseExited(MouseEvent e) { setBackground(Colors.TABLE_BACKGROUND); parent.setEscaped(true); } }); header.addMouseListener(new MouseListener() { @Override public void mousePressed(MouseEvent e) { MainPanel.getInstance().setSelectedDay(day); MainPanel.getInstance().clearSelected(); } @Override public void mouseClicked(MouseEvent e) { MainPanel.getInstance().miniMove(day); MainPanel.getInstance().viewDay(); } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { setBackground(Colors.TABLE_BACKGROUND); } }); addMouseMotionListener(new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { parent.repaint(); parent.dispatchEvent(e); } @Override public void mouseMoved(MouseEvent e) { parent.dispatchEvent(e); } }); }
From source file:edu.wpi.cs.wpisuitetng.modules.cal.ui.views.year.YearCalendar.java
License:Open Source License
/** * gets the drawn year//from w w w .j a v a 2s .c om * * @param start the date time that starts the series. * @return the jpanel that contains the colored days and the S/M/T/W/R/F/S labels */ private JPanel getFourMonthGrid(MutableDateTime start) { int gridHeight = 19; int gridWidth = 7; JPanel p = new JPanel(); p.setLayout(new GridLayout(gridHeight, gridWidth)); String[] days = { "S", "M", "T", "W", "R", "F", "S" }; for (int i = 0; i < 7; i++) { JLabel header = new JLabel(days[i]); header.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Colors.BORDER)); header.setHorizontalAlignment(SwingConstants.CENTER); header.setFont(new Font("DejaVu Sans", Font.ITALIC, 12)); p.add(header); } for (int j = 0; j < 18 * 7; j++) { Color dayBackground = start.getMonthOfYear() % 2 == 0 ? Colors.TABLE_BACKGROUND : Colors.TABLE_GRAY_HEADER; Integer eventCount = events.get(start.getDayOfYear()); eventCount = eventCount == null ? 0 : eventCount; YearlyDayHolder day = new YearlyDayHolder(start.toDateTime(), dayBackground); MutableDateTime today = new MutableDateTime(DateTime.now()); today.setMillisOfDay(0); MutableDateTime checking = new MutableDateTime(start); start.setMillisOfDay(0); if (checking.toDateTime().isEqual(today)) { day.setBackground(Colors.SELECTED_BACKGROUND); day.setForeground(Colors.SELECTED_TEXT); } JLabel dayLabel = new JLabel(start.getDayOfMonth() + ""); dayLabel.setHorizontalAlignment(SwingConstants.CENTER); day.setLayout(new GridLayout(1, 1)); day.add(dayLabel); day.setBorder( BorderFactory.createMatteBorder(0, start.getDayOfWeek() % 7 == 0 ? 1 : 0, 1, 1, Colors.BORDER)); day.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent me) { YearlyDayHolder event = (YearlyDayHolder) (me.getSource()); MainPanel.getInstance().miniMove(event.getDateTime()); MainPanel.getInstance().viewDay(); } @Override public void mouseEntered(MouseEvent me) { // this is just a demo of what it can do } @Override public void mouseExited(MouseEvent me) { } @Override public void mousePressed(MouseEvent me) { //TODO: something? maybe nothing? have to decide with team/steakholders } @Override public void mouseReleased(MouseEvent me) { YearlyDayHolder event = (YearlyDayHolder) (me.getSource()); MainPanel.getInstance().miniMove(event.getDateTime()); } }); p.add(day); start.addDays(1); } int width = 280; int height = 570; p.setMinimumSize(new Dimension(0, height - 150)); p.setPreferredSize(new Dimension(width, height)); p.setMaximumSize(new Dimension(width + 350, height + 150)); return p; }
From source file:fc.cron.CronExpression.java
License:Apache License
public DateTime nextTimeAfter(DateTime afterTime, DateTime dateTimeBarrier) { MutableDateTime nextTime = new MutableDateTime(afterTime); nextTime.setMillisOfSecond(0);//w w w . j a v a 2 s. c o m nextTime.secondOfDay().add(1); while (true) { // day of week while (true) { // month while (true) { // day of month while (true) { // hour while (true) { // minute while (true) { // second if (secondField.matches(nextTime.getSecondOfMinute())) { break; } nextTime.secondOfDay().add(1); } if (minuteField.matches(nextTime.getMinuteOfHour())) { break; } nextTime.minuteOfDay().add(1); nextTime.secondOfMinute().set(0); } if (hourField.matches(nextTime.getHourOfDay())) { break; } nextTime.hourOfDay().add(1); nextTime.minuteOfHour().set(0); nextTime.secondOfMinute().set(0); } if (dayOfMonthField.matches(new LocalDate(nextTime))) { break; } nextTime.addDays(1); nextTime.setTime(0, 0, 0, 0); checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier); } if (monthField.matches(nextTime.getMonthOfYear())) { break; } nextTime.addMonths(1); nextTime.setDayOfMonth(1); nextTime.setTime(0, 0, 0, 0); checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier); } if (dayOfWeekField.matches(new LocalDate(nextTime))) { break; } nextTime.addDays(1); nextTime.setTime(0, 0, 0, 0); checkIfDateTimeBarrierIsReached(nextTime, dateTimeBarrier); } return nextTime.toDateTime(); }
From source file:influent.server.rest.BigChartResource.java
License:MIT License
@Post("json") public Map<String, ChartData> getBigChartData(String jsonData) { try {/* w ww . j a va 2 s. co m*/ JSONProperties request = new JSONProperties(jsonData); final String focusContextId = request.getString("focuscontextid", null); final String sessionId = request.getString("sessionId", null); if (!GuidValidator.validateGuidString(sessionId)) { throw new ResourceException(Status.CLIENT_ERROR_EXPECTATION_FAILED, "sessionId is not a valid UUID"); } DateTime startDate = null; try { startDate = DateTimeParser.parse(request.getString("startDate", null)); } catch (IllegalArgumentException iae) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "BigChartResource: An illegal argument was passed into the 'startDate' parameter."); } DateTime endDate = null; try { endDate = DateTimeParser.parse(request.getString("endDate", null)); } catch (IllegalArgumentException iae) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "BigChartResource: An illegal argument was passed into the 'endDate' parameter."); } List<String> focusIds = new LinkedList<String>(); Iterable<String> focusIter = request.getStrings("focusId"); for (String entityId : focusIter) { List<String> entities = new ArrayList<String>(); InfluentId id = InfluentId.fromInfluentId(entityId); // Point account owners and summaries to their owner account if (id.getIdClass() == InfluentId.ACCOUNT_OWNER || id.getIdClass() == InfluentId.CLUSTER_SUMMARY) { entities.add(InfluentId.fromNativeId(InfluentId.ACCOUNT, id.getIdType(), id.getNativeId()) .toString()); } else if (id.getIdClass() == InfluentId.CLUSTER) { String nId = id.getNativeId(); if (nId.startsWith("|")) { // group cluster for (String sId : nId.split("\\|")) { if (!sId.isEmpty()) { entities.add(sId); } } } else { entities.add(entityId); } } else { entities.add(entityId); } for (String fid : entities) { if (!focusIds.contains(fid)) { focusIds.add(fid); } } } final Double focusMaxDebitCredit = request.getDouble("focusMaxDebitCredit", null); final Integer width = request.getInteger("width", 145); final Integer height = request.getInteger("height", 60); List<Properties> entityArray = Lists.newArrayList(request.getPropertiesSets("entities")); Map<String, ChartData> infoList = new HashMap<String, ChartData>(entityArray.size()); /// TODO : make this date range sanity check better if (startDate.getYear() < 1900 || startDate.getYear() > 9999) { MutableDateTime msdt = new MutableDateTime(startDate); msdt.setYear(2007); startDate = msdt.toDateTime(); logger.warn("Invalid start date passed from UI, setting to default"); } if (endDate.getYear() < 1900 || endDate.getYear() > 9999) { MutableDateTime medt = new MutableDateTime(endDate); medt.setYear(2013); endDate = medt.toDateTime(); logger.warn("Invalid end date passed from UI, setting to default"); } FL_DateRange dateRange = DateRangeBuilder.getBigChartDateRange(startDate, endDate); // compute an individual chart for each entity received for (Properties entityRequest : entityArray) { final String entityId = entityRequest.getString("dataId", null); final String entityContextId = entityRequest.getString("contextId", null); List<String> entityIds = new ArrayList<String>(); // Check to see if this entityId belongs to a group cluster. InfluentId id = InfluentId.fromInfluentId(entityId); if (id.getIdClass() == InfluentId.CLUSTER) { String nId = id.getNativeId(); if (nId.startsWith("|")) { // group cluster for (String sId : nId.split("\\|")) { if (!sId.isEmpty()) { entityIds.add(sId); } } } else { entityIds.add(entityId); } } else { entityIds.add(entityId); } ChartHash hash = new ChartHash(entityIds, startDate, endDate, focusIds, focusMaxDebitCredit, dateRange.getNumBins().intValue(), width, height, entityContextId, focusContextId, sessionId, contextCache); ChartData chartData = chartBuilder.computeChart(dateRange, entityIds, focusIds, entityContextId, focusContextId, sessionId, dateRange.getNumBins().intValue(), hash); infoList.put(entityId, //memberIds.get(0), chartData); } return infoList; } catch (AvroRemoteException e) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Data access error.", e); } catch (JSONException je) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "JSON parse error.", je); } }
From source file:influent.server.rest.ChartResource.java
License:MIT License
@Post("json") public Map<String, ChartData> getChartData(String jsonData) { try {// w w w .j av a 2 s.c o m JSONProperties request = new JSONProperties(jsonData); final String focusContextId = request.getString("focuscontextid", null); final String sessionId = request.getString("sessionId", null); if (!GuidValidator.validateGuidString(sessionId)) { throw new ResourceException(Status.CLIENT_ERROR_EXPECTATION_FAILED, "sessionId is not a valid UUID"); } DateTime startDate = null; try { startDate = DateTimeParser.parse(request.getString("startDate", null)); } catch (IllegalArgumentException iae) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "ChartResource: An illegal argument was passed into the 'startDate' parameter."); } DateTime endDate = null; try { endDate = DateTimeParser.parse(request.getString("endDate", null)); } catch (IllegalArgumentException iae) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "ChartResource: An illegal argument was passed into the 'endDate' parameter."); } List<String> focusIds = new LinkedList<String>(); Iterable<String> focusIter = request.getStrings("focusId"); for (String entityId : focusIter) { List<String> entities = new ArrayList<String>(); InfluentId id = InfluentId.fromInfluentId(entityId); // Point account owners and summaries to their owner account if (id.getIdClass() == InfluentId.ACCOUNT_OWNER || id.getIdClass() == InfluentId.CLUSTER_SUMMARY) { entities.add(InfluentId.fromNativeId(InfluentId.ACCOUNT, id.getIdType(), id.getNativeId()) .toString()); } else if (id.getIdClass() == InfluentId.CLUSTER) { String nId = id.getNativeId(); if (nId.startsWith("|")) { // group cluster for (String sId : nId.split("\\|")) { if (!sId.isEmpty()) { entities.add(sId); } } } else { entities.add(entityId); } } else { entities.add(entityId); } for (String fid : entities) { if (!focusIds.contains(fid)) { focusIds.add(fid); } } } final Double focusMaxDebitCredit = request.getDouble("focusMaxDebitCredit", null); final Integer width = request.getInteger("width", 140); final Integer height = request.getInteger("height", 60); List<Properties> entityArray = Lists.newArrayList(request.getPropertiesSets("entities")); Map<String, ChartData> infoList = new HashMap<String, ChartData>(entityArray.size()); final Integer numBuckets = request.getInteger("numBuckets", 15); /// TODO : make this date range sanity check better if (startDate.getYear() < 1900 || startDate.getYear() > 9999) { MutableDateTime msdt = new MutableDateTime(startDate); msdt.setYear(2007); startDate = msdt.toDateTime(); logger.warn("Invalid start date passed from UI, setting to default"); } if (endDate.getYear() < 1900 || endDate.getYear() > 9999) { MutableDateTime medt = new MutableDateTime(endDate); medt.setYear(2013); endDate = medt.toDateTime(); logger.warn("Invalid end date passed from UI, setting to default"); } FL_DateRange dateRange = DateRangeBuilder.getDateRange(startDate, endDate); // compute an individual chart for each entity received for (Properties entityRequest : entityArray) { final String entityId = entityRequest.getString("dataId", null); final String entityContextId = entityRequest.getString("contextId", null); List<String> entityIds = new ArrayList<String>(); InfluentId id = InfluentId.fromInfluentId(entityId); if (id.getIdClass() == InfluentId.CLUSTER) { String nId = id.getNativeId(); if (nId.startsWith("|")) { for (String sId : nId.split("\\|")) { if (!sId.isEmpty()) { entityIds.add(sId); } } } else { entityIds.add(entityId); } } else { entityIds.add(entityId); } ChartHash hash = new ChartHash(entityIds, startDate, endDate, focusIds, focusMaxDebitCredit, numBuckets, width, height, entityContextId, focusContextId, sessionId, contextCache); ChartData chartData = chartBuilder.computeChart(dateRange, entityIds, focusIds, entityContextId, focusContextId, sessionId, numBuckets, hash); infoList.put(entityId, //memberIds.get(0), chartData); } return infoList; } catch (AvroRemoteException e) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Data access error.", e); } catch (JSONException je) { throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "JSON parse error.", je); } }
From source file:io.druid.server.log.FileRequestLogger.java
License:Apache License
@LifecycleStart public void start() { try {//from ww w . j a va 2s . c o m baseDir.mkdirs(); MutableDateTime mutableDateTime = new DateTime().toMutableDateTime(); mutableDateTime.setMillisOfDay(0); currentDay = mutableDateTime.toDateTime(); fileWriter = new OutputStreamWriter( new FileOutputStream(new File(baseDir, currentDay.toString("yyyy-MM-dd'.log'")), true), Charsets.UTF_8); long nextDay = currentDay.plusDays(1).getMillis(); Duration delay = new Duration(nextDay - new DateTime().getMillis()); ScheduledExecutors.scheduleWithFixedDelay(exec, delay, Duration.standardDays(1), new Callable<ScheduledExecutors.Signal>() { @Override public ScheduledExecutors.Signal call() { currentDay = currentDay.plusDays(1); try { synchronized (lock) { CloseQuietly.close(fileWriter); fileWriter = new OutputStreamWriter( new FileOutputStream(new File(baseDir, currentDay.toString()), true), Charsets.UTF_8); } } catch (Exception e) { Throwables.propagate(e); } return ScheduledExecutors.Signal.REPEAT; } }); } catch (IOException e) { Throwables.propagate(e); } }
From source file:model.SqlInterface.java
/** * Get all the issues for a specified period to display in a report. * //from w ww . j a va 2 s . c o m * @param startDate The start date of the period. * @param endDate The end date of the period. * * @return The total time spent on tasks this within the given period. */ public String[][] getWeekEntries(DateTime startDate, DateTime endDate) { // Need mutable to perform arithmetic MutableDateTime start = startDate.toMutableDateTime(); // Need mutable to perform arithmetic MutableDateTime end = endDate.toMutableDateTime(); // Only have 'isBefore' so add one day to make it equivalent to // 'isBeforeOrOnThisDay' end.addDays(1); List<String[]> weekEntries = new ArrayList<String[]>(); int runningCount = 0; while (start.isBefore(end)) { try { String date = Time.getReferableDate(start.toDateTime()); for (String[] dayEntries : getEntriesByDate(date)) { weekEntries.add(dayEntries); runningCount++; } } catch (SQLException e) { e.printStackTrace(); } start.addDays(1); } String[][] weekEntriesArray = new String[runningCount][6]; int counter = 0; for (String[] entry : weekEntries) { weekEntriesArray[counter] = entry; counter++; } return weekEntriesArray; }
From source file:model.SqlInterface.java
/** * Using today's date and the date of the start of the week, determine how * much time has been spent on tasks so far this week. * //from www . j a v a2 s. c om * @param startDate The start date of the period. * @param endDate The end date of the period. * * @return The total time spent on tasks this within the given period. */ public Period getWeekTally(DateTime startDate, DateTime endDate) { Period tally = new Period(); // Need mutable to perform arithmetic MutableDateTime start = startDate.toMutableDateTime(); // Need mutable to perform arithmetic MutableDateTime end = endDate.toMutableDateTime(); // Only have 'isBefore' so add one day to make it equivalent to // 'isBeforeOrOnThisDay' end.addDays(1); ResultSet rs; while (start.isBefore(end)) { try { rs = statementHandler.executeQuery( "select * from timelord where date = '" + Time.getReferableDate(start.toDateTime()) + "';"); while (rs.next()) { // There should only be one for day and 7 for week tally = new Period(tally).plus(new Period(rs.getObject(4))); } rs.close(); } catch (SQLException e) { e.printStackTrace(); } start.addDays(1); } return tally; }