Example usage for org.joda.time DateTime getYear

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

Introduction

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

Prototype

public int getYear() 

Source Link

Document

Get the year field value.

Usage

From source file:br.com.moonjava.flight.util.VerifierString.java

License:Apache License

public static boolean isDateValid(String word, ResourceBundle bundle) {
    boolean birthDay = false;
    String country = bundle.getString("country");
    DateTime date = FormatDateTimeDesk.parseToDateTime(word, country);
    boolean leapYear = new GregorianCalendar().isLeapYear(date.getYear());

    // US MM/DD/YYYY
    if (country.equals("US")) {
        // No pode conter 30 e 31 em fevereiro e nem ser maior que a data atual
        if (!word.startsWith("02/30") && !word.startsWith("02/31")) {
            // Se for bissexto deve considerar 02/29
            if (word.startsWith("02/29") && leapYear || !word.startsWith("02/29")) {
                Pattern pattern = Pattern.compile(
                        "(0[1-9]|1[012])/(0[1-9]|[12][0-9]|3[01])/((19|20)\\d\\d) (0[0-9]|1[0-9]|2[0-4]):([0-5][0-9])");
                Matcher matcher = pattern.matcher(word);
                birthDay = matcher.find();
            }/*from w  ww.  j av a  2s . com*/

        }

        // BR DD/MM/YYYY
    } else {
        if (!word.startsWith("30/02") && !word.startsWith("31/02")) {
            // No pode conter 30 e 31 em fevereiro e nem ser maior que a data atual
            if (word.startsWith("29/02") && leapYear || !word.startsWith("29/02")) {
                // Se for bissexto deve considerar 29/02
                Pattern pattern = Pattern.compile(
                        "(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/((19|20)\\d\\d) (0[0-9]|1[0-9]|2[0-4]):([0-5][0-9])");
                Matcher matcher = pattern.matcher(word);
                birthDay = matcher.find();
            }
        }
    }

    return birthDay;
}

From source file:ca.uwaterloo.cs.cs349.mikrocalendar.ui.datetimepicker.DateTimePickerDialog.java

License:Open Source License

/**
 * Creates a new {@link DateTimePickerDialog} with a specified
 * {@link DateTime}.//from w  ww  .  j  ava2s .  c  o m
 * 
 * @param dateTime
 *            The {@link DateTime}.
 */
public DateTimePickerDialog(DateTime dateTime) {
    super((Frame) null, true);
    setTitle("Date Time Picker");

    this.dateTime = dateTime;

    // Array of selectable months.
    String[] months = new String[] { null, "January", "February", "March", "April", "May", "June", "July",
            "August", "September", "October", "November", "December" };

    // Array of selectable days.
    Integer days[] = new Integer[32];
    days[0] = null;
    for (int i = 1; i < days.length; i++) {
        days[i] = new Integer(i);
    }

    // Array of selectable hours.
    Integer hours[] = new Integer[24];
    for (int i = 0; i < hours.length; i++) {
        hours[i] = new Integer(i);
    }

    // Array of selectable minutes.
    Integer minutes[] = new Integer[60];
    for (int i = 0; i < minutes.length; i++) {
        minutes[i] = new Integer(i);
    }

    // Date time fields.
    monthComboBox = new JComboBox(months);
    dayComboBox = new JComboBox(days);
    yearTextField = new JTextField();
    yearTextField.setPreferredSize(new Dimension(40, (int) yearTextField.getPreferredSize().getHeight()));
    hourComboBox = new JComboBox(hours);
    minuteComboBox = new JComboBox(minutes);

    if (dateTime == null) {
        monthComboBox.setSelectedIndex(0);
        dayComboBox.setSelectedIndex(0);
        yearTextField.setText(null);
        hourComboBox.setSelectedIndex(0);
        minuteComboBox.setSelectedIndex(0);
    } else {
        monthComboBox.setSelectedIndex(dateTime.getMonthOfYear());
        dayComboBox.setSelectedIndex(dateTime.getDayOfMonth());
        yearTextField.setText(String.valueOf(dateTime.getYear()));
        hourComboBox.setSelectedIndex(dateTime.getHourOfDay());
        minuteComboBox.setSelectedIndex(dateTime.getMinuteOfHour());
    }

    // Labels to indicate what each field is for.
    JLabel monthLabel = new JLabel("Month");
    JLabel dayLabel = new JLabel("Day");
    JLabel yearLabel = new JLabel("Year");
    JLabel hourLabel = new JLabel("Hour");
    JLabel minuteLabel = new JLabel("Minute");

    // Main panel.
    final JPanel dateTimePanel = new JPanel(new SpringLayout());
    dateTimePanel.add(monthLabel);
    dateTimePanel.add(dayLabel);
    dateTimePanel.add(yearLabel);
    dateTimePanel.add(hourLabel);
    dateTimePanel.add(minuteLabel);
    dateTimePanel.add(monthComboBox);
    dateTimePanel.add(dayComboBox);
    dateTimePanel.add(yearTextField);
    dateTimePanel.add(hourComboBox);
    dateTimePanel.add(minuteComboBox);

    final ActionListener validateListener = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            validateFields();
        }
    };

    // Add listeners to the date time fields which enable or disable
    // the OK button.
    monthComboBox.addActionListener(validateListener);
    dayComboBox.addActionListener(validateListener);
    yearTextField.addActionListener(validateListener);
    hourComboBox.addActionListener(validateListener);
    dayComboBox.addActionListener(validateListener);

    // Reposition components for a better look.
    SpringUtilities.makeCompactGrid(dateTimePanel, 2, 5, 10, 10, 10, 10);

    // Create buttons.
    cancelButton = new JButton("Cancel");
    okButton = new JButton("OK");
    JButton resetButton = new JButton(new AbstractAction("Reset") {

        @Override
        public void actionPerformed(ActionEvent e) {
            resetFields();
        }
    });

    // Add buttons to panel.
    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
    buttonPanel.add(Box.createHorizontalGlue());
    buttonPanel.add(resetButton);
    buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPanel.add(cancelButton);
    buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPanel.add(okButton);

    getContentPane().add(dateTimePanel, BorderLayout.CENTER);
    getContentPane().add(buttonPanel, BorderLayout.PAGE_END);

    // Set fields to the date time that was passed into the constructor.
    resetFields();
}

From source file:calculadora.CalculadoraDeHoras.java

License:Apache License

private boolean forDiferente(DateTime inicial, DateTime finall) {

    if (inicial.getHourOfDay() != finall.getHourOfDay() && inicial.getHourOfDay() < finall.getHourOfDay())
        return true;
    if (inicial.getDayOfMonth() != finall.getDayOfMonth())
        return true;
    if (inicial.getMonthOfYear() != finall.getMonthOfYear())
        return true;
    if (inicial.getYear() != finall.getYear())
        return true;
    return false;
}

From source file:cd.education.data.collector.android.widgets.DateTimeWidget.java

License:Apache License

private void setAnswer() {

    if (mPrompt.getAnswerValue() != null) {

        DateTime ldt = new DateTime(((Date) ((DateTimeData) mPrompt.getAnswerValue()).getValue()).getTime());
        mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener);
        mTimePicker.setCurrentHour(ldt.getHourOfDay());
        mTimePicker.setCurrentMinute(ldt.getMinuteOfHour());

    } else {/*from   w ww .  j av  a  2 s . c o  m*/
        // create time widget with current time as of right now
        clearAnswer();
    }
}

From source file:cd.education.data.collector.android.widgets.DateTimeWidget.java

License:Apache License

/**
 * Resets date to today./*from w  w  w . ja  va  2s  . c om*/
 */
@Override
public void clearAnswer() {
    DateTime ldt = new DateTime();
    mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener);
    mTimePicker.setCurrentHour(ldt.getHourOfDay());
    mTimePicker.setCurrentMinute(ldt.getMinuteOfHour());
}

From source file:cd.education.data.collector.android.widgets.DateWidget.java

License:Apache License

private void setAnswer() {

    if (mPrompt.getAnswerValue() != null) {
        DateTime ldt = new DateTime(((Date) ((DateData) mPrompt.getAnswerValue()).getValue()).getTime());
        mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener);
    } else {//  w w w. j  ava 2 s.  c om
        // create date widget with current time as of right now
        clearAnswer();
    }
}

From source file:cd.education.data.collector.android.widgets.DateWidget.java

License:Apache License

/**
 * Resets date to today.//from  w  w w .  ja v a2  s.c o  m
 */
@Override
public void clearAnswer() {
    DateTime ldt = new DateTime();
    mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener);
}

From source file:ch.opentrainingcenter.model.training.filter.internal.FilterTrainingByDate.java

License:Open Source License

private long round(final Date date, final int hour, final int minute) {
    final DateTime dtStart = new DateTime(date);
    final int year = dtStart.getYear();
    final int monthOfYear = dtStart.getMonthOfYear();
    final int dayOfYear = dtStart.getDayOfMonth();
    final DateTime dt = new DateTime(year, monthOfYear, dayOfYear, hour, minute);
    return dt.getMillis();
}

From source file:cherry.goods.util.JodaTimeUtil.java

License:Apache License

/**
 * @param dtm ???{@link DateTime}//from www. j a  va 2s . c o  m
 * @return ?????{@link Calendar}(?{@link DateTime}??)????????????
 */
public static Calendar getCalendar(DateTime dtm) {
    Calendar cal = Calendar.getInstance(dtm.getZone().toTimeZone());
    cal.set(dtm.getYear(), dtm.getMonthOfYear() - 1, dtm.getDayOfMonth(), dtm.getHourOfDay(),
            dtm.getMinuteOfHour(), dtm.getSecondOfMinute());
    cal.set(MILLISECOND, dtm.getMillisOfSecond());
    return cal;
}

From source file:com.addthis.hydra.job.spawn.SpawnFormattedLogger.java

License:Apache License

private Bundle initBundle(EventType event) {
    assert (bundleLog != null);
    Bundle bundle = bundleLog.createBundle();
    bundleSetValue(bundle, "CLUSTER", clusterName);
    bundleSetValue(bundle, "EVENT_TYPE", event.toString());
    long time = JitterClock.globalTime();
    DateTime dateTime = new DateTime(time);
    bundleSetValue(bundle, "TIME", time);
    bundleSetValue(bundle, "DATE_YEAR", dateTime.getYear());
    bundleSetValue(bundle, "DATE_MONTH", dateTime.getMonthOfYear());
    bundleSetValue(bundle, "DATE_DAY", dateTime.getDayOfMonth());
    bundleSetValue(bundle, "FILE_PREFIX_HOUR", "logger-" + String.format("%02d", dateTime.getHourOfDay()));
    return bundle;
}