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() 

Source Link

Document

Constructs an instance set to the current local time evaluated using ISO chronology in the default zone.

Usage

From source file:com.makotogo.mobile.hoursdroid.util.RoundingUtils.java

License:Apache License

/**
 * Calculates a new Date object, and rounds down the seconds and milliseconds to zero
 * to give a nice new value at the minute boundary.
 *
 * @return//from  w w  w  . j  ava  2s  .  com
 */
public static Date calculateDateWithRounding() {
    final String METHOD = "calculateDateWithRounding()";
    LocalDateTime localDateTime = new LocalDateTime().withSecondOfMinute(0).withMillisOfSecond(0);
    Date ret = localDateTime.toDate();
    Log.d(TAG, METHOD + "Returning new date: " + ret);
    return ret;
}

From source file:com.mklinke.breakplanner.model.Break.java

License:Apache License

/**
 * @param time/*from  w  ww .  ja v  a  2  s .  c om*/
 *          the time for the break
 * @throws IllegalArgumentException
 *           if the time is null or in the past
 */
public void setTime(LocalDateTime time) {
    LocalDateTime aMinuteAgo = new LocalDateTime().minusMinutes(1);
    if (time == null || time.isBefore(aMinuteAgo)) {
        throw new IllegalArgumentException("Invalid time: " + time);
    }
    this.time = time;
}

From source file:com.mycollab.community.common.service.AppPropertiesServiceImpl.java

License:Open Source License

@Override
public void afterPropertiesSet() throws Exception {
    try {/*  w  ww  . j  av  a2  s .c o  m*/
        File homeFolder = FileUtils.getHomeFolder();
        File sysFile = new File(homeFolder, ".app.properties");
        properties = new Properties();
        if (sysFile.isFile() && sysFile.exists()) {
            properties.load(new FileInputStream(sysFile));
            String startDate = properties.getProperty("startdate");
            if (startDate == null) {
                properties.setProperty("startdate",
                        DateTimeUtils.formatDateToW3C(new GregorianCalendar().getTime()));
            }
            properties.setProperty("edition", getEdition());
            properties.store(new FileOutputStream(sysFile), "");
        } else {
            properties.setProperty("id",
                    UUID.randomUUID().toString() + new LocalDateTime().getMillisOfSecond());
            properties.setProperty("startdate",
                    DateTimeUtils.formatDateToW3C(new GregorianCalendar().getTime()));
            properties.setProperty("edition", getEdition());
            properties.store(new FileOutputStream(sysFile), "");
        }
    } catch (IOException e) {
        LOG.error("Error", e);
    }
}

From source file:com.none.tom.simplerssreader.activity.MainActivity.java

License:Open Source License

@SuppressWarnings("SameParameterValue")
public void startActivity(final String action, final String mimeType, final boolean... retainCategories) {
    final Intent intent = new Intent(action).setType(mimeType);

    if (action.equals(Intent.ACTION_OPEN_DOCUMENT)) {
        startActivityForResult(intent, REQUEST_CODE_IMPORT_SUBSCRIPTIONS);
    } else if (action.equals(Intent.ACTION_CREATE_DOCUMENT)) {
        final String title = TAG.toLowerCase() + "_" + new LocalDateTime().toString();

        if (mimeType.equals(MIME_TYPE_OPML)) {
            if (retainCategories.length > 0) {
                mRetainCategories = retainCategories[0];
            }//w  ww.j a  va2s  .c  o m
            intent.putExtra(Intent.EXTRA_TITLE, title);
            startActivityForResult(intent, REQUEST_CODE_EXPORT_SUBSCRIPTIONS);
        } else if (mimeType.equals(MIME_TYPE_JSON)) {
            intent.putExtra(Intent.EXTRA_TITLE, title + ".json");
            startActivityForResult(intent, REQUEST_CODE_EXPORT_SAVED_ENTRIES);
        }
    }
}

From source file:com.quinsoft.zeidon.standardoe.WriteOisToJsonStream.java

License:Open Source License

@Override
public void writeToStream(SerializeOi options, Writer writer) {
    this.viewList = options.getViewList();
    this.options = options;
    if (options.getFlags() == null)
        flags = EnumSet.noneOf(WriteOiFlags.class);
    else/* w  ww .  j a v  a2s. co  m*/
        flags = options.getFlags();
    if (!flags.contains(WriteOiFlags.INCREMENTAL))
        throw new ZeidonException("This JSON stream writer intended for writing incremental.");

    // Create a set of all the OIs and turn off the record owner flag.  The record owner
    // flag will be used to determine if a linked EI has been written to the stream.
    for (View view : viewList) {
        ObjectInstance oi = ((InternalView) view).getViewImpl().getObjectInstance();
        ois.add(oi);
        for (EntityInstanceImpl ei = oi.getRootEntityInstance(); ei != null; ei = ei.getNextTwin())
            ei.setRecordOwner(false);
    }

    JsonFactory jsonF = new JsonFactory();
    try {
        jg = jsonF.createGenerator(writer);
        if (!options.isCompressed())
            jg.useDefaultPrettyPrinter(); // enable indentation just to make debug/testing easier

        jg.writeStartObject();

        // Write meta info for entire JSON object.
        jg.writeObjectFieldStart(".meta");
        jg.writeStringField("version", VERSION);
        if (options.isWriteDate())
            jg.writeStringField("datetime", new LocalDateTime().toString());
        jg.writeEndObject();

        jg.writeArrayFieldStart("OIs");

        for (View view : viewList) {
            currentView = view;
            jg.writeStartObject();
            writeOi(view);
            jg.writeEndObject();
        }
        jg.writeEndArray();
        jg.writeEndObject();
        jg.close();
    } catch (Exception e) {
        throw ZeidonException.wrapException(e);
    }
}

From source file:com.ramzcalender.RWeekCalendar.java

License:Open Source License

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    nowView.setVisibility(View.GONE);

    /**//from w w  w.  j a v a2  s  . c  om
     * Checking for any customization values
     */

    if (getArguments().containsKey(CALENDER_BACKGROUND)) {

        mBackground.setBackgroundColor(getArguments().getInt(CALENDER_BACKGROUND));

    }

    if (getArguments().containsKey(DATE_SELECTOR_BACKGROUND)) {

        selectorDateIndicatorValue = getArguments().getString(DATE_SELECTOR_BACKGROUND);

    }

    if (getArguments().containsKey(CURRENT_DATE_BACKGROUND)) {

        currentDateIndicatorValue = getArguments().getInt(CURRENT_DATE_BACKGROUND);

    }

    if (getArguments().containsKey(CALENDER_TYPE)) {

        calenderType = getArguments().getInt(CALENDER_TYPE);
    }

    if (getArguments().containsKey(PRIMARY_BACKGROUND)) {

        monthView.setTextColor(getArguments().getInt(PRIMARY_BACKGROUND));
        primaryTextColor = getArguments().getInt(PRIMARY_BACKGROUND);

    }

    if (getArguments().containsKey(SECONDARY_BACKGROUND)) {

        nowView.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        sundayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        mondayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        tuesdayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        wednesdayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        thursdayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        fridayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));
        saturdayTv.setTextColor(getArguments().getInt(SECONDARY_BACKGROUND));

    }

    if (getArguments().containsKey(PACKAGENAME)) {

        PAKAGENAMEVALUE = getArguments().getString(PACKAGENAME);//its for showing the resource value from the parent package

    }

    if (getArguments().containsKey(NOW_BACKGROUND)) {

        Resources resources = getResources();
        nowView.setBackgroundResource(resources.getIdentifier(
                getArguments().getString(RWeekCalendar.NOW_BACKGROUND), "drawable", PAKAGENAMEVALUE));

    }

    //----------------------------------------------------------------------------------------------//

    /*If the selected calender is FDF Calender the resent the day names according to the starting days*/
    if (calenderType != NORMAL_CALENDER) {
        int startingDate = new LocalDateTime().dayOfWeek().get();
        if (startingDate == 1) {

            sundayTv.setText("Mon");
            mondayTv.setText("Tue");
            tuesdayTv.setText("Wed");
            wednesdayTv.setText("Thu");
            thursdayTv.setText("Fri");
            fridayTv.setText("Sat");
            saturdayTv.setText("Sun");

        } else if (startingDate == 2) {

            sundayTv.setText("Tue");
            mondayTv.setText("Wed");
            tuesdayTv.setText("Thu");
            wednesdayTv.setText("Fri");
            thursdayTv.setText("Sat");
            fridayTv.setText("Sun");
            saturdayTv.setText("Mon");

        } else if (startingDate == 3) {

            sundayTv.setText("Wed");
            mondayTv.setText("Thu");
            tuesdayTv.setText("Fri");
            wednesdayTv.setText("Sat");
            thursdayTv.setText("Sun");
            fridayTv.setText("Mon");
            saturdayTv.setText("Tue");

        } else if (startingDate == 4) {

            sundayTv.setText("Thu");
            mondayTv.setText("Fri");
            tuesdayTv.setText("Sat");
            wednesdayTv.setText("Sun");
            thursdayTv.setText("Mon");
            fridayTv.setText("Tue");
            saturdayTv.setText("Wed");

        } else if (startingDate == 5) {

            sundayTv.setText("Fri");
            mondayTv.setText("Sat");
            tuesdayTv.setText("Sun");
            wednesdayTv.setText("Mon");
            thursdayTv.setText("Tue");
            fridayTv.setText("Wed");
            saturdayTv.setText("Thu");

        } else if (startingDate == 6) {

            sundayTv.setText("Sat");
            mondayTv.setText("Sun");
            tuesdayTv.setText("Mon");
            wednesdayTv.setText("Tue");
            thursdayTv.setText("Wed");
            fridayTv.setText("Thu");
            saturdayTv.setText("Fri");

        }
    }

    /*Setting Calender Adaptor*/

    mAdaptor = new CalenderAdaptor(getActivity().getSupportFragmentManager());
    pager.setAdapter(mAdaptor);

    /*CalUtil is called*/

    CalUtil mCal = new CalUtil();
    //date calculation called according to the typr
    if (calenderType != NORMAL_CALENDER) {
        mCal.calculate(mStartDate, FDF_CALENDER);
    } else {
        mCal.calculate(mStartDate, NORMAL_CALENDER);
    }

    mStartDate = mCal.getStartDate();//sets start date from CalUtil

    //Setting the month name and selected date listener
    monthView.setText(selectedDate.monthOfYear().getAsShortText() + " "
            + selectedDate.year().getAsShortText().toUpperCase());
    calenderListener.onSelectDate(selectedDate);

    CURRENT_WEEK_POSITION = Weeks.weeksBetween(mStartDate, selectedDate).getWeeks();

    pager.setCurrentItem(CURRENT_WEEK_POSITION);
    /*Week change Listener*/

    pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int weekNumber) {

            int addDays = weekNumber * 7;

            selectedDate = mStartDate.plusDays(addDays); //add 7 days to the selected date

            monthView.setText(selectedDate.monthOfYear().getAsShortText() + "-"
                    + selectedDate.year().getAsShortText().toUpperCase());

            if (weekNumber == CURRENT_WEEK_POSITION) {

                //the first week comes to view
                nowView.setVisibility(View.GONE);

            } else {

                //the first week goes from view nowView set visible for Quick return to first week

                nowView.setVisibility(View.VISIBLE);
            }

        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

    /**
     * Change view to  the date of the current week
     */

    nowView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            calenderListener.onSelectDate(new LocalDateTime());

            pager.setCurrentItem(CURRENT_WEEK_POSITION);

        }
    });

    /**
     * For quick selection of a date.Any picker or custom date picker can de used
     */
    monthView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            calenderListener.onSelectPicker();

        }
    });

}

From source file:com.ramzcalender.RWeekCalendar.java

License:Open Source License

/**
 * Notify the selected date main page//from  w ww .  ja v  a  2 s .co m
 *
 * @param mSelectedDate
 */
public void getSelectedDate(LocalDateTime mSelectedDate, boolean fromUservisblity) {
    if (pager.getCurrentItem() == CURRENT_WEEK_POSITION) {
        if (fromUservisblity == true) {
            calenderListener.onSelectDate(new LocalDateTime());
        } else {
            calenderListener.onSelectDate(mSelectedDate);
        }

    } else {
        calenderListener.onSelectDate(mSelectedDate);
    }

}

From source file:com.ramzcalender.utils.CalUtil.java

License:Open Source License

/**
 * Initial calculation of the week/*from   w w w.j  a  v a2 s.  c  om*/
 *
 * @param mStartDate
 */
public void calculate(LocalDateTime mStartDate, int type) {

    //Initializing Start with current month
    final LocalDateTime currentDateTime = mStartDate;

    setStartDate(currentDateTime.getYear(), currentDateTime.getMonthOfYear(), currentDateTime.getDayOfMonth());

    /*Check for difference of weeks for alignment of days*/
    int weekGap = CalUtil.mDateGap(currentDateTime.dayOfWeek().getAsText().substring(0, 3).toLowerCase());

    if (weekGap != 0) {

        //If the there is week gap we need to maintain in the calender else alignment will be a mess

        if (type == RWeekCalendar.FDF_CALENDER) {
            //If the  week gap is in FDF calender first get the current days number of the week
            int currentWeekNumber = new LocalDateTime().dayOfWeek().get();
            //Subtract it with the rest of the days(Week gap) to get the rest of the days
            weekGap = weekGap - currentWeekNumber;
        }

        //This will add the additional days
        LocalDateTime ldt = mStartDate.minusDays(weekGap);

        // Set the the new startDate after new calculated days
        setStartDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth());

    }

    else {

        //Some times the week gap will be zero in that case If the selected calender is FDFCalender
        if (type == RWeekCalendar.FDF_CALENDER) {

            //Subtract total days of week (7) with the week day number of current date

            int currentWeekNumber = 7 - new LocalDateTime().dayOfWeek().get();

            if (currentWeekNumber != 0) {

                // Set the the new startDate after new calculated days

                LocalDateTime ldt = mStartDate.minusDays(currentWeekNumber);
                setStartDate(ldt.getYear(), ldt.getMonthOfYear(), ldt.getDayOfMonth());
            }

        }
    }
}

From source file:com.ramzcalender.WeekFragment.java

License:Open Source License

@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
    super.setUserVisibleHint(isVisibleToUser);

    /**/*w w  w  . j  av  a2  s  .  c o m*/
     * Reset date to first day of week when week goes from the view
     */

    if (isVisibleToUser) {

        if (dateInWeekArray.size() > 0)
            RWeekCalendar.getInstance().getSelectedDate(dateInWeekArray.get(0), true);

    } else {
        if (mSelectedDate != null) {
            if (RWeekCalendar.calenderType == RWeekCalendar.NORMAL_CALENDER) {
                //Resetting the day when current week scrolled or hidden
                if (datePosition != RWeekCalendar.CURRENT_WEEK_POSITION) {
                    textViewArray[0].setBackgroundResource(selectorDateIndicatorValue);

                    textViewArray[1].setBackgroundColor(Color.TRANSPARENT);
                    textViewArray[2].setBackgroundColor(Color.TRANSPARENT);
                    textViewArray[3].setBackgroundColor(Color.TRANSPARENT);
                    textViewArray[4].setBackgroundColor(Color.TRANSPARENT);
                    textViewArray[5].setBackgroundColor(Color.TRANSPARENT);
                    textViewArray[6].setBackgroundColor(Color.TRANSPARENT);
                } else {
                    //if the scrolled week is the current week then reset the selection to the current date

                    int position = new LocalDateTime().dayOfWeek().get();
                    textViewArray[position].setBackgroundResource(selectorDateIndicatorValue);
                    mDateSelectedBackground(position);
                }
            } else {
                //if the scrolled week is the current week then reset the selection to the current date for FDFcalender

                textViewArray[0].setBackgroundResource(selectorDateIndicatorValue);
                textViewArray[1].setBackgroundColor(Color.TRANSPARENT);
                textViewArray[2].setBackgroundColor(Color.TRANSPARENT);
                textViewArray[3].setBackgroundColor(Color.TRANSPARENT);
                textViewArray[4].setBackgroundColor(Color.TRANSPARENT);
                textViewArray[5].setBackgroundColor(Color.TRANSPARENT);
                textViewArray[6].setBackgroundColor(Color.TRANSPARENT);
            }
        }

    }

}

From source file:com.sandata.lab.wcf.lookup.impl.RestLookupTablesService.java

License:Open Source License

private void updateCache(final String key, final List value) {

    lastCacheUpdateTime = new LocalDateTime();
    lookupTableCache.put(key, value);//from  ww  w. j  ava  2 s  .  com
}