Example usage for org.joda.time LocalDateTime dayOfWeek

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

Introduction

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

Prototype

public Property dayOfWeek() 

Source Link

Document

Get the day of week property which provides access to advanced functionality.

Usage

From source file:com.gs.fw.common.mithra.test.cacheloader.PYETopLevelLoaderFactory.java

License:Apache License

protected Timestamp shiftBusinessDate(Timestamp businessDate) {
    LocalDate localDate = new LocalDate(businessDate);
    int year = localDate.getYear();
    LocalDateTime pye = new LocalDateTime(year - 1, 12, 31, 23, 59, 0, 0);
    int dayOfWeek = pye.dayOfWeek().get();
    if (dayOfWeek > 5) {
        pye = pye.minusDays(dayOfWeek - 5);
    }/*  w  w w.  ja va  2  s  . com*/
    return new Timestamp(pye.toDateTime().getMillis());
}

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

License:Open Source License

/**
 * Initial calculation of the week//from  w  w  w.  j ava2s  .  c  o  m
 *
 * @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.weekcalendar.utils.CalUtil.java

License:Open Source License

/**
 * Initial calculation of the week// w  ww .java  2  s.  c  o m
 */
public void calculate(Context mContext) {

    //Initializing JodaTime
    JodaTimeAndroid.init(mContext);

    //Initializing Start with current month
    final LocalDateTime currentDateTime = new LocalDateTime();

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

    int weekGap = CalUtil.mDateGap(currentDateTime.dayOfWeek().getAsText().substring(0, 3).toLowerCase());

    if (weekGap != 0) {
        //if the current date is not the first day of the week the rest of days is added

        //Calendar set to the current date
        Calendar calendar = Calendar.getInstance();

        calendar.add(Calendar.DAY_OF_YEAR, -weekGap);

        //now the date is weekGap days back
        LocalDateTime ldt = LocalDateTime.fromCalendarFields(calendar);

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

    }
}

From source file:org.gnucash.android.model.Budget.java

License:Apache License

/**
 * Returns the timestamp of the start of current period of the budget
 * @return Start timestamp in milliseconds
 *//*from   w  w  w.j a v a  2s. co  m*/
public long getStartofCurrentPeriod() {
    LocalDateTime localDate = new LocalDateTime();
    int interval = mRecurrence.getPeriodType().getMultiplier();
    switch (mRecurrence.getPeriodType()) {
    case DAY:
        localDate = localDate.millisOfDay().withMinimumValue().plusDays(interval);
        break;
    case WEEK:
        localDate = localDate.dayOfWeek().withMinimumValue().minusDays(interval);
        break;
    case MONTH:
        localDate = localDate.dayOfMonth().withMinimumValue().minusMonths(interval);
        break;
    case YEAR:
        localDate = localDate.dayOfYear().withMinimumValue().minusYears(interval);
        break;
    }
    return localDate.toDate().getTime();
}

From source file:org.gnucash.android.model.Budget.java

License:Apache License

/**
 * Returns the end timestamp of the current period
 * @return End timestamp in milliseconds
 *///w  ww  . j a  va  2s  . c om
public long getEndOfCurrentPeriod() {
    LocalDateTime localDate = new LocalDateTime();
    int interval = mRecurrence.getPeriodType().getMultiplier();
    switch (mRecurrence.getPeriodType()) {
    case DAY:
        localDate = localDate.millisOfDay().withMaximumValue().plusDays(interval);
        break;
    case WEEK:
        localDate = localDate.dayOfWeek().withMaximumValue().plusWeeks(interval);
        break;
    case MONTH:
        localDate = localDate.dayOfMonth().withMaximumValue().plusMonths(interval);
        break;
    case YEAR:
        localDate = localDate.dayOfYear().withMaximumValue().plusYears(interval);
        break;
    }
    return localDate.toDate().getTime();
}

From source file:org.gnucash.android.model.Budget.java

License:Apache License

public long getStartOfPeriod(int periodNum) {
    LocalDateTime localDate = new LocalDateTime(mRecurrence.getPeriodStart().getTime());
    int interval = mRecurrence.getPeriodType().getMultiplier() * periodNum;
    switch (mRecurrence.getPeriodType()) {
    case DAY:/*  www .  j  a  v a 2s.c om*/
        localDate = localDate.millisOfDay().withMinimumValue().plusDays(interval);
        break;
    case WEEK:
        localDate = localDate.dayOfWeek().withMinimumValue().minusDays(interval);
        break;
    case MONTH:
        localDate = localDate.dayOfMonth().withMinimumValue().minusMonths(interval);
        break;
    case YEAR:
        localDate = localDate.dayOfYear().withMinimumValue().minusYears(interval);
        break;
    }
    return localDate.toDate().getTime();
}

From source file:org.gnucash.android.model.Budget.java

License:Apache License

/**
 * Returns the end timestamp of the period
 * @param periodNum Number of the period
 * @return End timestamp in milliseconds of the period
 *//* w w w. j av  a  2  s  .  c o  m*/
public long getEndOfPeriod(int periodNum) {
    LocalDateTime localDate = new LocalDateTime();
    int interval = mRecurrence.getPeriodType().getMultiplier() * periodNum;
    switch (mRecurrence.getPeriodType()) {
    case DAY:
        localDate = localDate.millisOfDay().withMaximumValue().plusDays(interval);
        break;
    case WEEK:
        localDate = localDate.dayOfWeek().withMaximumValue().plusWeeks(interval);
        break;
    case MONTH:
        localDate = localDate.dayOfMonth().withMaximumValue().plusMonths(interval);
        break;
    case YEAR:
        localDate = localDate.dayOfYear().withMaximumValue().plusYears(interval);
        break;
    }
    return localDate.toDate().getTime();
}

From source file:playground.johannes.gsv.synPop.invermo.Date2TimeTask.java

License:Open Source License

private void setPlanDate(LocalDateTime dateTime, ProxyPlan plan) {
    plan.setAttribute(MIDKeys.PERSON_MONTH, dateTime.monthOfYear().getAsShortText(Locale.US));
    plan.setAttribute(CommonKeys.DAY, dateTime.dayOfWeek().getAsShortText(Locale.US));
}