Example usage for org.joda.time DateTime withMillisOfSecond

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

Introduction

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

Prototype

public DateTime withMillisOfSecond(int millis) 

Source Link

Document

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

Usage

From source file:com.github.dbourdette.otto.source.TimeFrame.java

License:Apache License

private DateTime oneDay(DateTime dateTime) {
    dateTime = dateTime.withMillisOfSecond(0);
    dateTime = dateTime.withSecondOfMinute(0);
    dateTime = dateTime.withMinuteOfHour(0);
    return dateTime.withHourOfDay(0);
}

From source file:com.pushinginertia.commons.domain.util.EmailSubscriptionUtils.java

License:Open Source License

/**
 * Calculates the next notification date as the last notification date plus the notification interval. If no
 * last notification date is given, then the calculated date is based on the current time plus the notification
 * interval.// w w w  .  j  av a2 s . com
 * @param lastNotificationTimestamp null is ok
 * @param notificationInterval number of days
 * @return calculated date/time
 */
public static DateTime calculateNextNotificationTimestamp(final DateTime lastNotificationTimestamp,
        final int notificationInterval) {
    if (lastNotificationTimestamp == null) {
        return DateTime.now().withMillisOfSecond(0).plusDays(notificationInterval);
    }

    return lastNotificationTimestamp.withMillisOfSecond(0).plusDays(notificationInterval);
}

From source file:com.qcadoo.localization.api.utils.DateUtils.java

License:Open Source License

private static DateTime round(final DateTime dateTime, final boolean upComplete, final String[] dateAndTime) {
    if (!upComplete) {
        return dateTime;
    }//  ww  w. j  ava  2  s  .  com

    DateTime roundedDateTime = dateTime;
    if (dateAndTime.length > 0 && StringUtils.isNotBlank(dateAndTime[0])) {
        roundedDateTime = roundUpDate(roundedDateTime, dateAndTime[0]);
        if (dateAndTime.length > 1 && StringUtils.isNotBlank(dateAndTime[1])) {
            roundedDateTime = roundUpTime(roundedDateTime, dateAndTime[1]);
        } else {
            roundedDateTime = roundedDateTime.withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59);
        }
    }

    return roundedDateTime.withMillisOfSecond(999);
}

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   ww w .j a v  a  2 s . 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.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: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//w w w . j  a  va  2s . c  o  m
 * @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:kr.debop4j.timeperiod.tools.Times.java

License:Apache License

/**
 * Trim to millis.//from  w w w.ja v a 2s  . c  o m
 *
 * @param moment         the moment
 * @param millisOfSecond the millis of second
 * @return the date time
 */
public static DateTime trimToMillis(DateTime moment, int millisOfSecond) {
    return moment.withMillisOfSecond(millisOfSecond);
}

From source file:org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral.java

License:Apache License

public KiWiDateLiteral(DateTime dateContent, KiWiUriResource type) {
    super(DateUtils.getXMLCalendar(dateContent.withMillisOfSecond(0)).toXMLFormat(), null, type);
    setDateContent(dateContent);/* www  .ja  va2  s  .  c  om*/
}

From source file:org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral.java

License:Apache License

public KiWiDateLiteral(DateTime dateContent, KiWiUriResource type, Date created) {
    super(DateUtils.getXMLCalendar(dateContent.withMillisOfSecond(0)).toXMLFormat(), null, type, created);
    setDateContent(dateContent);/*from  w  w w .  j ava 2  s  .  c om*/
}

From source file:org.apache.marmotta.kiwi.model.rdf.KiWiDateLiteral.java

License:Apache License

public void setDateContent(DateTime dateContent) {
    this.dateContent = dateContent.withMillisOfSecond(0);
    if (XSD.DateTime.equals(getDatatype())) {
        this.content = DateUtils.getXMLCalendar(this.dateContent).toXMLFormat();
    } else if (XSD.Date.equals(getDatatype())) {
        this.content = ISODateTimeFormat.date().print(dateContent);
    } else if (XSD.Time.equals(getDatatype())) {
        this.content = ISODateTimeFormat.time().print(dateContent);
    }/*from   w w  w. java 2s  . c  om*/
}