Example usage for org.joda.time DateTimeFieldType dayOfWeek

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

Introduction

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

Prototype

public static DateTimeFieldType dayOfWeek() 

Source Link

Document

Get the day of week field type.

Usage

From source file:com.edoli.calendarlms.CalendarAdapter.java

License:Apache License

public CalendarAdapter(Context context, DateTime date, GridView gridView) {
    mContext = context;//from ww w  . ja v  a2 s  .  c om
    mDate = date;
    mGridView = gridView;

    int firstDayOfWeek = mDate.get(DateTimeFieldType.dayOfWeek());
    mMonth = mDate.getMonthOfYear();
    mDate = mDate.minusDays(firstDayOfWeek);
}

From source file:com.edoli.calendarlms.DayOfWeekAdapter.java

License:Apache License

public DayOfWeekAdapter(Context context) {
    mContext = context;//from w  w  w.jav a 2s. c  om
    mDate = DateTime.now();

    int firstDayOfWeek = mDate.get(DateTimeFieldType.dayOfWeek());
    mDate = mDate.minusDays(firstDayOfWeek);

    mHeight = (int) UnitUtils.convertToPixel(mContext, 18); // Default height of this adapter
}

From source file:com.linagora.obm.ui.page.CreateCalendarPage.java

License:Open Source License

private void selectDay(UIEvent eventToCreate) {
    DateTime dateTime = new DateTime(eventToCreate.getDateBegin());
    switch (dateTime.get(DateTimeFieldType.dayOfWeek())) {
    case 1:/*from www . j  a  v  a  2  s.c o m*/
        cba_repeatday_1.click();
        break;
    case 2:
        cba_repeatday_2.click();
        break;
    case 3:
        cba_repeatday_3.click();
        break;
    case 4:
        cba_repeatday_4.click();
        break;
    case 5:
        cba_repeatday_5.click();
        break;
    case 6:
        cba_repeatday_6.click();
        break;
    case 7:
        cba_repeatday_7.click();
        break;
    }
}

From source file:de.avanux.smartapplianceenabler.appliance.TimeOfDayOfWeek.java

License:Open Source License

public LocalDateTime toNextOccurrence(LocalDateTime now) {
    LocalDateTime dateTime = new LocalDateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(),
            getHour(), getMinute(), getSecond());
    while (dateTime.get(DateTimeFieldType.dayOfWeek()) != dayOfWeek) {
        dateTime = dateTime.plusDays(1);
    }//from   w ww  .  j  a va  2s.  co m
    return dateTime;
}

From source file:de.avanux.smartapplianceenabler.appliance.TimeOfDayOfWeek.java

License:Open Source License

public LocalDateTime toLastOccurrence(LocalDateTime now) {
    LocalDateTime dateTime = new LocalDateTime(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(),
            getHour(), getMinute(), getSecond());
    while (dateTime.get(DateTimeFieldType.dayOfWeek()) != dayOfWeek) {
        dateTime = dateTime.minusDays(1);
    }/*from  w ww  .j  a  v  a 2s  .  c  o  m*/
    return dateTime;
}

From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java

License:Open Source License

public void setField(Granulaarsus field, int value) {
    // ------ Time
    if (field == Granulaarsus.AM_PM) {
        try {// www.  j av  a  2  s . co m
            this.underlyingTime = (this.underlyingTime).withField(DateTimeFieldType.halfdayOfDay(), value);
            updateTimeRepresentation(field, null, false, SET_TYPE_OPERATION);
        } catch (Exception e) {
        }
    }
    if (field == Granulaarsus.HOUR_OF_HALF_DAY) {
        try {
            if (value == 12) {
                value = 0;
            }
            this.underlyingTime = (this.underlyingTime).withField(DateTimeFieldType.hourOfHalfday(), value);
            // NB! Tunni seadistamisel nullime ka minutid, et ei tekiks nt ankurdamisel kummalisi vrtuseid
            this.underlyingTime = (this.underlyingTime).withField(DateTimeFieldType.minuteOfHour(), 0);
            updateTimeRepresentation(field, null, false, SET_TYPE_OPERATION);
        } catch (Exception e) {
        }
    }
    if (field == Granulaarsus.MINUTE) {
        try {
            this.underlyingTime = (this.underlyingTime).withField(DateTimeFieldType.minuteOfHour(), value);
            updateTimeRepresentation(field, null, false, SET_TYPE_OPERATION);
        } catch (Exception e) {
        }
    }
    // ------ Kuup2evad ja n2dalad
    if (field == Granulaarsus.DAY_OF_WEEK) {
        try {
            this.underlyingDate = (this.underlyingDate).withField(DateTimeFieldType.dayOfWeek(), value);
            dateModified = true;
            updateDateRepresentation(field, null, false, SET_TYPE_OPERATION);
        } catch (Exception e) {
        }
    }
    if (field == Granulaarsus.WEEK_OF_YEAR) {
        try {
            this.underlyingDate = (this.underlyingDate).withField(DateTimeFieldType.weekOfWeekyear(), value);
            dateModified = true;
            updateDateRepresentation(field, null, false, SET_TYPE_OPERATION);
        } catch (Exception e) {
        }
    }
    if (field == Granulaarsus.DAY_OF_MONTH) {
        try {
            this.underlyingDate = (this.underlyingDate).withField(DateTimeFieldType.dayOfMonth(), value);
            dateModified = true;
            updateDateRepresentation(field, null, false, SET_TYPE_OPERATION);
        } catch (Exception e) {
        }
    }
    if (field == Granulaarsus.MONTH) {
        try {
            this.underlyingDate = (this.underlyingDate).withField(DateTimeFieldType.monthOfYear(), value);
            dateModified = true;
            updateDateRepresentation(field, null, false, SET_TYPE_OPERATION);
        } catch (Exception e) {
        }
    }
    if (field == Granulaarsus.YEAR) {
        try {
            this.underlyingDate = (this.underlyingDate).withField(DateTimeFieldType.year(), value);
            dateModified = true;
            updateDateRepresentation(field, null, false, SET_TYPE_OPERATION);
        } catch (Exception e) {
        }
    }
    if (field == Granulaarsus.YEAR_OF_CENTURY) {
        try {
            this.underlyingDate = (this.underlyingDate).withField(DateTimeFieldType.yearOfCentury(), value);
            dateModified = true;
            // NB! Toimib nagu tavalise aastaarvu muutmine
            updateDateRepresentation(field, null, false, SET_TYPE_OPERATION);
        } catch (Exception e) {
        }
    }
    if (field == Granulaarsus.CENTURY_OF_ERA) {
        try {
            this.underlyingDate = (this.underlyingDate).withField(DateTimeFieldType.centuryOfEra(), value);
            dateModified = true;
            updateDateRepresentation(field, null, false, SET_TYPE_OPERATION);
        } catch (Exception e) {
        }
    }
}

From source file:fi.hsl.parkandride.core.domain.DayType.java

License:EUPL

public static DayType valueOf(ReadableInstant timestamp) {
    return valueOf(
            Optional.ofNullable(timestamp).map(ts -> ts.get(DateTimeFieldType.dayOfWeek())).orElse(null));
}

From source file:fi.hsl.parkandride.core.domain.DayType.java

License:EUPL

public static DayType valueOf(ReadablePartial timestamp) {
    return valueOf(
            Optional.ofNullable(timestamp).map(ts -> ts.get(DateTimeFieldType.dayOfWeek())).orElse(null));
}

From source file:gg.db.datamodel.Periods.java

License:Open Source License

/**
 * Gets the adjusted start date: the date is adjusted to the first day of the period<BR/>
 * Depending on periodType, the date will be:
 * <UL>/*from w w  w  . j  a  v  a2  s  .  c  o m*/
 * <LI>First day of the week (monday)</LI>
 * <LI>First day of the month</LI>
 * <LI>First day of the year</LI>>
 * </UL>
 * Example:
 * <UL>
 * <LI>getAdjustedStartDate(new LocalDate(2006, 5, 20), PeriodType.DAY) should return: <B>05/20/2006</B></LI>
 * <LI>getAdjustedStartDate(new LocalDate(2006, 5, 20), PeriodType.WEEK) should return: <B>05/15/2006</B> (if Configuration.getWeekStartingOn() == MONDAY)</LI>
 * <LI>getAdjustedStartDate(new LocalDate(2006, 5, 20), PeriodType.MONTH) should return: <B>05/01/2006</B></LI>
 * <LI>getAdjustedStartDate(new LocalDate(2006, 5, 20), PeriodType.YEAR) should return: <B>01/01/2006</B></LI>
 * <LI>getAdjustedStartDate(new LocalDate(2006, 5, 20), PeriodType.FREE) should return: <B>05/20/2006</B></LI>
 * </UL>
 * @param date Date to adjust to the start of the period
 * @param periodType Type of the Period to adjust the period
 * @return Date adjusted to the start of the period
 */
public static LocalDate getAdjustedStartDate(LocalDate date, PeriodType periodType) {
    if (date == null || periodType == null) {
        throw new IllegalArgumentException("One of the following parameters is null: 'date', 'periodType'");
    }

    LocalDate adjustedStartDate = null;
    switch (periodType) {
    case DAY: // No adjustement to do
        adjustedStartDate = date;
        break;
    case FREE: // No adjustement to do
        adjustedStartDate = date;
        break;
    case WEEK: // Adjust the date to the first day of the week (Monday)
        adjustedStartDate = date.toDateMidnight()
                .withField(DateTimeFieldType.dayOfWeek(), DateTimeConstants.MONDAY).toLocalDate();
        break;
    case MONTH: // Adjust the date to the first day of the month (<MONTH>/01/<YEAR>)
        adjustedStartDate = date.withField(DateTimeFieldType.dayOfMonth(), 1);
        break;
    case YEAR: // Adjust the date to the first day of the year (01/01/<YEAR>)
        adjustedStartDate = date.withField(DateTimeFieldType.dayOfMonth(), 1)
                .withField(DateTimeFieldType.monthOfYear(), 1);
        break;
    default:
        throw new AssertionError("Unknown PeriodType"); // should never happen
    }

    assert (adjustedStartDate != null);
    return adjustedStartDate;
}

From source file:gg.db.datamodel.Periods.java

License:Open Source License

/**
 * Gets the adjusted end date: the date is adjusted to the last day of the period<BR/>
 * Depending on periodType, the date will be:
 * <UL>/*  w ww . jav  a  2s .  co m*/
 * <LI>Last day of the week (sunday)</LI>
 * <LI>Last day of the month</LI>
 * <LI>Last day of the year</LI>>
 * </UL>
 * Example:
 * <UL>
 * <LI>getAdjustedEndDate(new LocalDate(2006, 5, 20), PeriodType.DAY) should return: <B>05/20/2006</B></LI>
 * <LI>getAdjustedEndDate(new LocalDate(2006, 5, 20), PeriodType.WEEK) should return: <B>05/21/2006</B> (if Configuration.getWeekStartingOn() == MONDAY)</LI>
 * <LI>getAdjustedEndDate(new LocalDate(2006, 5, 20), PeriodType.MONTH) should return: <B>05/31/2006</B></LI>
 * <LI>getAdjustedEndDate(new LocalDate(2006, 5, 20), PeriodType.YEAR) should return: <B>12/31/2006</B></LI>
 * <LI>getAdjustedEndDate(new LocalDate(2006, 5, 20), PeriodType.FREE) should return: <B>05/20/2006</B></LI>
 * </UL>
 * @param date Date to adjust to the end of the period
 * @param periodType Type of the Period to adjust the date
 * @return Date adjusted to the end of the period
 */
public static LocalDate getAdjustedEndDate(LocalDate date, PeriodType periodType) {
    if (date == null || periodType == null) {
        throw new IllegalArgumentException("One of the following parameters is null: 'date', 'periodType'");
    }

    LocalDate adjustedEndDate = null;
    switch (periodType) {
    case DAY: // No adjustement to do
        adjustedEndDate = date;
        break;
    case FREE: // No adjustement to do
        adjustedEndDate = date;
        break;
    case WEEK: // Adjust the date to the last day of the week (sunday)
        adjustedEndDate = date.toDateMidnight()
                .withField(DateTimeFieldType.dayOfWeek(), DateTimeConstants.MONDAY + 6).toLocalDate();
        break;
    case MONTH: // Adjust the date to the last day of the month
        adjustedEndDate = date.withField(DateTimeFieldType.dayOfMonth(), 1).plusMonths(1).minusDays(1);
        break;
    case YEAR: // Adjust the date to the last day of the year (12/31/<YEAR>)
        adjustedEndDate = date.withField(DateTimeFieldType.dayOfMonth(), 1).plusMonths(1).minusDays(1)
                .withField(DateTimeFieldType.monthOfYear(), 12);
        break;
    default:
        throw new AssertionError("Unknown PeriodType"); // should never happen
    }

    assert (adjustedEndDate != null);
    return adjustedEndDate;
}