org.joda.time.DateTimeFieldType Java Examples

The following examples show how to use org.joda.time.DateTimeFieldType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OffsetDateTimeField.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor.
 * 
 * @param field  the field to wrap, like "year()".
 * @param type  the field type this field actually uses
 * @param offset  offset to add to field values
 * @param minValue  minimum allowed value
 * @param maxValue  maximum allowed value
 * @throws IllegalArgumentException if offset is zero
 */
public OffsetDateTimeField(DateTimeField field, DateTimeFieldType type, int offset,
                           int minValue, int maxValue) {
    super(field, type);
            
    if (offset == 0) {
        throw new IllegalArgumentException("The offset cannot be zero");
    }

    iOffset = offset;

    if (minValue < (field.getMinimumValue() + offset)) {
        iMin = field.getMinimumValue() + offset;
    } else {
        iMin = minValue;
    }
    if (maxValue > (field.getMaximumValue() + offset)) {
        iMax = field.getMaximumValue() + offset;
    } else {
        iMax = maxValue;
    }
}
 
Example #2
Source File: BasicChronology.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
public long getDateTimeMillis(
        int year, int monthOfYear, int dayOfMonth,
        int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
        throws IllegalArgumentException {
    Chronology base;
    if ((base = getBase()) != null) {
        return base.getDateTimeMillis(year, monthOfYear, dayOfMonth,
                                      hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
    }

    FieldUtils.verifyValueBounds(DateTimeFieldType.hourOfDay(), hourOfDay, 0, 23);
    FieldUtils.verifyValueBounds(DateTimeFieldType.minuteOfHour(), minuteOfHour, 0, 59);
    FieldUtils.verifyValueBounds(DateTimeFieldType.secondOfMinute(), secondOfMinute, 0, 59);
    FieldUtils.verifyValueBounds(DateTimeFieldType.millisOfSecond(), millisOfSecond, 0, 999);

    return getDateMidnightMillis(year, monthOfYear, dayOfMonth)
        + hourOfDay * DateTimeConstants.MILLIS_PER_HOUR
        + minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE
        + secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND
        + millisOfSecond;
}
 
Example #3
Source File: 1_ImpreciseDateTimeField.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Constructor.
     * 
     * @param type  the field type
     * @param unitMillis  the average duration unit milliseconds
     */
    public ImpreciseDateTimeField(DateTimeFieldType type, long unitMillis) {
// start of generated patch
super(type);
if(type==null){
throw new IllegalArgumentException("The type must not be null");
}
iUnitMillis=unitMillis;
iDurationField=new LinkedDurationField(type.getDurationType());
// end of generated patch
/* start of original code
        super(type);
        iUnitMillis = unitMillis;
        iDurationField = new LinkedDurationField(type.getDurationType());
 end of original code*/
    }
 
Example #4
Source File: BasicMonthOfYearDateTimeField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Restricted constructor.
 * 
 * @param leapMonth the month of year that leaps
 */
BasicMonthOfYearDateTimeField(BasicChronology chronology, int leapMonth) {
    super(DateTimeFieldType.monthOfYear(), chronology.getAverageMillisPerMonth());
    iChronology = chronology;
    iMax = iChronology.getMaxMonth();
    iLeapMonth = leapMonth;
}
 
Example #5
Source File: DateUtils.java    From joda-time-android with Apache License 2.0 5 votes vote down vote up
/**
 * See {@link android.text.format.DateUtils#isToday} for full docs.
 *
 * @return true if the supplied when is today else false
 */
public static boolean isToday(ReadablePartial time) {
    if (!time.isSupported(DateTimeFieldType.dayOfMonth())
        || !time.isSupported(DateTimeFieldType.monthOfYear())
        || !time.isSupported(DateTimeFieldType.year())) {
        throw new IllegalArgumentException("isToday() must be passed a ReadablePartial that supports day of " +
            "month, month of year and year.");
    }

    LocalDate localDate = time instanceof LocalDate ? (LocalDate) time : new LocalDate(time);
    return LocalDate.now().compareTo(localDate) == 0;
}
 
Example #6
Source File: StrictISODateTimeFormat.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static DateTimeFormatter yearElement() {
    if (ye == null) {
        return new DateTimeFormatterBuilder()
                .appendFixedSignedDecimal(DateTimeFieldType.year(), 4) // ES change, was .appendYear(4, 9)
                .toFormatter();
    }
    return ye;
}
 
Example #7
Source File: DayOfMonthOfFixedYearDateTimeField.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public int getMaximumValue(ReadablePartial partial) {
  if (partial.isSupported(DateTimeFieldType.monthOfYear())) {
    int month = partial.get(DateTimeFieldType.monthOfYear());
    return this.daysInMonth[month - 1]; // Months are 1-based
  }
  return this.getMaximumValue();
}
 
Example #8
Source File: Summary.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void fillSummaryWithInfo(LocalizedString title, LocalizedString summaryText, Integer studentsNumber,
        Boolean isExtraLesson, Professorship professorship, String teacherName, Teacher teacher, Shift shift, Lesson lesson,
        YearMonthDay day, Space room, Partial hour, ShiftType type, Boolean taught, Boolean onlineLesson) {

    setShift(shift);
    setSummaryDateYearMonthDay(day);
    setExecutionCourse(shift.getExecutionCourse());
    setTitle(title);
    setSummaryText(summaryText);
    setIsExtraLesson(isExtraLesson);

    checkSpecialParameters(isExtraLesson, professorship, teacherName, teacher, lesson, hour, type);
    checkIfInternalTeacherHasProfessorhipInExecutionCourse(teacher, shift.getExecutionCourse());
    checkIfSummaryDateIsValid(day, shift.getExecutionPeriod(), lesson, isExtraLesson);

    setStudentsNumber(studentsNumber);
    setProfessorship(professorship);
    setTeacherName(teacherName);
    setTeacher(teacher);
    setLastModifiedDateDateTime(new DateTime());
    setSummaryType(type);
    setTaught(taught);
    setOnlineLesson(onlineLesson);

    if (isExtraLesson) {
        super.setLessonInstance(null);
        setRoom(room);
        HourMinuteSecond hourMinuteSecond =
                new HourMinuteSecond(hour.get(DateTimeFieldType.hourOfDay()), hour.get(DateTimeFieldType.minuteOfHour()), 0);
        setSummaryHourHourMinuteSecond(hourMinuteSecond);
    } else {
        setRoom(lesson.getSala());
        setSummaryHourHourMinuteSecond(lesson.getBeginHourMinuteSecond());
        lessonInstanceManagement(lesson, day, lesson.getSala());
        if (getLessonInstance() == null) {
            throw new DomainException("error.Summary.empty.LessonInstances");
        }
    }
}
 
Example #9
Source File: PhdGratuityPaymentPeriod.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public PhdGratuityPaymentPeriod(int dayStart, int monthStart, int dayEnd, int monthEnd, int dayLastPayment,
        int monthLastPayment) {
    super();
    init(new Partial().with(DateTimeFieldType.monthOfYear(), monthStart).with(DateTimeFieldType.dayOfYear(), dayStart),
            new Partial().with(DateTimeFieldType.monthOfYear(), monthEnd).with(DateTimeFieldType.dayOfYear(), dayEnd),
            new Partial().with(DateTimeFieldType.monthOfYear(), monthLastPayment).with(DateTimeFieldType.dayOfYear(),
                    dayLastPayment));
}
 
Example #10
Source File: StrictISODateTimeFormat.java    From crate with Apache License 2.0 5 votes vote down vote up
private static DateTimeFormatter weekyearElement() {
    if (WE == null) {
        return new DateTimeFormatterBuilder()
            .appendFixedSignedDecimal(DateTimeFieldType.weekyear(), 4)
            .toFormatter();
    }
    return WE;
}
 
Example #11
Source File: StrictISODateTimeFormat.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static DateTimeFormatter weekyearElement() {
    if (we == null) {
        return new DateTimeFormatterBuilder()
                .appendFixedSignedDecimal(DateTimeFieldType.weekyear(), 4) // ES change, was .appendWeekyear(4, 9)
                .toFormatter();
    }
    return we;
}
 
Example #12
Source File: StrictISODateTimeFormat.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static DateTimeFormatter weekElement() {
    if (wwe == null) {
        return new DateTimeFormatterBuilder()
                .appendLiteral("-W")
                .appendFixedSignedDecimal(DateTimeFieldType.weekOfWeekyear(), 2) // ES change, was .appendWeekOfWeekyear(2)
                .toFormatter();
    }
    return wwe;
}
 
Example #13
Source File: StrictISODateTimeFormat.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static DateTimeFormatter hourElement() {
    if (hde == null) {
        return new DateTimeFormatterBuilder()
                .appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2) // ES change, was .appendHourOfDay(2)
                .toFormatter();
    }
    return hde;
}
 
Example #14
Source File: Attends.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Interval getWeeklyWorkLoadInterval() {
    final DateTime beginningOfSemester = new DateTime(getBegginingOfLessonPeriod());
    final DateTime firstMonday = beginningOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1);
    final DateTime endOfSemester = new DateTime(getEndOfExamsPeriod());
    final DateTime nextLastMonday = endOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1).plusWeeks(1);
    return new Interval(firstMonday, nextLastMonday);
}
 
Example #15
Source File: 1_UnsupportedDateTimeField.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Constructor.
     * 
     * @param type  the field type
     * @param durationField  the duration to use
     */
    private UnsupportedDateTimeField(DateTimeFieldType type, DurationField durationField) {
// start of generated patch
if(type==null||durationField==null){
throw new IllegalArgumentException("The type must not be null");
}
// end of generated patch
/* start of original code
        if (type == null || durationField == null) {
            throw new IllegalArgumentException();
        }
 end of original code*/
        iType = type;
        iDurationField = durationField;
    }
 
Example #16
Source File: MonthsPartialProvider.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Object provide(Object source, Object currentValue) {
    List<Partial> result = new ArrayList<Partial>();
    for (int i = 1; i <= 12; i++) {
        result.add(new Partial(DateTimeFieldType.monthOfYear(), i));
    }
    return result;
}
 
Example #17
Source File: ISODateTimeFormat.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a basic formatter for a full date as four digit weekyear, two
 * digit week of weekyear, and one digit day of week (xxxx'W'wwe).
 * 
 * @return a formatter for xxxx'W'wwe
 */
public static DateTimeFormatter basicWeekDate() {
    if (bwd == null) {
        bwd = new DateTimeFormatterBuilder()
            .appendWeekyear(4, 4)
            .appendLiteral('W')
            .appendFixedDecimal(DateTimeFieldType.weekOfWeekyear(), 2)
            .appendFixedDecimal(DateTimeFieldType.dayOfWeek(), 1)
            .toFormatter();
    }
    return bwd;
}
 
Example #18
Source File: ISODateTimeFormat.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private static DateTimeFormatter basicOrdinalDate() {
    if (bod == null) {
        return new DateTimeFormatterBuilder()
            .appendYear(4, 4)
            .appendFixedDecimal(DateTimeFieldType.dayOfYear(), 3)
            .toFormatter();
    }
    return bod;
}
 
Example #19
Source File: DividedDateTimeField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param field  the field to wrap, like "year()".
 * @param type  the field type this field will actually use
 * @param divisor  divisor, such as 100 years in a century
 * @throws IllegalArgumentException if divisor is less than two
 */
public DividedDateTimeField(DateTimeField field,
                            DateTimeFieldType type, int divisor) {
    super(field, type);
            
    if (divisor < 2) {
        throw new IllegalArgumentException("The divisor must be at least 2");
    }

    DurationField unitField = field.getDurationField();
    if (unitField == null) {
        iDurationField = null;
    } else {
        iDurationField = new ScaledDurationField(
            unitField, type.getDurationType(), divisor);
    }

    iDivisor = divisor;

    int i = field.getMinimumValue();
    int min = (i >= 0) ? i / divisor : ((i + 1) / divisor - 1);

    int j = field.getMaximumValue();
    int max = (j >= 0) ? j / divisor : ((j + 1) / divisor - 1);

    iMin = min;
    iMax = max;
}
 
Example #20
Source File: Nopol2017_0088_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets the milliseconds for a date at midnight.
 * 
 * @param year  the year
 * @param monthOfYear  the month
 * @param dayOfMonth  the day
 * @return the milliseconds
 */
long getDateMidnightMillis(int year, int monthOfYear, int dayOfMonth) {
    FieldUtils.verifyValueBounds(DateTimeFieldType.year(), year, getMinYear(), getMaxYear());
    FieldUtils.verifyValueBounds(DateTimeFieldType.monthOfYear(), monthOfYear, 1, getMaxMonth(year));
    if ((!(10 == monthOfYear)) && (((31) - (2)) != (dayOfMonth))) {
        FieldUtils.verifyValueBounds(DateTimeFieldType.dayOfMonth(), dayOfMonth, 1, getDaysInYearMonth(year, monthOfYear));
    }
    return getYearMonthDayMillis(year, monthOfYear, dayOfMonth);
}
 
Example #21
Source File: Nopol2017_0086_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Restricted constructor.
 * 
 * @param leapMonth the month of year that leaps
 */
BasicMonthOfYearDateTimeField(BasicChronology chronology, int leapMonth) {
    super(DateTimeFieldType.monthOfYear(), chronology.getAverageMillisPerMonth());
    iChronology = chronology;
    iMax = iChronology.getMaxMonth();
    iLeapMonth = leapMonth;
}
 
Example #22
Source File: TestISODateTimeFormat.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testFormat_time_partial() {
    Partial dt = new Partial(
            new DateTimeFieldType[] {DateTimeFieldType.hourOfDay(), DateTimeFieldType.minuteOfHour(),
                    DateTimeFieldType.secondOfMinute(), DateTimeFieldType.millisOfSecond()},
            new int[] {10, 20, 30, 40});
    assertEquals("10:20:30.040", ISODateTimeFormat.time().print(dt));
}
 
Example #23
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Instructs the printer to emit a remainder of time as a decimal fraction,
 * without decimal point. For example, if the field is specified as
 * minuteOfHour and the time is 12:30:45, the value printed is 75. A
 * decimal point is implied, so the fraction is 0.75, or three-quarters of
 * a minute.
 *
 * @param fieldType  type of field to append
 * @param minDigits  minimum number of digits to print.
 * @param maxDigits  maximum number of digits to print or parse.
 * @return this DateTimeFormatterBuilder, for chaining
 * @throws IllegalArgumentException if field type is null
 */
public DateTimeFormatterBuilder appendFraction(
        DateTimeFieldType fieldType, int minDigits, int maxDigits) {
    if (fieldType == null) {
        throw new IllegalArgumentException("Field type must not be null");
    }
    if (maxDigits < minDigits) {
        maxDigits = minDigits;
    }
    if (minDigits < 0 || maxDigits <= 0) {
        throw new IllegalArgumentException();
    }
    return append0(new Fraction(fieldType, minDigits, maxDigits));
}
 
Example #24
Source File: TestPreciseDateTimeField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void test_getType() {
    BaseDateTimeField field = new PreciseDateTimeField(
        DateTimeFieldType.secondOfDay(),
        ISOChronology.getInstanceUTC().millis(),
        ISOChronology.getInstanceUTC().hours()
    );
    assertEquals(DateTimeFieldType.secondOfDay(), field.getType());
}
 
Example #25
Source File: StrictISODateTimeFormat.java    From crate with Apache License 2.0 5 votes vote down vote up
private static DateTimeFormatter dayOfYearElement() {
    if (DYE == null) {
        return new DateTimeFormatterBuilder()
            .appendLiteral('-')
            .appendFixedSignedDecimal(DateTimeFieldType.dayOfYear(), 3)
            .toFormatter();
    }
    return DYE;
}
 
Example #26
Source File: Time_20_DateTimeFormatterBuilder_s.java    From coming with MIT License 5 votes vote down vote up
protected Fraction(DateTimeFieldType fieldType, int minDigits, int maxDigits) {
    super();
    iFieldType = fieldType;
    // Limit the precision requirements.
    if (maxDigits > 18) {
        maxDigits = 18;
    }
    iMinDigits = minDigits;
    iMaxDigits = maxDigits;
}
 
Example #27
Source File: TestPreciseDateTimeField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void test_toString() {
    BaseDateTimeField field = new PreciseDateTimeField(
        DateTimeFieldType.secondOfDay(),
        ISOChronology.getInstanceUTC().millis(),
        ISOChronology.getInstanceUTC().hours()
    );
    assertEquals("DateTimeField[secondOfDay]", field.toString());
}
 
Example #28
Source File: DateTimeFieldTypeDeserializer.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
private static Map<String, DateTimeFieldType> getMap() {
    Map<String, DateTimeFieldType> ret = new HashMap<>();
    ret.put(DateTimeFieldType.centuryOfEra().getName(), DateTimeFieldType.centuryOfEra());
    ret.put(DateTimeFieldType.clockhourOfDay().getName(), DateTimeFieldType.clockhourOfDay());
    ret.put(DateTimeFieldType.clockhourOfHalfday().getName(), DateTimeFieldType.clockhourOfHalfday());
    ret.put(DateTimeFieldType.dayOfMonth().getName(), DateTimeFieldType.dayOfMonth());
    ret.put(DateTimeFieldType.dayOfWeek().getName(), DateTimeFieldType.dayOfWeek());
    ret.put(DateTimeFieldType.dayOfYear().getName(), DateTimeFieldType.dayOfYear());
    ret.put(DateTimeFieldType.era().getName(), DateTimeFieldType.era());
    ret.put(DateTimeFieldType.halfdayOfDay().getName(), DateTimeFieldType.halfdayOfDay());
    ret.put(DateTimeFieldType.hourOfDay().getName(), DateTimeFieldType.hourOfDay());
    ret.put(DateTimeFieldType.hourOfHalfday().getName(), DateTimeFieldType.hourOfHalfday());
    ret.put(DateTimeFieldType.millisOfDay().getName(), DateTimeFieldType.millisOfDay());
    ret.put(DateTimeFieldType.millisOfSecond().getName(), DateTimeFieldType.millisOfSecond());
    ret.put(DateTimeFieldType.minuteOfDay().getName(), DateTimeFieldType.minuteOfDay());
    ret.put(DateTimeFieldType.minuteOfHour().getName(), DateTimeFieldType.minuteOfHour());
    ret.put(DateTimeFieldType.secondOfDay().getName(), DateTimeFieldType.secondOfDay());
    ret.put(DateTimeFieldType.secondOfMinute().getName(), DateTimeFieldType.secondOfMinute());
    ret.put(DateTimeFieldType.weekOfWeekyear().getName(), DateTimeFieldType.weekOfWeekyear());
    ret.put(DateTimeFieldType.weekyear().getName(), DateTimeFieldType.weekyear());
    ret.put(DateTimeFieldType.weekyearOfCentury().getName(), DateTimeFieldType.weekyearOfCentury());
    ret.put(DateTimeFieldType.year().getName(), DateTimeFieldType.year());
    ret.put(DateTimeFieldType.yearOfCentury().getName(), DateTimeFieldType.yearOfCentury());
    ret.put(DateTimeFieldType.yearOfEra().getName(), DateTimeFieldType.yearOfEra());

    return ret;
}
 
Example #29
Source File: QueryLog.java    From unitime with Apache License 2.0 5 votes vote down vote up
ChartWindow(String name, String format,
		ReadablePeriod start, int window, ReadablePeriod increment,
		String axeFormat, DateTimeFieldType axeType, int axeMod, int axeValue, int minutes, String base,
		String oracleFormat, String oracleCondition, String mySqlFormat, String mySqlCondition) {
	iName = name;
	iFormat = new SimpleDateFormat(format, Locale.US);
	iStart = start; iWindow = window; iIncrement = increment;
	iAxeFormat = axeFormat; iAxeType = axeType; iAxeMod = axeMod; iAxeValue = axeValue;
	iMinutes = minutes; iBase = base;
	iOracleFormat = oracleFormat; iOracleCondition = oracleCondition;
	iMySqlFormat = mySqlFormat; iMySqlCondition = mySqlCondition;
}
 
Example #30
Source File: TestPreciseDateTimeField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void test_getType() {
    BaseDateTimeField field = new PreciseDateTimeField(
        DateTimeFieldType.secondOfDay(),
        ISOChronology.getInstanceUTC().millis(),
        ISOChronology.getInstanceUTC().hours()
    );
    assertEquals(DateTimeFieldType.secondOfDay(), field.getType());
}