List of usage examples for org.joda.time DateTime withMinuteOfHour
public DateTime withMinuteOfHour(int minute)
From source file:com.nissatech.proasense.eventplayer.partnerconfigurations.HellaConfiguration.java
/** * {@inheritDoc}/* w w w.j a va 2 s .c o m*/ */ @Override public BoundStatement generateQuery(DateTime startTime, DateTime endTime, List<String> variables, CassandraClient client) { DateTime roundedStartTime = startTime.withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); //to be sure we have the complete hour List<String> inKeys = new ArrayList<String>(); int hoursBetween = Hours.hoursBetween(roundedStartTime, endTime).getHours(); for (int i = 0; i < hoursBetween; i++) { long milliKeyPart = roundedStartTime.plusHours(i).getMillis(); for (String variable : variables) { inKeys.add(variable + "|" + milliKeyPart); } } //the ? in the prepared query is out of parenthesis for a reason. This is a deviation from the standard when using the IN keyword String query = "select * from hella_variables where type_hour_stamp in ? order by variable_timestamp"; BoundStatement statement = client.prepareStatement(query); statement.bind(inKeys); return statement; }
From source file:com.njlabs.amrita.aid.gpms.client.Gpms.java
License:Open Source License
private DateTime roundOffDate(DateTime target) { int minutes = target.getMinuteOfHour(); if (minutes > 0 && minutes < 15) { return target.withMinuteOfHour(15); } else if (minutes > 15 && minutes < 30) { return target.withMinuteOfHour(30); } else if (minutes > 30 && minutes < 45) { return target.withMinuteOfHour(45); } else if (minutes > 45 && minutes <= 59) { if (target.getHourOfDay() == 23) { return target.plusDays(1).withHourOfDay(0).withMinuteOfHour(0); } else {/*from w w w .j a v a 2 s. c o m*/ return target.plusHours(1).withMinuteOfHour(0); } } else { return target; } }
From source file:com.qcadoo.localization.api.utils.DateUtils.java
License:Open Source License
private static DateTime roundUpTime(final DateTime dateTime, final String timeExpressionPart) { DateTime roundedDate = dateTime; final String[] time = timeExpressionPart.split(":"); if (time.length < 1 || StringUtils.isBlank(time[0])) { roundedDate = roundedDate.withHourOfDay(23); }//from w ww . j a va 2 s. co m if (time.length < 2 || StringUtils.isBlank(time[1])) { roundedDate = roundedDate.withMinuteOfHour(59); } if (time.length < 3 || StringUtils.isBlank(time[2])) { roundedDate = roundedDate.withSecondOfMinute(59); } return roundedDate; }
From source file:com.splout.db.examples.PageCountsDataGenerator.java
License:Apache License
public void generate(File namesFile, int days, File outFolder) throws IOException { if (outFolder.exists()) { FileUtils.deleteDirectory(outFolder); }/*from w ww . ja v a2 s .com*/ outFolder.mkdirs(); if (!namesFile.exists()) { throw new IllegalArgumentException("Provided names file doesn't exist (" + namesFile + ")"); } List<String> names = Files.readLines(namesFile, Charset.forName("UTF-8")); DateTime today = new DateTime(); DateTime someDaysBefore = today.minusDays(days); someDaysBefore = someDaysBefore.withMinuteOfHour(0); someDaysBefore = someDaysBefore.withSecondOfMinute(0); while (someDaysBefore.isBefore(today)) { for (int hour = 0; hour < 24; hour++) { someDaysBefore = someDaysBefore.withHourOfDay(hour); File currentFile = new File(outFolder, "pagecounts-" + format.print(someDaysBefore)); BufferedWriter writer = new BufferedWriter(new FileWriter(currentFile)); for (String name : names) { int pageviews = (int) (Math.random() * 10000) + 1; writer.write("en " + name + " " + pageviews + " 0" + "\n"); } writer.close(); } someDaysBefore = someDaysBefore.plusDays(1); } }
From source file:de.azapps.mirakel.model.recurring.Recurring.java
License:Open Source License
@NonNull private Optional<DateTime> addRecurring(@NonNull final Optional<DateTime> cal, final boolean onlyOnce) { if (!cal.isPresent()) { return absent(); }/*from w w w.j a v a2 s . co m*/ DateTime c = cal.get(); final DateTime now = new DateTime(); if (isExact()) { c = now; } now.withSecondOfMinute(0); now.withMinuteOfHour(0); final List<Integer> weekdays = getWeekdays(); if (weekdays.isEmpty()) { if ((!getStartDate().isPresent() || now.isAfter(getStartDate().get())) && (!getEndDate().isPresent() || now.isBefore(getEndDate().get()))) { do { c = c.plus(recurringInterval); } while (c.isBefore(now) && !onlyOnce); } } else { int diff = 8; if (c.isBefore(now)) { c = now; } c = c.plusDays(1); for (final Integer day : weekdays) { int local_diff = day - c.getDayOfWeek(); if (local_diff < 0) { local_diff += 7; } if (diff > local_diff) { diff = local_diff; } } c = c.plusDays(diff); } return of(c); }
From source file:dk.dma.epd.common.prototype.gui.nogo.NogoDialogCommon.java
License:Apache License
protected void initGUI() { JPanel contentPanel = new JPanel(); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); JPanel panel = new JPanel(); panel.setBorder(/* ww w . ja v a 2 s .c om*/ new TitledBorder(null, "Area Selection", TitledBorder.LEADING, TitledBorder.TOP, null, null)); panel.setBounds(15, 30, 327, 115); JLabel lblNogoRequest = new JLabel("Nogo Request:"); lblNogoRequest.setBounds(15, 5, 81, 14); lblNogoRequest.setFont(new Font("Tahoma", Font.BOLD, 11)); contentPanel.setLayout(null); panel.setLayout(null); contentPanel.add(panel); btnSelectArea = new JButton("Select Area"); btnSelectArea.setBounds(204, 81, 113, 23); panel.add(btnSelectArea); btnSelectArea.addActionListener(this); nwPtlbl = new JLabel("Select the area you want to request NoGo for"); nwPtlbl.setBounds(10, 26, 300, 14); panel.add(nwPtlbl); nePtlbl = new JLabel(""); nePtlbl.setBounds(176, 26, 141, 14); panel.add(nePtlbl); swPtlbl = new JLabel(""); swPtlbl.setBounds(10, 51, 300, 14); panel.add(swPtlbl); sePtlbl = new JLabel(""); sePtlbl.setBounds(176, 51, 127, 14); panel.add(sePtlbl); contentPanel.add(lblNogoRequest); JPanel panel_1 = new JPanel(); panel_1.setBorder( new TitledBorder(null, "Time Selected", TitledBorder.LEADING, TitledBorder.TOP, null, null)); panel_1.setBounds(15, 156, 327, 94); contentPanel.add(panel_1); panel_1.setLayout(null); JLabel lblNogoBetween = new JLabel("NoGo valid between:"); lblNogoBetween.setBounds(10, 24, 137, 14); panel_1.add(lblNogoBetween); DateTime dateTime = new DateTime(PntTime.getDate()); dateTime = dateTime.withMillisOfSecond(0); dateTime = dateTime.withSecondOfMinute(0); dateTime = dateTime.withMinuteOfHour(0); Date date = new Date(dateTime.getMillis()); Date date48hour = date; Calendar c = Calendar.getInstance(); c.setTime(date48hour); c.add(Calendar.DATE, 2); // number of days to add date48hour = c.getTime(); spinnerTimeStart = new JSpinner(); spinnerTimeEnd = new JSpinner(); spinnerTimeStart.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { if (((Date) spinnerTimeEnd.getValue()).getTime() < ((Date) spinnerTimeStart.getValue()).getTime()) { spinnerTimeEnd.setValue(spinnerTimeStart.getValue()); } calculateSlices(); } }); spinnerTimeEnd.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { calculateSlices(); } }); spinnerTimeStart.setModel(new SpinnerDateModel(date, null, date48hour, Calendar.HOUR)); spinnerTimeStart.setBounds(10, 41, 98, 20); spinnerTimeEnd.setModel(new SpinnerDateModel(date, null, date48hour, Calendar.HOUR)); spinnerTimeEnd.setBounds(10, 64, 98, 20); panel_1.add(spinnerTimeStart); panel_1.add(spinnerTimeEnd); spinnerTimeStart.setEditor(new JSpinner.DateEditor(spinnerTimeStart, "HH:mm-dd-MM-yy")); spinnerTimeEnd.setEditor(new JSpinner.DateEditor(spinnerTimeEnd, "HH:mm-dd-MM-yy")); chckbxUseSlices = new JCheckBox("Use Slices"); chckbxUseSlices.setBounds(153, 24, 97, 23); chckbxUseSlices.addItemListener(this); panel_1.add(chckbxUseSlices); minuteSlices = new JComboBox<Integer>(); minuteSlices.setModel(new DefaultComboBoxModel<Integer>(new Integer[] { 10, 20, 30, 40, 50, 60 })); minuteSlices.setEnabled(false); minuteSlices.setBounds(155, 49, 43, 20); panel_1.add(minuteSlices); minuteSlices.addItemListener(this); JLabel lblMinutes = new JLabel("Minutes"); lblMinutes.setBounds(208, 49, 46, 14); panel_1.add(lblMinutes); slicesCount = new JLabel(""); slicesCount.setBounds(153, 72, 165, 14); panel_1.add(slicesCount); JPanel panel_2 = new JPanel(); panel_2.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Depth Contour", TitledBorder.LEADING, TitledBorder.TOP, null, null)); panel_2.setBounds(15, 259, 327, 114); contentPanel.add(panel_2); panel_2.setLayout(null); JLabel lblNewLabel = new JLabel("Ship Draft in meters:"); lblNewLabel.setBounds(12, 26, 139, 16); panel_2.add(lblNewLabel); SpinnerNumberModel m_numberSpinnerModel; Double current = new Double(5.50); Double min = new Double(0.00); Double max = new Double(1000.00); Double step = new Double(0.50); m_numberSpinnerModel = new SpinnerNumberModel(current, min, max, step); spinnerDraught = new JSpinner(m_numberSpinnerModel); spinnerDraught.setBounds(252, 24, 38, 20); spinnerDraught.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { updateTotalDepthLabel(); } }); panel_2.add(spinnerDraught); JLabel lblDesiredUnderKeel = new JLabel("Desired Under Keel Clearance (UKC) in meters:"); lblDesiredUnderKeel.setBounds(12, 53, 224, 14); panel_2.add(lblDesiredUnderKeel); JLabel lblTotalDepthIn = new JLabel("Total Depth in meters:"); lblTotalDepthIn.setBounds(10, 78, 226, 14); panel_2.add(lblTotalDepthIn); depthTxt = new JLabel(""); depthTxt.setBounds(257, 78, 65, 14); panel_2.add(depthTxt); SpinnerNumberModel ukcSpinnerModel = new SpinnerNumberModel(1.0, 0.0, 1000.0, 0.50); spinnerUKC = new JSpinner(); spinnerUKC.setModel(ukcSpinnerModel); spinnerUKC.setBounds(252, 55, 38, 20); spinnerUKC.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { updateTotalDepthLabel(); } }); panel_2.add(spinnerUKC); { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { requestNogo = new JButton("Request NoGo"); requestNogo.addActionListener(this); buttonPane.add(requestNogo); getRootPane().setDefaultButton(requestNogo); } { cancelButton = new JButton("Cancel"); cancelButton.addActionListener(this); buttonPane.add(cancelButton); } } // if (ownShipHandler != null && ownShipHandler.getStaticData() != null) { // // int shipDraught = (int) ownShipHandler.getStaticData().getDraught(); // // // System.out.println("Pure value is " + ownShipHandler.getStaticData().getDraught()); // double draught = shipDraught / 10.0; // // System.out.println("Draught is " + draught); // spinnerDraught.setValue(draught); // // } updateTotalDepthLabel(); }
From source file:dk.dma.epd.common.prototype.model.voct.SARISXMLParser.java
License:Apache License
private SARWeatherData getSingleSARWeatherData(Node node) throws XPathExpressionException { Element el = (Element) node; NodeList children = el.getChildNodes(); Node timeEntry = children.item(1); Element timeElement = (Element) timeEntry; NodeList timeNodes = timeElement.getChildNodes(); DateTime windEntryDate = new DateTime(); // Day 0/* w w w. j a va2 s . co m*/ windEntryDate = windEntryDate .withDayOfMonth(Integer.parseInt(timeNodes.item(0).getFirstChild().getNodeValue())); // Month 2 windEntryDate = windEntryDate .withMonthOfYear(Integer.parseInt(timeNodes.item(2).getFirstChild().getNodeValue())); // Year 4 windEntryDate = windEntryDate.withYear(Integer.parseInt(timeNodes.item(4).getFirstChild().getNodeValue())); // hour 6 windEntryDate = windEntryDate .withHourOfDay(Integer.parseInt(timeNodes.item(6).getFirstChild().getNodeValue())); // minute 8 windEntryDate = windEntryDate .withMinuteOfHour(Integer.parseInt(timeNodes.item(8).getFirstChild().getNodeValue())); // second 10 windEntryDate = windEntryDate .withSecondOfMinute(Integer.parseInt(timeNodes.item(10).getFirstChild().getNodeValue())); Node windEntry = children.item(3); Element windElements = (Element) windEntry; NodeList windNodes = windElements.getChildNodes(); System.out.println(windElements.getFirstChild().getNodeValue()); for (int k = 0; k < windNodes.getLength(); k++) { System.out.println("k is " + k); Node child2 = windNodes.item(k); System.out.println("Child2 name is " + child2.getNodeName()); if (child2.getNodeType() != Node.TEXT_NODE) { System.out.println("child tag: " + child2.getNodeName()); if (child2.getFirstChild().getNodeType() == Node.TEXT_NODE) { System.out.println("inner child value:" + child2.getFirstChild().getNodeValue()); } } } // System.out.println(node.getChildNodes()); // Get time // System.out.println(getDateFromNodeList(node.getChildNodes().item(1).getChildNodes())); // System.out.println(node.getChildNodes().item(1).getChildNodes().item(0).getChildNodes().item(0).getNodeValue()); // Wind values // System.out.println(node.getChildNodes().item(3)); // for (int i = 0; i < node.getChildNodes().getLength(); i++) { // System.out.println(node.getChildNodes().item(i).getChildNodes().item(1)); // } return null; }
From source file:dk.dma.epd.common.prototype.model.voct.SARISXMLParser.java
License:Apache License
private DateTime getDateFromNodeList(NodeList nodeList) { DateTime returnDate = new DateTime(); if (nodeList.getLength() == 0) { return null; }/* w ww .j a v a 2 s. com*/ if (nodeList.item(0).getNodeName().equals("day")) { // Day returnDate = returnDate .withDayOfMonth(Integer.parseInt(nodeList.item(0).getFirstChild().getNodeValue())); // System.out.println("DAY"); } if (nodeList.item(1).getNodeName().equals("month")) { // Month returnDate = returnDate .withMonthOfYear(Integer.parseInt(nodeList.item(1).getFirstChild().getNodeValue())); // System.out.println("MONTH"); } if (nodeList.item(2).getNodeName().equals("year")) { // Year returnDate = returnDate.withYear(Integer.parseInt(nodeList.item(2).getFirstChild().getNodeValue())); // System.out.println("YEAR"); } if (nodeList.item(3).getNodeName().equals("hour")) { // Hour returnDate = returnDate .withHourOfDay(Integer.parseInt(nodeList.item(3).getFirstChild().getNodeValue())); // System.out.println("HOUR"); } if (nodeList.item(4).getNodeName().equals("minute")) { // Minute returnDate = returnDate .withMinuteOfHour(Integer.parseInt(nodeList.item(4).getFirstChild().getNodeValue())); // System.out.println("MINUTE"); } if (nodeList.item(5).getNodeName().equals("second")) { // Second returnDate = returnDate .withSecondOfMinute(Integer.parseInt(nodeList.item(5).getFirstChild().getNodeValue())); // System.out.println("SECOND"); } return returnDate; }
From source file:io.apiman.manager.api.core.metrics.AbstractMetricsAccessor.java
License:Apache License
/** * Based on the given interval, create a "floor" value relative to the * given date. This basically means zero'ing out certain fields (different * fields based on the interval type) and returning the modified date. * @param date/* ww w . j a v a2s. c om*/ * @param interval */ protected static DateTime floor(DateTime date, HistogramIntervalType interval) { DateTime rval = date.withMillisOfSecond(0); switch (interval) { case day: rval = rval.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0); break; case hour: rval = rval.withMinuteOfHour(0).withSecondOfMinute(0); break; case minute: rval = rval.withSecondOfMinute(0); break; case month: rval = rval.withDayOfMonth(1).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0); break; case week: rval = rval.withDayOfWeek(DateTimeConstants.MONDAY).withHourOfDay(0).withMinuteOfHour(0) .withSecondOfMinute(0); break; } return rval; }
From source file:net.sourceforge.fenixedu.domain.EnrolmentEvaluation.java
License:Open Source License
@Override public void setExamDateYearMonthDay(YearMonthDay evaluationDateYearMonthDay) { if (evaluationDateYearMonthDay != null) { final Enrolment enrolment = getEnrolment(); final Thesis thesis = enrolment.getThesis(); if (thesis != null) { DateTime newDateTime = evaluationDateYearMonthDay.toDateTimeAtMidnight(); final DateTime dateTime = thesis.getDiscussed(); if (dateTime != null) { newDateTime = newDateTime.withHourOfDay(dateTime.getHourOfDay()); newDateTime = newDateTime.withMinuteOfHour(dateTime.getMinuteOfHour()); }//www . j a v a2 s . c o m thesis.setDiscussed(newDateTime); } } super.setExamDateYearMonthDay(evaluationDateYearMonthDay); }