Example usage for org.joda.time LocalDateTime getMonthOfYear

List of usage examples for org.joda.time LocalDateTime getMonthOfYear

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime getMonthOfYear.

Prototype

public int getMonthOfYear() 

Source Link

Document

Get the month of year field value.

Usage

From source file:at.wada811.dayscounter.view.activity.SettingsActivity.java

License:Apache License

@Override
protected void onCreate(Bundle savedInstanceState) {
    // catch UncaughtException
    Thread.setDefaultUncaughtExceptionHandler(new CrashExceptionHandler(getApplicationContext()));
    super.onCreate(savedInstanceState);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    setContentView(R.layout.activity_settings);
    ButterKnife.inject(this);
    // Window size dialog
    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.width = WindowManager.LayoutParams.MATCH_PARENT;
    params.height = WindowManager.LayoutParams.MATCH_PARENT;
    getWindow().setAttributes(params);/*from w  ww  .  j a va 2s .  co m*/
    LogUtils.d();
    // check Crash report
    File file = ResourceUtils.getFile(this, CrashExceptionHandler.FILE_NAME);
    if (file.exists()) {
        startActivity(new Intent(this, CrashReportActivity.class));
        finish();
        return;
    }
    // AppWidgetId
    Intent intent = getIntent();
    Bundle extras = intent.getExtras();
    if (extras != null) {
        appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    }
    LogUtils.d("appWidgetId: " + appWidgetId);

    WidgetModel model = new WidgetModel(this, appWidgetId);
    viewModel = new Widget1x1ViewModel(this, model);
    // Title
    new EditTextBinding(titleEditText).bind(new Func<EditText, String>() {
        @Override
        public String apply(EditText editText) {
            return editText.getText().toString();
        }
    }, viewModel.getTitle(), new EditTextTextChanged() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            titleTextView.setText(viewModel.getTitle().getValue());
        }
    });
    titleEditText.setText(viewModel.getTitle().getValue());
    // Date
    String date = viewModel.getDate().getValue();
    LogUtils.d("date: " + date);
    LocalDateTime dateTime = date != null ? new LocalDateTime(date) : LocalDateTime.now();
    DatePickerBinding datePickerBinding = new DatePickerBinding(datePicker);
    datePickerBinding.bind(new Func<DatePicker, String>() {
        @Override
        public String apply(DatePicker datePicker) {
            return DatePickerUtils.format(datePicker);
        }
    }, viewModel.getDate(), new OnDateChangedListener() {
        @Override
        public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            diffTextView.setText(viewModel.getDiff().getValue());
            diffTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, viewModel.getDiffTextSize().getValue());
            daysTextView.setText(viewModel.getComparison().getValue());
        }
    });
    datePicker.init(dateTime.getYear(), dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth(),
            datePickerBinding.getOnDateChangedListener());
    diffTextView.setText(viewModel.getDiff().getValue());
    diffTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, viewModel.getDiffTextSize().getValue());
    daysTextView.setText(viewModel.getComparison().getValue());

    // Button
    submitButton.setOnClickListener(this);
}

From source file:ch.icclab.cyclops.util.DateTimeUtil.java

License:Open Source License

/**
 * Generates the 1 hr time range (from and to) by computing the present server time
 *
 * @return dateTime A string consisting of from and to dateTime entries
 *///  ww  w .j  a v  a2s . c  om
public String[] getRange() {
    String from, to;
    String sMonth = null;
    String sDay = null;
    String stHour = null;
    String sHour = null;
    String sMin = null;
    String sSec = null;
    int year, month, day, hour, min, sec, tHour;
    String[] dateTime = new String[2];

    LocalDateTime currentDate = LocalDateTime.now();
    year = currentDate.getYear();
    month = currentDate.getMonthOfYear();
    if (month <= 9) {
        sMonth = "0" + month;
    } else {
        sMonth = month + "";
    }
    day = currentDate.getDayOfMonth();
    if (day <= 9) {
        sDay = "0" + day;
    } else {
        sDay = day + "";
    }
    hour = currentDate.getHourOfDay();
    if (hour <= 9) {
        sHour = "0" + hour;
    } else {
        sHour = hour + "";
    }
    min = currentDate.getMinuteOfHour();
    if (min <= 9) {
        sMin = "0" + min;
    } else {
        sMin = min + "";
    }
    sec = currentDate.getSecondOfMinute();
    if (sec <= 9) {
        sSec = "0" + sec;
    } else {
        sSec = sec + "";
    }

    to = year + "-" + sMonth + "-" + sDay + "T" + sHour + ":" + sMin + ":" + sSec + "Z";
    Date dateTo = getDate(to);
    //Converting to in UTC
    to = getString(dateTo);
    long sensuFrequency = Loader.getSettings().getSchedulerSettings().getSchedulerFrequency();

    long fromTimestamp = dateTo.getTime() - sensuFrequency * 1000;
    Date fromDate = new Date(fromTimestamp);

    from = getString(fromDate);

    dateTime[0] = to;
    dateTime[1] = from;

    return dateTime;
}

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

License:Apache License

/**
 * @param ldtm ???{@link LocalDateTime}// w w w  .j ava2  s .  c om
 * @return ?????{@link Calendar}(?)????????
 */
public static Calendar getCalendar(LocalDateTime ldtm) {
    Calendar cal = Calendar.getInstance();
    cal.set(ldtm.getYear(), ldtm.getMonthOfYear() - 1, ldtm.getDayOfMonth(), ldtm.getHourOfDay(),
            ldtm.getMinuteOfHour(), ldtm.getSecondOfMinute());
    cal.set(MILLISECOND, ldtm.getMillisOfSecond());
    return cal;
}

From source file:com.axelor.apps.hr.service.timesheet.TimesheetServiceImpl.java

License:Open Source License

public String computeFullName(Timesheet timesheet) {

    User timesheetUser = timesheet.getUser();
    LocalDateTime createdOn = timesheet.getCreatedOn();

    if (timesheetUser != null && createdOn != null) {
        return timesheetUser.getFullName() + " " + createdOn.getDayOfMonth() + "/" + createdOn.getMonthOfYear()
                + "/" + timesheet.getCreatedOn().getYear() + " " + createdOn.getHourOfDay() + ":"
                + createdOn.getMinuteOfHour();
    } else if (timesheetUser != null) {
        return timesheetUser.getFullName() + " N" + timesheet.getId();
    } else {/*from  w  w  w .  j av a 2s  .  c om*/
        return "N" + timesheet.getId();
    }
}

From source file:com.axelor.apps.production.web.OperationOrderController.java

License:Open Source License

public void chargeByMachineHours(ActionRequest request, ActionResponse response) throws AxelorException {
    List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
    DateTimeFormatter parser = ISODateTimeFormat.dateTime();
    LocalDateTime fromDateTime = LocalDateTime.parse(request.getContext().get("fromDateTime").toString(),
            parser);/*from w w w . ja v  a2  s . co m*/
    LocalDateTime toDateTime = LocalDateTime.parse(request.getContext().get("toDateTime").toString(), parser);
    LocalDateTime itDateTime = new LocalDateTime(fromDateTime);

    if (Days.daysBetween(
            new LocalDate(fromDateTime.getYear(), fromDateTime.getMonthOfYear(), fromDateTime.getDayOfMonth()),
            new LocalDate(toDateTime.getYear(), toDateTime.getMonthOfYear(), toDateTime.getDayOfMonth()))
            .getDays() > 20) {
        throw new AxelorException(String.format(I18n.get(IExceptionMessage.CHARGE_MACHINE_DAYS)),
                IException.CONFIGURATION_ERROR);
    }

    List<OperationOrder> operationOrderListTemp = operationOrderRepo.all()
            .filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", fromDateTime, toDateTime)
            .fetch();
    Set<String> machineNameList = new HashSet<String>();
    for (OperationOrder operationOrder : operationOrderListTemp) {
        if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) {
            if (!machineNameList.contains(operationOrder.getWorkCenter().getMachine().getName())) {
                machineNameList.add(operationOrder.getWorkCenter().getMachine().getName());
            }
        }
    }
    while (!itDateTime.isAfter(toDateTime)) {
        List<OperationOrder> operationOrderList = operationOrderRepo.all()
                .filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", itDateTime,
                        itDateTime.plusHours(1))
                .fetch();
        Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
        for (OperationOrder operationOrder : operationOrderList) {
            if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) {
                String machine = operationOrder.getWorkCenter().getMachine().getName();
                int numberOfMinutes = 0;
                if (operationOrder.getPlannedStartDateT().isBefore(itDateTime)) {
                    numberOfMinutes = Minutes.minutesBetween(itDateTime, operationOrder.getPlannedEndDateT())
                            .getMinutes();
                } else if (operationOrder.getPlannedEndDateT().isAfter(itDateTime.plusHours(1))) {
                    numberOfMinutes = Minutes
                            .minutesBetween(operationOrder.getPlannedStartDateT(), itDateTime.plusHours(1))
                            .getMinutes();
                } else {
                    numberOfMinutes = Minutes.minutesBetween(operationOrder.getPlannedStartDateT(),
                            operationOrder.getPlannedEndDateT()).getMinutes();
                }
                if (numberOfMinutes > 60) {
                    numberOfMinutes = 60;
                }
                BigDecimal percentage = new BigDecimal(numberOfMinutes).multiply(new BigDecimal(100))
                        .divide(new BigDecimal(60), 2, RoundingMode.HALF_UP);
                if (map.containsKey(machine)) {
                    map.put(machine, map.get(machine).add(percentage));
                } else {
                    map.put(machine, percentage);
                }
            }
        }
        Set<String> keyList = map.keySet();
        for (String key : machineNameList) {
            if (keyList.contains(key)) {
                Map<String, Object> dataMap = new HashMap<String, Object>();
                if (Hours.hoursBetween(fromDateTime, toDateTime).getHours() > 24) {
                    dataMap.put("dateTime", (Object) itDateTime.toString("dd/MM/yyyy HH:mm"));
                } else {
                    dataMap.put("dateTime", (Object) itDateTime.toString("HH:mm"));
                }
                dataMap.put("charge", (Object) map.get(key));
                dataMap.put("machine", (Object) key);
                dataList.add(dataMap);
            } else {
                Map<String, Object> dataMap = new HashMap<String, Object>();
                if (Hours.hoursBetween(fromDateTime, toDateTime).getHours() > 24) {
                    dataMap.put("dateTime", (Object) itDateTime.toString("dd/MM/yyyy HH:mm"));
                } else {
                    dataMap.put("dateTime", (Object) itDateTime.toString("HH:mm"));
                }
                dataMap.put("charge", (Object) BigDecimal.ZERO);
                dataMap.put("machine", (Object) key);
                dataList.add(dataMap);
            }
        }

        itDateTime = itDateTime.plusHours(1);
    }

    response.setData(dataList);
}

From source file:com.axelor.apps.production.web.OperationOrderController.java

License:Open Source License

public void chargeByMachineDays(ActionRequest request, ActionResponse response) throws AxelorException {
    List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
    DateTimeFormatter parser = ISODateTimeFormat.dateTime();
    LocalDateTime fromDateTime = LocalDateTime.parse(request.getContext().get("fromDateTime").toString(),
            parser);// w w  w.  j  ava  2s .  c o  m
    fromDateTime = fromDateTime.withHourOfDay(0).withMinuteOfHour(0);
    LocalDateTime toDateTime = LocalDateTime.parse(request.getContext().get("toDateTime").toString(), parser);
    toDateTime = toDateTime.withHourOfDay(23).withMinuteOfHour(59);
    LocalDateTime itDateTime = new LocalDateTime(fromDateTime);
    if (Days.daysBetween(
            new LocalDate(fromDateTime.getYear(), fromDateTime.getMonthOfYear(), fromDateTime.getDayOfMonth()),
            new LocalDate(toDateTime.getYear(), toDateTime.getMonthOfYear(), toDateTime.getDayOfMonth()))
            .getDays() > 500) {
        throw new AxelorException(String.format(I18n.get(IExceptionMessage.CHARGE_MACHINE_DAYS)),
                IException.CONFIGURATION_ERROR);
    }

    List<OperationOrder> operationOrderListTemp = operationOrderRepo.all()
            .filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", fromDateTime, toDateTime)
            .fetch();
    Set<String> machineNameList = new HashSet<String>();
    for (OperationOrder operationOrder : operationOrderListTemp) {
        if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) {
            if (!machineNameList.contains(operationOrder.getWorkCenter().getMachine().getName())) {
                machineNameList.add(operationOrder.getWorkCenter().getMachine().getName());
            }
        }
    }
    while (!itDateTime.isAfter(toDateTime)) {
        List<OperationOrder> operationOrderList = operationOrderRepo.all()
                .filter("self.plannedStartDateT <= ?2 AND self.plannedEndDateT >= ?1", itDateTime,
                        itDateTime.plusHours(1))
                .fetch();
        Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
        for (OperationOrder operationOrder : operationOrderList) {
            if (operationOrder.getWorkCenter() != null && operationOrder.getWorkCenter().getMachine() != null) {
                String machine = operationOrder.getWorkCenter().getMachine().getName();
                int numberOfMinutes = 0;
                if (operationOrder.getPlannedStartDateT().isBefore(itDateTime)) {
                    numberOfMinutes = Minutes.minutesBetween(itDateTime, operationOrder.getPlannedEndDateT())
                            .getMinutes();
                } else if (operationOrder.getPlannedEndDateT().isAfter(itDateTime.plusHours(1))) {
                    numberOfMinutes = Minutes
                            .minutesBetween(operationOrder.getPlannedStartDateT(), itDateTime.plusHours(1))
                            .getMinutes();
                } else {
                    numberOfMinutes = Minutes.minutesBetween(operationOrder.getPlannedStartDateT(),
                            operationOrder.getPlannedEndDateT()).getMinutes();
                }
                if (numberOfMinutes > 60) {
                    numberOfMinutes = 60;
                }
                int numberOfMinutesPerDay = 0;
                if (operationOrder.getWorkCenter().getMachine().getWeeklyPlanning() != null) {
                    DayPlanning dayPlanning = weeklyPlanningService.findDayPlanning(
                            operationOrder.getWorkCenter().getMachine().getWeeklyPlanning(),
                            new LocalDate(itDateTime));
                    numberOfMinutesPerDay = Minutes
                            .minutesBetween(dayPlanning.getMorningFrom(), dayPlanning.getMorningTo())
                            .getMinutes();
                    numberOfMinutesPerDay += Minutes
                            .minutesBetween(dayPlanning.getAfternoonFrom(), dayPlanning.getAfternoonTo())
                            .getMinutes();
                } else {
                    numberOfMinutesPerDay = 60 * 8;
                }
                BigDecimal percentage = new BigDecimal(numberOfMinutes).multiply(new BigDecimal(100))
                        .divide(new BigDecimal(numberOfMinutesPerDay), 2, RoundingMode.HALF_UP);
                if (map.containsKey(machine)) {
                    map.put(machine, map.get(machine).add(percentage));
                } else {
                    map.put(machine, percentage);
                }
            }
        }
        Set<String> keyList = map.keySet();
        for (String key : machineNameList) {
            if (keyList.contains(key)) {
                int found = 0;
                for (Map<String, Object> mapIt : dataList) {
                    if (mapIt.get("dateTime").equals((Object) itDateTime.toString("dd/MM/yyyy"))
                            && mapIt.get("machine").equals((Object) key)) {
                        mapIt.put("charge", new BigDecimal(mapIt.get("charge").toString()).add(map.get(key)));
                        found = 1;
                        break;
                    }

                }
                if (found == 0) {
                    Map<String, Object> dataMap = new HashMap<String, Object>();

                    dataMap.put("dateTime", (Object) itDateTime.toString("dd/MM/yyyy"));
                    dataMap.put("charge", (Object) map.get(key));
                    dataMap.put("machine", (Object) key);
                    dataList.add(dataMap);
                }
            }
        }

        itDateTime = itDateTime.plusHours(1);
    }

    response.setData(dataList);
}

From source file:com.gs.fw.common.mithra.databasetype.SybaseIqNativeDatabaseType.java

License:Apache License

@Override
public Timestamp getTimestampFromResultSet(ResultSet rs, int pos, TimeZone timeZone) throws SQLException {
    Timestamp localTs = rs.getTimestamp(pos);
    if (localTs == null) {
        return null;
    }//w ww.  j  a va  2s . c  o  m
    LocalDateTime ldt = new LocalDateTime(localTs.getTime());

    Calendar utcCal = getCalendarInstance();
    utcCal.set(Calendar.YEAR, ldt.getYear());
    utcCal.set(Calendar.MONTH, ldt.getMonthOfYear() - 1);
    utcCal.set(Calendar.DAY_OF_MONTH, ldt.getDayOfMonth());
    utcCal.set(Calendar.HOUR_OF_DAY, ldt.getHourOfDay());
    utcCal.set(Calendar.MINUTE, ldt.getMinuteOfHour());
    utcCal.set(Calendar.SECOND, ldt.getSecondOfMinute());
    utcCal.set(Calendar.MILLISECOND, ldt.getMillisOfSecond());
    Timestamp utcTs = new Timestamp(utcCal.getTimeInMillis());
    return MithraTimestamp.zConvertTimeForReadingWithUtcCalendar(utcTs, timeZone);
}

From source file:com.gst.infrastructure.dataqueries.service.GenericDataServiceImpl.java

License:Apache License

@Override
public String generateJsonFromGenericResultsetData(final GenericResultsetData grs) {

    final StringBuffer writer = new StringBuffer();

    writer.append("[");

    final List<ResultsetColumnHeaderData> columnHeaders = grs.getColumnHeaders();

    final List<ResultsetRowData> data = grs.getData();
    List<String> row;
    Integer rSize;// www .  j  a  v a  2  s.  c  o  m
    final String doubleQuote = "\"";
    final String slashDoubleQuote = "\\\"";
    String currColType;
    String currVal;

    for (int i = 0; i < data.size(); i++) {
        writer.append("\n{");

        row = data.get(i).getRow();
        rSize = row.size();
        for (int j = 0; j < rSize; j++) {

            writer.append(doubleQuote + columnHeaders.get(j).getColumnName() + doubleQuote + ": ");
            currColType = columnHeaders.get(j).getColumnDisplayType();
            final String colType = columnHeaders.get(j).getColumnType();
            if (currColType == null && colType.equalsIgnoreCase("INT")) {
                currColType = "INTEGER";
            }
            if (currColType == null && colType.equalsIgnoreCase("VARCHAR")) {
                currColType = "VARCHAR";
            }
            if (currColType == null && colType.equalsIgnoreCase("DATE")) {
                currColType = "DATE";
            }
            currVal = row.get(j);
            if (currVal != null && currColType != null) {
                if (currColType.equals("DECIMAL") || currColType.equals("INTEGER")) {
                    writer.append(currVal);
                } else {
                    if (currColType.equals("DATE")) {
                        final LocalDate localDate = new LocalDate(currVal);
                        writer.append("[" + localDate.getYear() + ", " + localDate.getMonthOfYear() + ", "
                                + localDate.getDayOfMonth() + "]");
                    } else if (currColType.equals("DATETIME")) {
                        final LocalDateTime localDateTime = new LocalDateTime(currVal);
                        writer.append("[" + localDateTime.getYear() + ", " + localDateTime.getMonthOfYear()
                                + ", " + localDateTime.getDayOfMonth() + " " + localDateTime.getHourOfDay()
                                + ", " + localDateTime.getMinuteOfHour() + ", "
                                + localDateTime.getSecondOfMinute() + ", " + localDateTime.getMillisOfSecond()
                                + "]");
                    } else {
                        writer.append(
                                doubleQuote + replace(currVal, doubleQuote, slashDoubleQuote) + doubleQuote);
                    }
                }
            } else {
                writer.append("null");
            }
            if (j < (rSize - 1)) {
                writer.append(",\n");
            }
        }

        if (i < (data.size() - 1)) {
            writer.append("},");
        } else {
            writer.append("}");
        }
    }

    writer.append("\n]");
    return writer.toString();

}

From source file:com.helger.datetime.xml.PDTXMLConverter.java

License:Apache License

/**
 * Get the passed object as {@link XMLGregorianCalendar} with date and time.
 *
 * @param aBase/*from w ww.  j a v a  2 s. c om*/
 *        The source object. May be <code>null</code>.
 * @return <code>null</code> if the parameter is <code>null</code>.
 */
@Nullable
public static XMLGregorianCalendar getXMLCalendar(@Nullable final LocalDateTime aBase) {
    return aBase == null ? null
            : s_aDTFactory.newXMLGregorianCalendar(aBase.getYear(), aBase.getMonthOfYear(),
                    aBase.getDayOfMonth(), aBase.getHourOfDay(), aBase.getMinuteOfHour(),
                    aBase.getSecondOfMinute(), aBase.getMillisOfSecond(), DatatypeConstants.FIELD_UNDEFINED);
}

From source file:com.kccomy.orgar.ui.editor.NodeEditorFragment.java

License:Apache License

private void showDatePickerDialog(OrgTimestamp.Type type) {

    LocalDateTime src = null;//from  w ww. j a v  a 2 s . c  o  m

    if (OrgTimestamp.Type.SCHEDULED.equals(type)) {
        src = scheduledDate;
    } else if (OrgTimestamp.Type.DEADLINE.equals(type)) {
        src = deadlineDate;
    }
    LocalDateTime date = src != null ? src : LocalDateTime.now();

    DatePickerDialog picker = DatePickerDialog.newInstance(this, date.getYear(), date.getMonthOfYear(),
            date.getDayOfMonth());
    picker.setAccentColor(getResources().getColor(R.color.colorAccent));
    picker.show(getActivity().getFragmentManager(), type.toString());
}