本文整理汇总了Java中org.joda.time.ReadablePartial类的典型用法代码示例。如果您正苦于以下问题:Java ReadablePartial类的具体用法?Java ReadablePartial怎么用?Java ReadablePartial使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReadablePartial类属于org.joda.time包,在下文中一共展示了ReadablePartial类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAsString
import org.joda.time.ReadablePartial; //导入依赖的package包/类
@Override
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) {
this.facesContext = facesContext;
Class<?> type = ValueExpressionHelper.getValueType(facesContext, uiComponent,
Lists.<Class<?>> newArrayList(DateTime.class, LocalDate.class, LocalTime.class));
Preconditions.checkArgument(type != null, "DateTimeConverter is not attached to a component bound to either a"
+ " DateTime, LocalDate, or LocalTime.");
if (value instanceof LocalDate) {
LocalDate localDate = (LocalDate) value;
return getAsStringValue(facesContext, uiComponent, localDate.toDateTimeAtStartOfDay(getTimeZone()));
}
if (value instanceof LocalTime) {
LocalTime localTime = (LocalTime) value;
return getAsStringValue(facesContext, uiComponent, localTime.toDateTimeToday(getTimeZone()));
}
if (value instanceof ReadablePartial) {
ReadablePartial readablePartial = (ReadablePartial) value;
return getAsStringValue(facesContext, uiComponent, readablePartial.toDateTime(new DateTime()));
}
this.facesContext = null;
return getAsStringValue(facesContext, uiComponent, value);
}
示例2: between
import org.joda.time.ReadablePartial; //导入依赖的package包/类
/**
* Calculates the number of whole units between the two specified partial datetimes.
* <p>
* The two partials must contain the same fields, for example you can specify
* two <code>LocalDate</code> objects.
*
* @param start the start partial date, validated to not be null
* @param end the end partial date, validated to not be null
* @param zeroInstance the zero instance constant, must not be null
* @return the period
* @throws IllegalArgumentException if the partials are null or invalid
*/
protected static int between(ReadablePartial start, ReadablePartial end, ReadablePeriod zeroInstance) {
if (start == null || end == null) {
throw new IllegalArgumentException("ReadablePartial objects must not be null");
}
if (start.size() != end.size()) {
throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
}
for (int i = 0, isize = start.size(); i < isize; i++) {
if (start.getFieldType(i) != end.getFieldType(i)) {
throw new IllegalArgumentException("ReadablePartial objects must have the same set of fields");
}
}
if (DateTimeUtils.isContiguous(start) == false) {
throw new IllegalArgumentException("ReadablePartial objects must be contiguous");
}
Chronology chrono = DateTimeUtils.getChronology(start.getChronology()).withUTC();
int[] values = chrono.get(zeroInstance, chrono.set(start, 0L), chrono.set(end, 0L));
return values[0];
}
示例3: equals
import org.joda.time.ReadablePartial; //导入依赖的package包/类
/**
* Compares this ReadablePartial with another returning true if the chronology,
* field types and values are equal.
*
* @param partial an object to check against
* @return true if fields and values are equal
*/
public boolean equals(Object partial) {
if (this == partial) {
return true;
}
if (partial instanceof ReadablePartial == false) {
return false;
}
ReadablePartial other = (ReadablePartial) partial;
if (size() != other.size()) {
return false;
}
for (int i = 0, isize = size(); i < isize; i++) {
if (getValue(i) != other.getValue(i) || getFieldType(i) != other.getFieldType(i)) {
return false;
}
}
return FieldUtils.equals(getChronology(), other.getChronology());
}
示例4: compareTo
import org.joda.time.ReadablePartial; //导入依赖的package包/类
/**
* Compares this partial with another returning an integer
* indicating the order.
* <p>
* The fields are compared in order, from largest to smallest.
* The first field that is non-equal is used to determine the result.
* <p>
* The specified object must be a partial instance whose field types
* match those of this partial.
* <p>
* NOTE: Prior to v2.0, the {@code Comparable} interface was only implemented
* in this class and not in the {@code ReadablePartial} interface.
*
* @param other an object to check against
* @return negative if this is less, zero if equal, positive if greater
* @throws ClassCastException if the partial is the wrong class
* or if it has field types that don't match
* @throws NullPointerException if the partial is null
* @since 1.1
*/
public int compareTo(ReadablePartial other) {
if (this == other) {
return 0;
}
if (size() != other.size()) {
throw new ClassCastException("ReadablePartial objects must have matching field types");
}
for (int i = 0, isize = size(); i < isize; i++) {
if (getFieldType(i) != other.getFieldType(i)) {
throw new ClassCastException("ReadablePartial objects must have matching field types");
}
}
// fields are ordered largest first
for (int i = 0, isize = size(); i < isize; i++) {
if (getValue(i) > other.getValue(i)) {
return 1;
}
if (getValue(i) < other.getValue(i)) {
return -1;
}
}
return 0;
}
示例5: parsePointInTime
import org.joda.time.ReadablePartial; //导入依赖的package包/类
public PointInTime parsePointInTime(String text) {
if (getParser() == null) {
throw new UnsupportedOperationException("Parsing not supported");
}
text = truncateTimeZone(text);
Chronology chrono = selectChronology();
PointInTimeParserBucket bucket = new PointInTimeParserBucket(0, chrono, getLocale());
int newPos = getParser().parseInto(bucket, text, 0);
if (newPos >= 0) {
if (newPos >= text.length()) {
ReadablePartial partial = bucket.toPartial();
return new PointInTime(partial);
}
} else {
newPos = ~newPos;
}
throw new IllegalArgumentException(createErrorMessage(text, newPos));
}
示例6: printTo
import org.joda.time.ReadablePartial; //导入依赖的package包/类
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
DateTimePrinter[] elements = iPrinters;
if (elements == null) {
throw new UnsupportedOperationException();
}
if (locale == null) {
// Guard against default locale changing concurrently.
locale = Locale.getDefault();
}
int len = elements.length;
for (int i=0; i<len; i++) {
elements[i].printTo(buf, partial, locale);
}
}
示例7: printTo
import org.joda.time.ReadablePartial; //导入依赖的package包/类
@Override
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
if (hasMilliSecondPrecision) {
buf.append(String.valueOf(getDateTimeMillis(partial)));
} else {
buf.append(String.valueOf(getDateTimeMillis(partial) / 1000));
}
}
示例8: getDateTimeMillis
import org.joda.time.ReadablePartial; //导入依赖的package包/类
private long getDateTimeMillis(ReadablePartial partial) {
int year = partial.get(DateTimeFieldType.year());
int monthOfYear = partial.get(DateTimeFieldType.monthOfYear());
int dayOfMonth = partial.get(DateTimeFieldType.dayOfMonth());
int hourOfDay = partial.get(DateTimeFieldType.hourOfDay());
int minuteOfHour = partial.get(DateTimeFieldType.minuteOfHour());
int secondOfMinute = partial.get(DateTimeFieldType.secondOfMinute());
int millisOfSecond = partial.get(DateTimeFieldType.millisOfSecond());
return partial.getChronology().getDateTimeMillis(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}
示例9: getPrinter
import org.joda.time.ReadablePartial; //导入依赖的package包/类
@Override
public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) {
DateTimeFormatter formatter = getFormatter(annotation, fieldType);
if (ReadablePartial.class.isAssignableFrom(fieldType)) {
return new ReadablePartialPrinter(formatter);
}
else if (ReadableInstant.class.isAssignableFrom(fieldType) || Calendar.class.isAssignableFrom(fieldType)) {
// assumes Calendar->ReadableInstant converter is registered
return new ReadableInstantPrinter(formatter);
}
else {
// assumes Date->Long converter is registered
return new MillisecondInstantPrinter(formatter);
}
}
示例10: getMaximumValue
import org.joda.time.ReadablePartial; //导入依赖的package包/类
@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();
}
示例11: isToday
import org.joda.time.ReadablePartial; //导入依赖的package包/类
/**
* 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;
}
示例12: getRelativeDateTimeString
import org.joda.time.ReadablePartial; //导入依赖的package包/类
/**
* Return string describing the time until/elapsed time since 'time' formatted like
* "[relative time/date], [time]".
*
* See {@link android.text.format.DateUtils#getRelativeDateTimeString} for full docs.
*
* @throws IllegalArgumentException if using a ReadablePartial without a time component
* @see #getRelativeDateTimeString(Context, ReadableInstant, ReadablePeriod, int)
*/
public static CharSequence getRelativeDateTimeString(Context context, ReadablePartial time,
ReadablePeriod transitionResolution, int flags) {
if (!time.isSupported(DateTimeFieldType.hourOfDay())
|| !time.isSupported(DateTimeFieldType.minuteOfHour())) {
throw new IllegalArgumentException("getRelativeDateTimeString() must be passed a ReadablePartial that " +
"supports time, otherwise it makes no sense");
}
return getRelativeDateTimeString(context, time.toDateTime(DateTime.now()), transitionResolution, flags);
}
示例13: getValue
import org.joda.time.ReadablePartial; //导入依赖的package包/类
protected int getValue(ReadablePartial partial) {
try {
int value = partial.get(type);
if (value < 0) {
value = -value;
}
return value;
} catch (RuntimeException e) {
return -1;
}
}
示例14: testToPartialForYearMonthDayHour
import org.joda.time.ReadablePartial; //导入依赖的package包/类
@Test
public void testToPartialForYearMonthDayHour() {
ReadablePartial p = new Partial().with(DateTimeFieldType.year(), 1975).with(DateTimeFieldType.monthOfYear(), 7)
.with(DateTimeFieldType.dayOfMonth(), 23).with(DateTimeFieldType.hourOfDay(), 15);
ReadablePartial t = new PointInTime(1975, 7, 23, 15);
Assert.assertTrue(p.equals(t));
}
示例15: compareTo
import org.joda.time.ReadablePartial; //导入依赖的package包/类
/**
* Compare this field to the same field on another partial instant.
* <p>
* The comparison is based on the value of the same field type, irrespective
* of any difference in chronology. Thus, if this property represents the
* hourOfDay field, then the hourOfDay field of the other partial will be queried
* whether in the same chronology or not.
*
* @param partial the partial to compare to
* @return negative value if this is less, 0 if equal, or positive value if greater
* @throws IllegalArgumentException if the instant is null
* @throws IllegalArgumentException if the field of this property cannot be queried
* on the specified instant
*/
public int compareTo(ReadablePartial partial) {
if (partial == null) {
throw new IllegalArgumentException("The instant must not be null");
}
int thisValue = get();
int otherValue = partial.get(getFieldType());
if (thisValue < otherValue) {
return -1;
} else if (thisValue > otherValue) {
return 1;
} else {
return 0;
}
}