Example usage for org.joda.time DateTime withSecondOfMinute

List of usage examples for org.joda.time DateTime withSecondOfMinute

Introduction

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

Prototype

public DateTime withSecondOfMinute(int second) 

Source Link

Document

Returns a copy of this datetime with the second of minute field updated.

Usage

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);
    }// w  ww .j av  a 2  s.  c  o 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.sonicle.webtop.calendar.CalendarManager.java

License:Open Source License

@Override
public List<SchedEventInstance> listUpcomingEventInstances(Collection<Integer> calendarIds, DateTime now,
        int days, Condition<EventQuery> conditionPredicate, DateTimeZone targetTimezone) throws WTException {
    if (days > 15)
        days = 15;// ww  w.  j  a va  2s. c  o m
    DateTimeRange range = new DateTimeRange(
            now.withSecondOfMinute(0).withMillisOfSecond(0).withZone(targetTimezone),
            now.withTimeAtStartOfDay().plusDays(days));
    return listEventInstances(calendarIds, range, conditionPredicate, targetTimezone, true);
}

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);
    }// www .ja v a2  s . c  o m
    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:com.thinkbiganalytics.metadata.cache.util.TimeUtil.java

License:Apache License

public static Long getTimeNearestFiveSeconds() {
    DateTime dt = new DateTime().withMillisOfSecond(0);
    int seconds = dt.getSecondOfMinute();
    if (seconds % 5 > 0) {
        dt = dt.withSecondOfMinute(seconds - (seconds % 5));
    }//  www . j  a v a2 s . com
    return dt.getMillis();

}

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  a 2  s  .c  o 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(//from w  ww .  ja  v a 2s  . c o  m
            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/*from  ww  w.j  av  a2  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 w w.  jav  a  2 s.c  om

    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:dk.teachus.utils.PeriodComparator.java

License:Apache License

private DateTime convertAndReset(LocalTime date) {
    DateMidnight now = new DateMidnight();
    DateTime dateTime = date.toDateTime(now);
    dateTime = dateTime.withSecondOfMinute(0);
    dateTime = dateTime.withMillisOfSecond(0);

    return dateTime;
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.DateTimeWithPrecisionVTwo.java

License:Open Source License

private Map<String, String> checkDate(String precisionURI, Map<String, String[]> qp) {
    if (precisionURI == null)
        return Collections.emptyMap();

    Map<String, String> errors = new HashMap<String, String>();

    Integer year, month, day, hour, minute, second;

    //just check if the values for the precision parse to integers
    if (precisionURI.equals(VitroVocabulary.Precision.YEAR.uri())) {
        if (!canParseToNumber(getFieldName() + "-year", qp))
            errors.put(getFieldName() + "-year", NON_INTEGER_YEAR);
    } else if (precisionURI.equals(VitroVocabulary.Precision.MONTH.uri())) {
        if (!canParseToNumber(getFieldName() + "-year", qp))
            errors.put(getFieldName() + "-year", NON_INTEGER_YEAR);
        if (!canParseToNumber(getFieldName() + "-month", qp))
            errors.put(getFieldName() + "-month", NON_INTEGER_MONTH);
    } else if (precisionURI.equals(VitroVocabulary.Precision.DAY.uri())) {
        if (!canParseToNumber(getFieldName() + "-year", qp))
            errors.put(getFieldName() + "-year", NON_INTEGER_YEAR);
        if (!canParseToNumber(getFieldName() + "-month", qp))
            errors.put(getFieldName() + "-month", NON_INTEGER_MONTH);
        if (!canParseToNumber(getFieldName() + "-day", qp))
            errors.put(getFieldName() + "-day", NON_INTEGER_DAY);
    } else if (precisionURI.equals(VitroVocabulary.Precision.HOUR.uri())) {
        if (!canParseToNumber(getFieldName() + "-year", qp))
            errors.put(getFieldName() + "-year", NON_INTEGER_YEAR);
        if (!canParseToNumber(getFieldName() + "-month", qp))
            errors.put(getFieldName() + "-month", NON_INTEGER_MONTH);
        if (!canParseToNumber(getFieldName() + "-day", qp))
            errors.put(getFieldName() + "-day", NON_INTEGER_DAY);
        if (!canParseToNumber(getFieldName() + "-hour", qp))
            errors.put(getFieldName() + "-hour", NON_INTEGER_HOUR);
    } else if (precisionURI.equals(VitroVocabulary.Precision.MINUTE.uri())) {
        if (!canParseToNumber(getFieldName() + "-year", qp))
            errors.put(getFieldName() + "-year", NON_INTEGER_YEAR);
        if (!canParseToNumber(getFieldName() + "-month", qp))
            errors.put(getFieldName() + "-month", NON_INTEGER_MONTH);
        if (!canParseToNumber(getFieldName() + "-day", qp))
            errors.put(getFieldName() + "-day", NON_INTEGER_DAY);
        if (!canParseToNumber(getFieldName() + "-hour", qp))
            errors.put(getFieldName() + "-hour", NON_INTEGER_HOUR);
        if (!canParseToNumber(getFieldName() + "-minute", qp))
            errors.put(getFieldName() + "-minute", NON_INTEGER_HOUR);
    } else if (precisionURI.equals(VitroVocabulary.Precision.SECOND.uri())) {
        if (!canParseToNumber(getFieldName() + "-year", qp))
            errors.put(getFieldName() + "-year", NON_INTEGER_YEAR);
        if (!canParseToNumber(getFieldName() + "-month", qp))
            errors.put(getFieldName() + "-month", NON_INTEGER_MONTH);
        if (!canParseToNumber(getFieldName() + "-day", qp))
            errors.put(getFieldName() + "-day", NON_INTEGER_DAY);
        if (!canParseToNumber(getFieldName() + "-hour", qp))
            errors.put(getFieldName() + "-hour", NON_INTEGER_HOUR);
        if (!canParseToNumber(getFieldName() + "-minute", qp))
            errors.put(getFieldName() + "-minute", NON_INTEGER_HOUR);
        if (!canParseToNumber(getFieldName() + "-second", qp))
            errors.put(getFieldName() + "-second", NON_INTEGER_SECOND);
    }/*  w  w w  .ja  va2  s . c o  m*/

    //check if we can make a valid date with these integers
    year = parseToInt(getFieldName() + "-year", qp);
    if (year == null)
        year = 1999;
    month = parseToInt(getFieldName() + "-month", qp);
    if (month == null)
        month = 1;
    day = parseToInt(getFieldName() + "-day", qp);
    if (day == null)
        day = 1;
    hour = parseToInt(getFieldName() + "-hour", qp);
    if (hour == null)
        hour = 0;
    minute = parseToInt(getFieldName() + "-minute", qp);
    if (minute == null)
        minute = 0;
    second = parseToInt(getFieldName() + "-second", qp);
    if (second == null)
        second = 0;

    //initialize to something so that we can be assured not to get 
    //system date dependent behavior
    DateTime dateTime = new DateTime("1970-01-01T00:00:00Z");

    try {
        dateTime = dateTime.withYear(year);
    } catch (IllegalArgumentException iae) {
        errors.put(getFieldName() + "-year", iae.getLocalizedMessage());
    }
    try {
        dateTime = dateTime.withMonthOfYear(month);
    } catch (IllegalArgumentException iae) {
        errors.put(getFieldName() + "-month", iae.getLocalizedMessage());
    }
    try {
        dateTime = dateTime.withDayOfMonth(day);
    } catch (IllegalArgumentException iae) {
        errors.put(getFieldName() + "-day", iae.getLocalizedMessage());
    }
    try {
        dateTime = dateTime.withHourOfDay(hour);
    } catch (IllegalArgumentException iae) {
        errors.put(getFieldName() + "-hour", iae.getLocalizedMessage());
    }
    try {
        dateTime = dateTime.withSecondOfMinute(second);
    } catch (IllegalArgumentException iae) {
        errors.put(getFieldName() + "-second", iae.getLocalizedMessage());
    }

    return errors;
}