Java Code Examples for org.joda.time.ReadablePartial#isSupported()

The following examples show how to use org.joda.time.ReadablePartial#isSupported() . 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: Time_20_DateTimeFormatterBuilder_s.java    From coming with MIT License 5 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.writePaddedInteger(out, partial.get(iFieldType), iMinPrintedDigits);
        } catch (RuntimeException e) {
            printUnknownString(out, iMinPrintedDigits);
        }
    } else {
        printUnknownString(out, iMinPrintedDigits);
    }
}
 
Example 2
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.appendUnpaddedInteger(buf, partial.get(iFieldType));
        } catch (RuntimeException e) {
            buf.append('\ufffd');
        }
    } else {
        buf.append('\ufffd');
    }
}
 
Example 3
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.appendPaddedInteger(buf, partial.get(iFieldType), iMinPrintedDigits);
        } catch (RuntimeException e) {
            appendUnknownString(buf, iMinPrintedDigits);
        }
    } else {
        appendUnknownString(buf, iMinPrintedDigits);
    }
}
 
Example 4
Source File: DateUtils.java    From joda-time-android with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.writePaddedInteger(out, partial.get(iFieldType), iMinPrintedDigits);
        } catch (RuntimeException e) {
            printUnknownString(out, iMinPrintedDigits);
        }
    } else {
        printUnknownString(out, iMinPrintedDigits);
    }
}
 
Example 6
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 7
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.writeUnpaddedInteger(out, partial.get(iFieldType));
        } catch (RuntimeException e) {
            out.write('\ufffd');
        }
    } else {
        out.write('\ufffd');
    }
}
 
Example 8
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private String print(ReadablePartial partial, Locale locale) {
    if (partial.isSupported(iFieldType)) {
        DateTimeField field = iFieldType.getField(partial.getChronology());
        if (iShort) {
            return field.getAsShortText(partial, locale);
        } else {
            return field.getAsText(partial, locale);
        }
    } else {
        return "\ufffd";
    }
}
 
Example 9
Source File: Time_20_DateTimeFormatterBuilder_s.java    From coming with MIT License 5 votes vote down vote up
private String print(ReadablePartial partial, Locale locale) {
    if (partial.isSupported(iFieldType)) {
        DateTimeField field = iFieldType.getField(partial.getChronology());
        if (iShort) {
            return field.getAsShortText(partial, locale);
        } else {
            return field.getAsText(partial, locale);
        }
    } else {
        return "\ufffd";
    }
}
 
Example 10
Source File: Time_20_DateTimeFormatterBuilder_s.java    From coming with MIT License 5 votes vote down vote up
private int getTwoDigitYear(ReadablePartial partial) {
    if (partial.isSupported(iType)) {
        try {
            int year = partial.get(iType);
            if (year < 0) {
                year = -year;
            }
            return year % 100;
        } catch (RuntimeException e) {}
    } 
    return -1;
}
 
Example 11
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 12
Source File: Time_20_DateTimeFormatterBuilder_s.java    From coming with MIT License 5 votes vote down vote up
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.appendPaddedInteger(buf, partial.get(iFieldType), iMinPrintedDigits);
        } catch (RuntimeException e) {
            appendUnknownString(buf, iMinPrintedDigits);
        }
    } else {
        appendUnknownString(buf, iMinPrintedDigits);
    }
}
 
Example 13
Source File: Time_20_DateTimeFormatterBuilder_s.java    From coming with MIT License 5 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.writeUnpaddedInteger(out, partial.get(iFieldType));
        } catch (RuntimeException e) {
            out.write('\ufffd');
        }
    } else {
        out.write('\ufffd');
    }
}
 
Example 14
Source File: Time_20_DateTimeFormatterBuilder_s.java    From coming with MIT License 5 votes vote down vote up
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.appendUnpaddedInteger(buf, partial.get(iFieldType));
        } catch (RuntimeException e) {
            buf.append('\ufffd');
        }
    } else {
        buf.append('\ufffd');
    }
}
 
Example 15
Source File: DateTimeFormatterBuilder.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.writePaddedInteger(out, partial.get(iFieldType), iMinPrintedDigits);
        } catch (RuntimeException e) {
            printUnknownString(out, iMinPrintedDigits);
        }
    } else {
        printUnknownString(out, iMinPrintedDigits);
    }
}
 
Example 16
Source File: Time_20_DateTimeFormatterBuilder_t.java    From coming with MIT License 5 votes vote down vote up
private int getTwoDigitYear(ReadablePartial partial) {
    if (partial.isSupported(iType)) {
        try {
            int year = partial.get(iType);
            if (year < 0) {
                year = -year;
            }
            return year % 100;
        } catch (RuntimeException e) {}
    } 
    return -1;
}
 
Example 17
Source File: Time_20_DateTimeFormatterBuilder_t.java    From coming with MIT License 5 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.writePaddedInteger(out, partial.get(iFieldType), iMinPrintedDigits);
        } catch (RuntimeException e) {
            printUnknownString(out, iMinPrintedDigits);
        }
    } else {
        printUnknownString(out, iMinPrintedDigits);
    }
}
 
Example 18
Source File: Time_20_DateTimeFormatterBuilder_t.java    From coming with MIT License 5 votes vote down vote up
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.appendPaddedInteger(buf, partial.get(iFieldType), iMinPrintedDigits);
        } catch (RuntimeException e) {
            appendUnknownString(buf, iMinPrintedDigits);
        }
    } else {
        appendUnknownString(buf, iMinPrintedDigits);
    }
}
 
Example 19
Source File: Time_20_DateTimeFormatterBuilder_t.java    From coming with MIT License 5 votes vote down vote up
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.writeUnpaddedInteger(out, partial.get(iFieldType));
        } catch (RuntimeException e) {
            out.write('\ufffd');
        }
    } else {
        out.write('\ufffd');
    }
}
 
Example 20
Source File: Time_20_DateTimeFormatterBuilder_t.java    From coming with MIT License 5 votes vote down vote up
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
    if (partial.isSupported(iFieldType)) {
        try {
            FormatUtils.appendUnpaddedInteger(buf, partial.get(iFieldType));
        } catch (RuntimeException e) {
            buf.append('\ufffd');
        }
    } else {
        buf.append('\ufffd');
    }
}