java类org.joda.time.format.DateTimeParserBucket的实例源码

Tasks.java 文件源码 项目:heroic 阅读 51 收藏 0 点赞 0 评论 0
private static long parseTodayInstant(String input, final Chronology chrono, long now) {
    final DateTime n = new DateTime(now, chrono);

    for (final DateTimeParser p : today) {
        final DateTimeParserBucket bucket =
            new DateTimeParserBucket(0, chrono, null, null, 2000);

        bucket.saveField(chrono.year(), n.getYear());
        bucket.saveField(chrono.monthOfYear(), n.getMonthOfYear());
        bucket.saveField(chrono.dayOfYear(), n.getDayOfYear());

        try {
            p.parseInto(bucket, input, 0);
        } catch (IllegalArgumentException e) {
            // pass-through
            continue;
        }

        return bucket.computeMillis();
    }

    throw new IllegalArgumentException(input + " is not a valid instant");
}
Tasks.java 文件源码 项目:heroic 阅读 22 收藏 0 点赞 0 评论 0
private static long parseFullInstant(String input, final Chronology chrono) {
    for (final DateTimeParser p : full) {
        final DateTimeParserBucket bucket =
            new DateTimeParserBucket(0, chrono, null, null, 2000);

        try {
            p.parseInto(bucket, input, 0);
        } catch (IllegalArgumentException e) {
            // pass-through
            continue;
        }

        return bucket.computeMillis();
    }

    throw new IllegalArgumentException(input + " is not a valid instant");
}
Joda.java 文件源码 项目:elasticsearch_my 阅读 22 收藏 0 点赞 0 评论 0
@Override
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
    boolean isPositive = text.startsWith("-") == false;
    boolean isTooLong = text.length() > estimateParsedLength();

    if ((isPositive && isTooLong) ||
        // timestamps have to have UTC timezone
        bucket.getZone() != DateTimeZone.UTC) {
        return -1;
    }

    int factor = hasMilliSecondPrecision ? 1 : 1000;
    try {
        long millis = Long.valueOf(text) * factor;
        DateTime dt = new DateTime(millis, DateTimeZone.UTC);
        bucket.saveField(DateTimeFieldType.year(), dt.getYear());
        bucket.saveField(DateTimeFieldType.monthOfYear(), dt.getMonthOfYear());
        bucket.saveField(DateTimeFieldType.dayOfMonth(), dt.getDayOfMonth());
        bucket.saveField(DateTimeFieldType.hourOfDay(), dt.getHourOfDay());
        bucket.saveField(DateTimeFieldType.minuteOfHour(), dt.getMinuteOfHour());
        bucket.saveField(DateTimeFieldType.secondOfMinute(), dt.getSecondOfMinute());
        bucket.saveField(DateTimeFieldType.millisOfSecond(), dt.getMillisOfSecond());
        bucket.setZone(DateTimeZone.UTC);
    } catch (Exception e) {
        return -1;
    }
    return text.length();
}
TwoDigitNumber.java 文件源码 项目:eHMP 阅读 22 收藏 0 点赞 0 评论 0
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
    int value = ParseUtils.parseTwoDigits(text, position);
    if (value > 0 || (value == 0 && (type == DateTimeFieldType.hourOfDay() || type == DateTimeFieldType
            .minuteOfHour() || type == DateTimeFieldType.secondOfMinute() || type == DateTimeFieldType
            .millisOfSecond())))
        bucket.saveField(type, value);
    return position + 2 > text.length() ? position + 1 : position + 2;
}
TwoDigitNumber.java 文件源码 项目:eHMP 阅读 20 收藏 0 点赞 0 评论 0
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
    int value = parseTwoDigits(text, position);
    if (value > 0 || (value == 0 && (type == DateTimeFieldType.hourOfDay() || type == DateTimeFieldType
            .minuteOfHour() || type == DateTimeFieldType.secondOfMinute() || type == DateTimeFieldType
            .millisOfSecond())))
        bucket.saveField(type, value);
    return position + 2 > text.length() ? position + 1 : position + 2;
}
ParseUtils.java 文件源码 项目:eHMP 阅读 22 收藏 0 点赞 0 评论 0
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
    return position + 1;
}


问题


面经


文章

微信
公众号

扫码关注公众号