Example usage for org.joda.time LocalDate LocalDate

List of usage examples for org.joda.time LocalDate LocalDate

Introduction

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

Prototype

public LocalDate(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:com.constellio.app.services.appManagement.AppManagementService.java

License:Open Source License

public LicenseInfo getLicenseInfo() {
    LicenseInfo license = null;/*from   ww w  .  ja v  a2  s.  c o  m*/
    try {
        String licenseString = ioServices.readFileToString(foldersLocator.getLicenseFile());
        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(new StringReader(licenseString));

        String name = document.getRootElement().getChild("name").getContent().get(0).getValue();
        LocalDate date = new LocalDate(
                document.getRootElement().getChild("date").getContent().get(0).getValue());
        String signature = document.getRootElement().getChild("signature").getContent().get(0).getValue();

        license = new LicenseInfo(name, date, signature);
    } catch (IOException ioe) {
    } catch (JDOMException joe) {
    }

    return license;
}

From source file:com.einzig.ipst2.activities.PSEditActivity.java

License:Open Source License

@OnClick(R.id.datesubbutton_pseditactivity)
public void editSubDate() {
    final Calendar c = Calendar.getInstance(Locale.getDefault());
    if (portal != null && portal.getDateSubmitted() != null) {
        c.setTime(portal.getDateSubmitted().toDate());
    }/* ww w .j  a  va2s  .  co m*/
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);
    DatePickerDialog DPDSub_dialog = new DatePickerDialog(this,
            ThemeHelper.getDateDialogTheme(PSEditActivity.this), new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker datePicker, int year, int month, int day) {
                    Calendar c = Calendar.getInstance(Locale.getDefault());
                    c.set(year, month, day);
                    if (portal != null)
                        portal.setDateSubmitted(new LocalDate(c.getTime()));
                    updateDateButton(datesubbutton_pseditactivity, portal.getDateSubmitted().toString());
                }
            }, year, month, day);
    DPDSub_dialog.setTitle("Set Submission Date");
    DPDSub_dialog.show();
}

From source file:com.einzig.ipst2.activities.PSEditActivity.java

License:Open Source License

public void doPortalRespondedButton(final View view) {
    final Calendar c = Calendar.getInstance(Locale.getDefault());
    if (portal != null && portal instanceof PortalResponded
            && ((PortalResponded) portal).getDateResponded() != null) {
        c.setTime(((PortalResponded) portal).getDateResponded().toDate());
    }/*from   www. j a va 2s . c  o  m*/
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);
    DatePickerDialog _dialog = new DatePickerDialog(PSEditActivity.this,
            ThemeHelper.getDateDialogTheme(PSEditActivity.this), new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker datePicker, int year, int month, int day) {
                    Calendar c = Calendar.getInstance(Locale.getDefault());
                    c.set(year, month, day);
                    if (portal != null && portal instanceof PortalResponded)
                        ((PortalResponded) portal).setDateResponded(new LocalDate(c.getTime()));
                    updateDateButton((Button) view, ((PortalResponded) portal).getDateResponded().toString());
                }
            }, year, month, day);
    _dialog.setTitle("Set Responded Date");
    _dialog.show();
}

From source file:com.einzig.ipst2.database.PortalGrabber.java

License:Open Source License

@Override
protected Vector<? extends PortalSubmission> doInBackground(Void... voids) {
    Vector<? extends PortalSubmission> psList = null;
    Logger.d("RANGE: " + RANGE);
    Logger.d("TYPE: " + TYPE);
    LocalDate viewDate = null;// www  . j  a v  a 2  s.co  m
    PreferencesHelper helper = new PreferencesHelper(fromAct);
    try {
        if (RANGE != null)
            if (!RANGE.equalsIgnoreCase(""))
                viewDate = new LocalDate(RANGE);
        if (TYPE != null)
            switch (TYPE) {
            case "all":
                if (viewDate == null)
                    psList = db.getAllPortals(helper.isSeerOnly());
                else
                    psList = db.getAllPortalsFromDate(viewDate, helper.isSeerOnly());
                break;
            case "accepted":
                if (viewDate == null)
                    psList = db.getAllAccepted(helper.isSeerOnly());
                else
                    psList = db.getAcceptedByResponseDate(viewDate, helper.isSeerOnly());
                break;
            case "pending":
                if (viewDate == null)
                    psList = db.getAllPending(helper.isSeerOnly());
                else
                    psList = db.getPendingByDate(viewDate, helper.isSeerOnly());
                break;
            case "rejected":
                if (viewDate == null)
                    psList = db.getAllRejected(helper.isSeerOnly());
                else
                    psList = db.getRejectedByResponseDate(viewDate, helper.isSeerOnly());
                break;
            }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return psList;
}

From source file:com.einzig.ipst2.parse.EmailParser.java

License:Open Source License

/**
 * Get a portal object from an email/*ww  w .  j a  va  2 s . co m*/
 *
 * @param message A Message being parsed.
 * @return PortalSubmission or subclass if the email can be parsed, otherwise null
 */
PortalSubmission getPortal(Message message) {
    String messageString, subject;
    LocalDate receivedDate;
    try {
        subject = message.getSubject();
        subject = cleanSubject(subject);
        receivedDate = new LocalDate(message.getReceivedDate());
    } catch (MessagingException e) {
        return null;
    }
    /*if (!isEmailFromNiantic(message))
    return null;*/
    messageString = getText(message);
    return parse(subject, messageString, receivedDate);
}

From source file:com.einzig.ipst2.parse.EmailParseTask.java

License:Open Source License

@Override
protected Void doInBackground(Void... voids) {
    Logger.d("Parsing email");
    LocalDate now = LocalDate.now();
    for (int i = 0; i < messages.length; i++) {
        PortalSubmission p = parser.getPortal(messages[i]);
        addPortal(p);//from  w  w  w.j a v a2 s  .co  m
        publishProgress(i, messages.length);
        if (isCancelled()) {
            try {
                now = new LocalDate(messages[i].getReceivedDate());
            } catch (MessagingException e) {
                Logger.e(e.toString());
            }
            break;
        }
    }
    onEmailParse(now);
    bundle.cleanup();
    return null;
}

From source file:com.esofthead.mycollab.core.arguments.DateSearchField.java

License:Open Source License

public DateSearchField(String oper, Date dateVal, String comparison) {
    this.operation = oper;
    this.comparison = comparison;
    this.value = new LocalDate(dateVal).toDate();
}

From source file:com.esofthead.mycollab.module.project.view.assignments.gantt.GanttExt.java

License:Open Source License

private void updateTasksInfoByResizeOrMove(StepExt step, long startDate, long endDate) {
    final GanttItemWrapper ganttItemWrapper = step.getGanttItemWrapper();
    if (ganttItemWrapper.hasSubTasks()) {
        step.setStartDate(ganttItemWrapper.getStartDate().toDate());
        step.setEndDate(ganttItemWrapper.getEndDate().plusDays(1).toDate());
        EventBusFactory.getInstance().post(new GanttEvent.UpdateGanttItem(GanttExt.this, ganttItemWrapper));
        NotificationUtil.showWarningNotification("Can not adjust dates of parent task");
    } else {/*from w  ww .ja  va  2 s .  c  o m*/
        LocalDate suggestedStartDate = new LocalDate(startDate);
        LocalDate suggestedEndDate = new LocalDate(endDate);
        ganttItemWrapper.setStartAndEndDate(suggestedStartDate, suggestedEndDate, true, true);
        EventBusFactory.getInstance().post(new GanttEvent.UpdateGanttItem(GanttExt.this, ganttItemWrapper));
        EventBusFactory.getInstance()
                .post(new GanttEvent.AddGanttItemUpdateToQueue(GanttExt.this, ganttItemWrapper));
        this.calculateMaxMinDates(ganttItemWrapper);
    }
}

From source file:com.esofthead.mycollab.module.project.view.assignments.gantt.GanttItemWrapper.java

License:Open Source License

public void adjustTaskDatesByPredecessors(List<TaskPredecessor> predecessors) {
    if (CollectionUtils.isNotEmpty(predecessors)) {
        LocalDate currentStartDate = new LocalDate(getStartDate());
        LocalDate currentEndDate = new LocalDate(getEndDate());
        LocalDate boundStartDate = new LocalDate(1970, 1, 1);
        LocalDate boundEndDate = new LocalDate(2100, 1, 1);

        for (TaskPredecessor predecessor : predecessors) {
            int ganttIndex = predecessor.getGanttIndex();

            GanttItemWrapper ganttPredecessor = gantt.getBeanContainer().getItemByGanttIndex(ganttIndex);
            int dur = getDuration().intValue() - 1;
            if (ganttPredecessor != null) {
                Integer lagDay = predecessor.getLagday() + 1;

                if (TaskPredecessor.FS.equals(predecessor.getPredestype())) {
                    LocalDate endDate = new LocalDate(ganttPredecessor.getEndDate());
                    endDate = endDate.plusDays(1);
                    LocalDate expectedStartDate = BusinessDayTimeUtils.plusDays(endDate, lagDay);
                    if (boundStartDate.isBefore(expectedStartDate)) {
                        boundStartDate = expectedStartDate;
                    }//from  w ww  .  jav a  2  s .  c  o m
                    if (currentStartDate.isBefore(expectedStartDate)) {
                        currentStartDate = expectedStartDate;
                        LocalDate expectedEndDate = currentStartDate.plusDays(dur);
                        currentEndDate = DateTimeUtils.min(boundEndDate, expectedEndDate);
                    }
                } else if (TaskPredecessor.FF.equals(predecessor.getPredestype())) {
                    LocalDate endDate = new LocalDate(ganttPredecessor.getEndDate());
                    LocalDate expectedEndDate = BusinessDayTimeUtils.plusDays(endDate, lagDay);
                    if (boundEndDate.isAfter(expectedEndDate)) {
                        boundEndDate = expectedEndDate;
                    }
                    if (currentEndDate.isAfter(expectedEndDate)) {
                        currentEndDate = expectedEndDate;
                        LocalDate expectedStartDate = currentEndDate.minusDays(dur);
                        currentStartDate = DateTimeUtils.max(boundStartDate, expectedStartDate);
                    }
                } else if (TaskPredecessor.SF.equals(predecessor.getPredestype())) {
                    LocalDate startDate = new LocalDate(ganttPredecessor.getStartDate());
                    LocalDate expectedEndDate = BusinessDayTimeUtils.plusDays(startDate, lagDay);
                    if (boundEndDate.isAfter(expectedEndDate)) {
                        boundEndDate = expectedEndDate;
                    }
                    if (currentEndDate.isAfter(expectedEndDate)) {
                        currentEndDate = expectedEndDate;
                        LocalDate expectedStartDate = currentEndDate.minusDays(dur);
                        currentStartDate = DateTimeUtils.max(boundStartDate, expectedStartDate);
                    }
                } else if (TaskPredecessor.SS.equals(predecessor.getPredestype())) {
                    LocalDate startDate = new LocalDate(ganttPredecessor.getStartDate());
                    LocalDate expectedStartDate = BusinessDayTimeUtils.plusDays(startDate, lagDay);

                    if (boundStartDate.isBefore(expectedStartDate)) {
                        boundStartDate = expectedStartDate;
                    }

                    if (currentStartDate.isBefore(expectedStartDate)) {
                        currentStartDate = expectedStartDate;
                        LocalDate expectedEndDate = BusinessDayTimeUtils.plusDays(startDate, dur);
                        currentEndDate = DateTimeUtils.min(boundEndDate, expectedEndDate);
                    }
                } else {
                    throw new MyCollabException(
                            "Do not support predecessor type " + predecessor.getPredestype());
                }

                if (currentEndDate.isBefore(currentStartDate)) {
                    throw new UserInvalidInputException("Invalid constraint");
                }
            }
        }

        setStartAndEndDate(currentStartDate, currentEndDate, false, true);
    }
}

From source file:com.esofthead.mycollab.module.project.view.task.TaskEditFormFieldFactory.java

License:Open Source License

@Override
protected Field<?> onCreateField(final Object propertyId) {
    if (Task.Field.assignuser.equalTo(propertyId)) {
        ProjectMemberSelectionField field = new ProjectMemberSelectionField();
        field.addValueChangeListener(new Property.ValueChangeListener() {
            @Override//from   w  w  w .j  a v a2 s .  com
            public void valueChange(Property.ValueChangeEvent valueChangeEvent) {
                Property property = valueChangeEvent.getProperty();
                SimpleProjectMember member = (SimpleProjectMember) property.getValue();
                if (member != null) {
                    subscribersComp.addFollower(member.getUsername());
                }
            }
        });
        return field;
    } else if (Task.Field.milestoneid.equalTo(propertyId)) {
        return new MilestoneComboBox();
    } else if (Task.Field.notes.equalTo(propertyId)) {
        final RichTextArea richTextArea = new RichTextArea();
        richTextArea.setNullRepresentation("");
        return richTextArea;
    } else if (Task.Field.taskname.equalTo(propertyId)) {
        final TextField tf = new TextField();
        tf.setNullRepresentation("");
        tf.setRequired(true);
        tf.setRequiredError(AppContext.getMessage(ErrorI18nEnum.FIELD_MUST_NOT_NULL, "Name"));
        return tf;
    } else if (Task.Field.status.equalTo(propertyId)) {
        return new TaskStatusComboBox();
    } else if (Task.Field.percentagecomplete.equalTo(propertyId)) {
        return new TaskSliderField();
    } else if (Task.Field.priority.equalTo(propertyId)) {
        return new TaskPriorityComboBox();
    } else if (Task.Field.duration.equalTo(propertyId)) {
        final TextField field = new TextField();
        field.setConverter(new HumanTimeConverter());
        final SimpleTask beanItem = attachForm.getBean();
        if (beanItem.getNumSubTasks() != null && beanItem.getNumSubTasks() > 0) {
            field.setEnabled(false);
            field.setDescription("Because this row has sub-tasks, this cell "
                    + "is a summary value and can not be edited directly. You can edit cells "
                    + "beneath this row to change its value");
        }

        //calculate the end date if the start date is set
        field.addBlurListener(new FieldEvents.BlurListener() {
            @Override
            public void blur(FieldEvents.BlurEvent event) {
                HumanTime humanTime = HumanTime.eval(field.getValue());
                Integer duration = Integer.valueOf(humanTime.getDelta() + "");
                DateTimeOptionField startDateField = (DateTimeOptionField) fieldGroup
                        .getField(Task.Field.startdate.name());
                Date startDateVal = startDateField.getValue();
                if (duration > 0 && startDateVal != null) {
                    int durationIndays = duration / (int) DateTimeUtils.MILLISECONDS_IN_A_DAY;
                    if (durationIndays > 0) {
                        LocalDate startDateJoda = new LocalDate(startDateVal);
                        LocalDate endDateJoda = BusinessDayTimeUtils.plusDays(startDateJoda, durationIndays);
                        DateTimeOptionField endDateField = (DateTimeOptionField) fieldGroup
                                .getField(Task.Field.enddate.name());
                        endDateField.setValue(endDateJoda.toDate());
                    }
                }
            }
        });
        return field;
    } else if (Task.Field.originalestimate.equalTo(propertyId)
            || Task.Field.remainestimate.equalTo(propertyId)) {
        return new DoubleField();
    } else if (Task.Field.startdate.equalTo(propertyId)) {
        final DateTimeOptionField startDateField = new DateTimeOptionField(true);
        startDateField.addValueChangeListener(new Property.ValueChangeListener() {
            @Override
            public void valueChange(Property.ValueChangeEvent event) {
                calculateDurationBaseOnStartAndEndDates();
            }
        });
        return startDateField;
    } else if (Task.Field.enddate.equalTo(propertyId)) {
        DateTimeOptionField endDateField = new DateTimeOptionField(true);
        endDateField.addValueChangeListener(new Property.ValueChangeListener() {
            @Override
            public void valueChange(Property.ValueChangeEvent event) {
                calculateDurationBaseOnStartAndEndDates();
            }
        });
        return endDateField;
    } else if (Task.Field.id.equalTo(propertyId)) {
        attachmentUploadField = new AttachmentUploadField();
        Task beanItem = attachForm.getBean();
        if (beanItem.getId() != null) {
            String attachmentPath = AttachmentUtils.getProjectEntityAttachmentPath(AppContext.getAccountId(),
                    beanItem.getProjectid(), ProjectTypeConstants.TASK, "" + beanItem.getId());
            attachmentUploadField.getAttachments(attachmentPath);
        }
        return attachmentUploadField;
    } else if (Task.Field.deadline.equalTo(propertyId)) {
        return new DateTimeOptionField(true);
    } else if (propertyId.equals("selected")) {
        return subscribersComp;
    }
    return null;
}