List of usage examples for org.joda.time DateTime getDayOfMonth
public int getDayOfMonth()
From source file:app.rappla.calendar.Date.java
License:Open Source License
/** * Constructor/*from ww w . j a va 2 s . co m*/ * * @param icalStr * One or more lines of iCalendar that specifies a date * @param parseMode * PARSE_STRICT or PARSE_LOOSE */ public Date(String icalStr) throws ParseException, BogusDataException { super(icalStr); year = month = day = 0; hour = minute = second = 0; for (int i = 0; i < attributeList.size(); i++) { Attribute a = attributeAt(i); String aname = a.name.toUpperCase(Locale.ENGLISH); String aval = a.value.toUpperCase(Locale.ENGLISH); // TODO: not sure if any attributes are allowed here... // Look for VALUE=DATE or VALUE=DATE-TIME // DATE means untimed for the event if (aname.equals("VALUE")) { if (aval.equals("DATE")) { dateOnly = true; } else if (aval.equals("DATE-TIME")) { dateOnly = false; } } else if (aname.equals("TZID")) { tzid = a.value; } else { // TODO: anything else allowed here? } } String inDate = value; if (inDate.length() < 8) { // Invalid format throw new ParseException("Invalid date format '" + inDate + "'", inDate); } // Make sure all parts of the year are numeric. for (int i = 0; i < 8; i++) { char ch = inDate.charAt(i); if (ch < '0' || ch > '9') { throw new ParseException("Invalid date format '" + inDate + "'", inDate); } } year = Integer.parseInt(inDate.substring(0, 4)); month = Integer.parseInt(inDate.substring(4, 6)); day = Integer.parseInt(inDate.substring(6, 8)); if (day < 1 || day > 31 || month < 1 || month > 12) throw new BogusDataException("Invalid date '" + inDate + "'", inDate); // Make sure day of month is valid for specified month if (year % 4 == 0) { // leap year if (day > leapMonthDays[month - 1]) { throw new BogusDataException("Invalid day of month '" + inDate + "'", inDate); } } else { if (day > monthDays[month - 1]) { throw new BogusDataException("Invalid day of month '" + inDate + "'", inDate); } } // TODO: parse time, handle localtime, handle timezone if (inDate.length() > 8) { // TODO make sure dateOnly == false if (inDate.charAt(8) == 'T') { try { hour = Integer.parseInt(inDate.substring(9, 11)); minute = Integer.parseInt(inDate.substring(11, 13)); second = Integer.parseInt(inDate.substring(13, 15)); if (hour > 23 || minute > 59 || second > 59) { throw new BogusDataException("Invalid time in date string '" + inDate + "'", inDate); } if (inDate.length() > 15) { isUTC = inDate.charAt(15) == 'Z'; } } catch (NumberFormatException nef) { throw new BogusDataException("Invalid time in date string '" + inDate + "' - " + nef, inDate); } } else { // Invalid format throw new ParseException("Invalid date format '" + inDate + "'", inDate); } } else { // Just date, no time dateOnly = true; } if (isUTC && !dateOnly) { // Use Joda Time to convert UTC to localtime DateTime utcDateTime = new DateTime(DateTimeZone.UTC); utcDateTime = utcDateTime.withDate(year, month, day).withTime(hour, minute, second, 0); DateTime localDateTime = utcDateTime.withZone(DateTimeZone.getDefault()); year = localDateTime.getYear(); month = localDateTime.getMonthOfYear(); day = localDateTime.getDayOfMonth(); hour = localDateTime.getHourOfDay(); minute = localDateTime.getMinuteOfHour(); second = localDateTime.getSecondOfMinute(); } else if (tzid != null) { DateTimeZone tz = DateTimeZone.forID(tzid); if (tz != null) { // Convert to localtime DateTime utcDateTime = new DateTime(tz); utcDateTime = utcDateTime.withDate(year, month, day).withTime(hour, minute, second, 0); DateTime localDateTime = utcDateTime.withZone(DateTimeZone.getDefault()); year = localDateTime.getYear(); month = localDateTime.getMonthOfYear(); day = localDateTime.getDayOfMonth(); hour = localDateTime.getHourOfDay(); minute = localDateTime.getMinuteOfHour(); second = localDateTime.getSecondOfMinute(); // Since we have converted to localtime, remove the TZID // attribute this.removeNamedAttribute("TZID"); } } isUTC = false; // Add attribute that says date-only or date with time if (dateOnly) addAttribute("VALUE", "DATE"); else addAttribute("VALUE", "DATE-TIME"); }
From source file:br.edu.utfpr.cm.JGitMinerWeb.services.metric.auxiliary.AuxCoChangeMetrics.java
private Integer getDayOfMonth(DateTime dateFile) { return dateFile.getDayOfMonth(); }
From source file:br.edu.utfpr.cm.JGitMinerWeb.services.metric.social.TimeMetric.java
public void calculateMetric(AuxAllMetrics pairOfFile, DateTime being, DateTime end) { List<AuxCountTimeMetrics> timeMetricsList = new ArrayList<>(); // if (result.containsKey(pairOfFiles.getAuxPairOfFiles())) { // timeMetricsList = result.get(pairOfFiles.getAuxPairOfFiles()); // } else { // timeMetricsList = new ArrayList<>(); // }/*from ww w .java 2s . c o m*/ PeriodOfDayCount periodOfDayCount = new PeriodOfDayCount(); DayOfWeekCount dayOfWeekCount = new DayOfWeekCount(); DayOfMonthCount dayOfMonthCount = new DayOfMonthCount(); MonthCount monthCount = new MonthCount(); // if (isBetweenDate(pairOfFiles.getDateFile1(), being, end)) { if (!pairOfFile.getRepoCommits_idList().isEmpty()) { for (EntityRepositoryCommit repoCommit : pairOfFile.getRepoCommits()) { DateTime repoCommitDate = new DateTime(repoCommit.getCommit().getAuthor().getDateCommitUser(), DateTimeZone.UTC); if (isBetweenDate(repoCommitDate, being, end)) { periodOfDayCount.countPeriodOfDay(getPeriodOfDay(repoCommitDate)); dayOfWeekCount.countDayOfWeek(repoCommitDate.getDayOfWeek()); dayOfMonthCount.countDayOfMonth(repoCommitDate.getDayOfMonth()); monthCount.countMonth(repoCommitDate.getMonthOfYear()); } } } // periodOfDayCount.countPeriodOfDay(pairOfFiles.getPedriodOfDayFile1()); // dayOfWeekCount.countDayOfWeek(pairOfFiles.getDayOfWeekFile1()); // dayOfMonthCount.countDayOfMonth(pairOfFiles.getDayOfMonthFile1()); // monthCount.countMonth(pairOfFiles.getMonthOfModFile1()); AuxCountTimeMetrics timeMetrics = new AuxCountTimeMetrics(periodOfDayCount, dayOfWeekCount, dayOfMonthCount, monthCount); timeMetricsList.add(timeMetrics); // } result.put(pairOfFile.getId(), timeMetricsList); }
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}./*w ww . j a v a2 s. co 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:calendario.service.Day.java
public Day(DateTime dt) { this.day = dt.getDayOfMonth() + ""; this.dayOfWeekShort = dt.dayOfWeek().getAsShortText(); }
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 ww w .j av a2 s . c om // 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 . j a va 2s. c o m*/ */ @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 {//from w ww . java 2s.com // 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./* ww w . j a va 2 s.com*/ */ @Override public void clearAnswer() { DateTime ldt = new DateTime(); mDatePicker.init(ldt.getYear(), ldt.getMonthOfYear() - 1, ldt.getDayOfMonth(), mDateListener); }