Example usage for org.joda.time LocalDateTime LocalDateTime

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

Introduction

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

Prototype

public LocalDateTime(Object instant) 

Source Link

Document

Constructs an instance from an Object that represents a datetime.

Usage

From source file:com.makotogo.mobile.hoursdroid.BillingSummaryFragment.java

License:Apache License

private void processBeginDateRequestResult(Intent data) {
    String METHOD = "processBeginDateRequestResult(Intent): ";
    Date beginDate = (Date) data.getSerializableExtra(DateTimePickerFragment.RESULT_DATE_TIME);
    long now = System.currentTimeMillis();
    long begin = beginDate.getTime();
    long end = (mEndDate != null) ? mEndDate.getTime() : DEFAULT_END_TIME_MILLIS;
    if (begin > now) {
        // Sanity Check #1 - Begin must be before now
        // It is not. Error message.
        String message = "Begin date/time cannot be later than current date/time (i.e., \"now\"). Please try again.";
        Log.e(TAG, METHOD + message);/*from w ww . j av  a  2s.co  m*/
        Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
    } else {
        if (end >= begin) {
            // Sanity Check #2 - Begin must be before or equal to End.
            // It is. Set the begin date the user chose, at the BEGINNING of that day
            LocalDateTime ldt = new LocalDateTime(beginDate).withHourOfDay(0).withMinuteOfHour(0);
            mBeginDate = beginDate;
            // Update the new filter setting
            updateSharedPreferences();
        } else {
            String message = "Begin date/time cannot be later than End date/time. Please try again.";
            Log.e(TAG, METHOD + message);
            Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
        }
    }
}

From source file:com.makotogo.mobile.hoursdroid.BillingSummaryFragment.java

License:Apache License

private void processEndDateRequestResult(Intent data) {
    String METHOD = "processEndDateRequestResult(Intent): ";
    Date endDate = (Date) data.getSerializableExtra(DateTimePickerFragment.RESULT_DATE_TIME);
    long now = System.currentTimeMillis();
    long end = endDate.getTime();
    long begin = (mBeginDate != null) ? mBeginDate.getTime() : DEFAULT_BEGIN_TIME_MILLIS;
    if (begin <= end) {
        // Sanity Check #2 - Begin must be before or equal to End.
        // It is. Set the end date the user chose, at the END of that day
        LocalDateTime ldt = new LocalDateTime(endDate).withHourOfDay(23).withMinuteOfHour(59);
        mEndDate = ldt.toDate();/*  ww  w.  j a v  a 2 s .co  m*/
        // Update the new filter setting
        updateSharedPreferences();
    } else {
        String message = "Begin date/time cannot be later than End date/time. Please try again.";
        Log.e(TAG, METHOD + message);
        Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
    }
}

From source file:com.makotogo.mobile.hoursdroid.BillingSummaryFragment.java

License:Apache License

private void updateBeginDateTextView() {
    // Take the End part of the Interval setting and display it
    TextView beginDateTextView = (TextView) getView().findViewById(R.id.textview_reporting_summary_begin_date);
    if (mBeginDate != null) {
        beginDateTextView.setText(new LocalDateTime(mBeginDate.getTime()).toString(SHORT_DATE_FORMAT_STRING));
    } else {//  w w  w. java  2 s .  co m
        beginDateTextView.setText(DATE_NONE);
    }
}

From source file:com.makotogo.mobile.hoursdroid.BillingSummaryFragment.java

License:Apache License

private void updateEndDateTextView() {
    // Take the End part of the Interval setting and display it
    TextView endDateTextView = (TextView) getView().findViewById(R.id.textview_reporting_summary_end_date);
    if (mEndDate != null) {
        endDateTextView.setText(new LocalDateTime(mEndDate.getTime()).toString(SHORT_DATE_FORMAT_STRING));
    } else {/*from   ww  w .jav a  2s. c o m*/
        endDateTextView.setText(DATE_NONE);
    }
}

From source file:com.makotogo.mobile.hoursdroid.BillingSummaryFragment.java

License:Apache License

private String formatDate(Date dateToFormat) {
    String ret = "";
    if (dateToFormat != null) {
        ret = new LocalDateTime(dateToFormat.getTime()).toString(DATE_FORMAT_STRING);
    }/*from ww  w. jav  a  2s .  c om*/
    return ret;
}

From source file:com.makotogo.mobile.hoursdroid.DateTimePickerFragment.java

License:Apache License

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Pull the date out of the Fragment Arguments
    processFragmentArguments();//w  ww.  ja  v a  2s .co m
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(mDate);
    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH);
    int day = calendar.get(Calendar.DAY_OF_MONTH);

    View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_date_time, null);

    // Spinner to choose either Date or Time to edit
    final Spinner dateTimeSpinner = (Spinner) view.findViewById(R.id.spinner_date_time_choice);
    mDatePicker = (DatePicker) view.findViewById(R.id.date_picker);
    mTimePicker = (TimePicker) view.findViewById(R.id.time_picker);
    // Note: the OnDateChangedListener does not work in Android 5 when using the
    /// super cool material style of calendar, which is really slick.
    mDatePicker.init(year, month, day, null);

    int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
    int minuteOfHour = calendar.get(Calendar.MINUTE);
    //noinspection deprecation
    mTimePicker.setCurrentHour(hourOfDay);
    //noinspection deprecation
    mTimePicker.setCurrentMinute(minuteOfHour);

    configureDateTimeSpinner(dateTimeSpinner);
    // Now show the Dialog in all its glory!
    return new AlertDialog.Builder(getActivity()).setView(view).setTitle(R.string.please_choose)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    final String METHOD = "onClick(" + dialog + ", " + which + "): ";
                    if (getTargetFragment() == null) {
                        Log.e(TAG, "Target Fragment is null!");
                    } else {
                        //noinspection deprecation
                        mDate = computeDateFromComponents(mDatePicker.getYear(), mDatePicker.getMonth(),
                                mDatePicker.getDayOfMonth(), mTimePicker.getCurrentHour(),
                                mTimePicker.getCurrentMinute());
                        Intent intent = new Intent();
                        intent.putExtra(RESULT_DATE_TIME, mDate);
                        getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK,
                                intent);
                        Log.d(TAG, METHOD + "Sending result back to the caller...:"
                                + new LocalDateTime(mDate.getTime()).toString("MM/dd/yyyy hh:mm a"));
                    }
                }
            }).create();
}

From source file:com.makotogo.mobile.hoursdroid.FilterDialogFragment.java

License:Apache License

/**
 * Formats the specified date according to the format string from the
 * ApplicationOptions object.//from w w w .j a va 2s. c o  m
 * <p/>
 * TODO: Move to generic class?
 *
 * @param date
 * @return
 */
private String formatDate(Date date) {
    ApplicationOptions applicationOptions = ApplicationOptions.instance(getActivity());
    String dateFormatString = applicationOptions.getDateFormatString();
    // Sanity check
    if (dateFormatString == null || dateFormatString.equals("")) {
        throw new RuntimeException("Date Format String cannot be null or empty string.");
    }
    LocalDateTime localDateTime = new LocalDateTime(date.getTime());
    return localDateTime.toString(dateFormatString);
}

From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java

License:Apache License

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    final String METHOD = "onActivityResult(" + requestCode + ", " + resultCode + ", " + data + "): ";
    if (resultCode == Activity.RESULT_OK) {
        // Figure out which Result code we are dealing with. This method
        /// handles the results of all dialog fragments used to set the
        /// model data.
        switch (requestCode) {
        case REQUEST_BEGIN_DATE_PICKER:
            Date beginDate = (Date) data.getSerializableExtra(DateTimePickerFragment.RESULT_DATE_TIME);
            LocalDateTime ldtBeginDate = new LocalDateTime(beginDate.getTime());
            if (ldtBeginDate.isBefore(new LocalDateTime(mHours.getEnd().getTime()))) {
                mHours.setBegin(beginDate);
                updateUI();/*from  w  w  w.  ja  va2 s  . c  o  m*/
            } else {
                String message = "End date must be after begin date";
                Log.e(TAG, METHOD + message);
                Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
            }
            break;
        case REQUEST_END_DATE_PICKER:
            Date endDate = (Date) data.getSerializableExtra(DateTimePickerFragment.RESULT_DATE_TIME);
            LocalDateTime ldtEndDate = new LocalDateTime(endDate.getTime());
            if (ldtEndDate.isAfter(new LocalDateTime(mHours.getBegin().getTime()))) {
                mHours.setEnd(endDate);
                updateUI();
            } else {
                String message = "End date must be after begin date";
                Log.e(TAG, METHOD + message);
                Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
            }
            break;
        case REQUEST_BREAK:
            Integer breakTimeInMinutes = (Integer) data
                    .getSerializableExtra(NumberPickerFragment.RESULT_MINUTES);
            mHours.setBreak(renderBreakForStorage(breakTimeInMinutes));
            updateUI();
            break;
        case REQUEST_CODE_MANAGE_PROJECTS:
            Project project = (Project) data.getSerializableExtra(ProjectListActivity.RESULT_PROJECT);
            mHours.setProject(project);
            updateUI();
            break;
        default:
            break;
        }
    }
}

From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java

License:Apache License

private void updateBegin() {
    if (mHours.getBegin() != null) {
        LocalDateTime beginDateTime = new LocalDateTime(mHours.getBegin().getTime());
        ((TextView) getView().findViewById(R.id.textview_hours_detail_begin_date))
                .setText(beginDateTime.toString(DATE_FORMAT_PATTERN));
    }//from   w w w.ja va  2 s .c om
}

From source file:com.makotogo.mobile.hoursdroid.HoursDetailFragment.java

License:Apache License

private void updateEnd() {
    if (mHours.getEnd() != null) {
        LocalDateTime endDateTime = new LocalDateTime(mHours.getEnd().getTime());
        ((TextView) getView().findViewById(R.id.textview_hours_detail_end_date))
                .setText(endDateTime.toString(DATE_FORMAT_PATTERN));
    }//from  w  w  w.  j  a  va  2  s  . co m
}