java.time.format.DateTimeFormatterBuilder#appendPattern ( )源码实例Demo

下面列出了java.time.format.DateTimeFormatterBuilder#appendPattern ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: TestReducedParser.java
@Test(dataProvider="ParseAdjacent")
public void test_parseAdjacent(String pattern, String input, boolean strict, int pos, int parseLen, int year, int month, int day) {
    ParsePosition ppos = new ParsePosition(0);
    builder = new DateTimeFormatterBuilder();
    setStrict(strict);
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    TemporalAccessor parsed = dtf.parseUnresolved(input, ppos);
    assertNotNull(parsed, String.format("parse failed: ppos: %s, formatter: %s%n", ppos.toString(), dtf));
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), parseLen, "error case parse position");
    } else {
        assertEquals(ppos.getIndex(), parseLen, "parse position");
        assertParsed(parsed, YEAR_OF_ERA, Long.valueOf(year));
        assertParsed(parsed, MONTH_OF_YEAR, Long.valueOf(month));
        assertParsed(parsed, DAY_OF_MONTH, Long.valueOf(day));
    }
}
 
源代码2 项目: TencentKona-8   文件: TestReducedParser.java
@Test(dataProvider="ParseAdjacent")
public void test_parseAdjacent(String pattern, String input, boolean strict, int pos, int parseLen, int year, int month, int day) {
    ParsePosition ppos = new ParsePosition(0);
    builder = new DateTimeFormatterBuilder();
    setStrict(strict);
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    TemporalAccessor parsed = dtf.parseUnresolved(input, ppos);
    assertNotNull(parsed, String.format("parse failed: ppos: %s, formatter: %s%n", ppos.toString(), dtf));
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), parseLen, "error case parse position");
    } else {
        assertEquals(ppos.getIndex(), parseLen, "parse position");
        assertParsed(parsed, YEAR_OF_ERA, Long.valueOf(year));
        assertParsed(parsed, MONTH_OF_YEAR, Long.valueOf(month));
        assertParsed(parsed, DAY_OF_MONTH, Long.valueOf(day));
    }
}
 
源代码3 项目: openjdk-jdk8u   文件: TestReducedParser.java
@Test(dataProvider="ParseAdjacent")
public void test_parseAdjacent(String pattern, String input, boolean strict, int pos, int parseLen, int year, int month, int day) {
    ParsePosition ppos = new ParsePosition(0);
    builder = new DateTimeFormatterBuilder();
    setStrict(strict);
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    TemporalAccessor parsed = dtf.parseUnresolved(input, ppos);
    assertNotNull(parsed, String.format("parse failed: ppos: %s, formatter: %s%n", ppos.toString(), dtf));
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), parseLen, "error case parse position");
    } else {
        assertEquals(ppos.getIndex(), parseLen, "parse position");
        assertParsed(parsed, YEAR_OF_ERA, Long.valueOf(year));
        assertParsed(parsed, MONTH_OF_YEAR, Long.valueOf(month));
        assertParsed(parsed, DAY_OF_MONTH, Long.valueOf(day));
    }
}
 
源代码4 项目: jdk8u_jdk   文件: TestReducedParser.java
@Test(dataProvider="ParseAdjacent")
public void test_parseAdjacent(String pattern, String input, boolean strict, int pos, int parseLen, int year, int month, int day) {
    ParsePosition ppos = new ParsePosition(0);
    builder = new DateTimeFormatterBuilder();
    setStrict(strict);
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    TemporalAccessor parsed = dtf.parseUnresolved(input, ppos);
    assertNotNull(parsed, String.format("parse failed: ppos: %s, formatter: %s%n", ppos.toString(), dtf));
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), parseLen, "error case parse position");
    } else {
        assertEquals(ppos.getIndex(), parseLen, "parse position");
        assertParsed(parsed, YEAR_OF_ERA, Long.valueOf(year));
        assertParsed(parsed, MONTH_OF_YEAR, Long.valueOf(month));
        assertParsed(parsed, DAY_OF_MONTH, Long.valueOf(day));
    }
}
 
源代码5 项目: openjdk-8-source   文件: TestReducedParser.java
@Test(dataProvider="ParseAdjacent")
public void test_parseAdjacent(String pattern, String input, boolean strict, int pos, int parseLen, int year, int month, int day) {
    ParsePosition ppos = new ParsePosition(0);
    builder = new DateTimeFormatterBuilder();
    setStrict(strict);
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    TemporalAccessor parsed = dtf.parseUnresolved(input, ppos);
    assertNotNull(parsed, String.format("parse failed: ppos: %s, formatter: %s%n", ppos.toString(), dtf));
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), parseLen, "error case parse position");
    } else {
        assertEquals(ppos.getIndex(), parseLen, "parse position");
        assertParsed(parsed, YEAR_OF_ERA, Long.valueOf(year));
        assertParsed(parsed, MONTH_OF_YEAR, Long.valueOf(month));
        assertParsed(parsed, DAY_OF_MONTH, Long.valueOf(day));
    }
}
 
源代码6 项目: jdk8u-jdk   文件: TestReducedParser.java
@Test(dataProvider="ParseAdjacent")
public void test_parseAdjacent(String pattern, String input, boolean strict, int pos, int parseLen, int year, int month, int day) {
    ParsePosition ppos = new ParsePosition(0);
    builder = new DateTimeFormatterBuilder();
    setStrict(strict);
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    TemporalAccessor parsed = dtf.parseUnresolved(input, ppos);
    assertNotNull(parsed, String.format("parse failed: ppos: %s, formatter: %s%n", ppos.toString(), dtf));
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), parseLen, "error case parse position");
    } else {
        assertEquals(ppos.getIndex(), parseLen, "parse position");
        assertParsed(parsed, YEAR_OF_ERA, Long.valueOf(year));
        assertParsed(parsed, MONTH_OF_YEAR, Long.valueOf(month));
        assertParsed(parsed, DAY_OF_MONTH, Long.valueOf(day));
    }
}
 
源代码7 项目: openjdk-8   文件: TestReducedParser.java
@Test(dataProvider="ParseAdjacent")
public void test_parseAdjacent(String pattern, String input, boolean strict, int pos, int parseLen, int year, int month, int day) {
    ParsePosition ppos = new ParsePosition(0);
    builder = new DateTimeFormatterBuilder();
    setStrict(strict);
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    TemporalAccessor parsed = dtf.parseUnresolved(input, ppos);
    assertNotNull(parsed, String.format("parse failed: ppos: %s, formatter: %s%n", ppos.toString(), dtf));
    if (ppos.getErrorIndex() != -1) {
        assertEquals(ppos.getErrorIndex(), parseLen, "error case parse position");
    } else {
        assertEquals(ppos.getIndex(), parseLen, "parse position");
        assertParsed(parsed, YEAR_OF_ERA, Long.valueOf(year));
        assertParsed(parsed, MONTH_OF_YEAR, Long.valueOf(month));
        assertParsed(parsed, DAY_OF_MONTH, Long.valueOf(day));
    }
}
 
源代码8 项目: TencentKona-8   文件: TestReducedPrinter.java
@Test(dataProvider="PrintAdjacent")
public void test_printAdjacent(String pattern, String text, int year, int month, int day) {
    builder = new DateTimeFormatterBuilder();
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    LocalDate ld = LocalDate.of(year, month, day);
    String actual = dtf.format(ld);
    assertEquals(actual, text, "formatter output: " + dtf);
}
 
源代码9 项目: jdk8u-jdk   文件: TestReducedPrinter.java
@Test(dataProvider="PrintAdjacent")
public void test_printAdjacent(String pattern, String text, int year, int month, int day) {
    builder = new DateTimeFormatterBuilder();
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    LocalDate ld = LocalDate.of(year, month, day);
    String actual = dtf.format(ld);
    assertEquals(actual, text, "formatter output: " + dtf);
}
 
源代码10 项目: jdk8u60   文件: TestReducedPrinter.java
@Test(dataProvider="PrintAdjacent")
public void test_printAdjacent(String pattern, String text, int year, int month, int day) {
    builder = new DateTimeFormatterBuilder();
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    LocalDate ld = LocalDate.of(year, month, day);
    String actual = dtf.format(ld);
    assertEquals(actual, text, "formatter output: " + dtf);
}
 
源代码11 项目: openjdk-jdk8u   文件: TestReducedPrinter.java
@Test(dataProvider="PrintAdjacent")
public void test_printAdjacent(String pattern, String text, int year, int month, int day) {
    builder = new DateTimeFormatterBuilder();
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    LocalDate ld = LocalDate.of(year, month, day);
    String actual = dtf.format(ld);
    assertEquals(actual, text, "formatter output: " + dtf);
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: TestReducedPrinter.java
@Test(dataProvider="PrintAdjacent")
public void test_printAdjacent(String pattern, String text, int year, int month, int day) {
    builder = new DateTimeFormatterBuilder();
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    LocalDate ld = LocalDate.of(year, month, day);
    String actual = dtf.format(ld);
    assertEquals(actual, text, "formatter output: " + dtf);
}
 
源代码13 项目: jdk8u_jdk   文件: TestReducedPrinter.java
@Test(dataProvider="PrintAdjacent")
public void test_printAdjacent(String pattern, String text, int year, int month, int day) {
    builder = new DateTimeFormatterBuilder();
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    LocalDate ld = LocalDate.of(year, month, day);
    String actual = dtf.format(ld);
    assertEquals(actual, text, "formatter output: " + dtf);
}
 
源代码14 项目: openjdk-jdk9   文件: TestReducedPrinter.java
@Test(dataProvider="PrintAdjacent")
public void test_printAdjacent(String pattern, String text, int year, int month, int day) {
    builder = new DateTimeFormatterBuilder();
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    LocalDate ld = LocalDate.of(year, month, day);
    String actual = dtf.format(ld);
    assertEquals(actual, text, "formatter output: " + dtf);
}
 
源代码15 项目: roboslack   文件: SlackDateTimeFormatter.java
/**
 * The delegate {@link DateTimeFormatter} for formatting a {@link SlackDateTime} outside of the context of Slack.
 *
 * @return the {@link DateTimeFormatter} to use when formatting a {@link SlackDateTime} outside of Slack
 */
@Value.Derived
protected DateTimeFormatter delegateFormatter() {
    DateTimeFormatterBuilder formatterBuilder = new DateTimeFormatterBuilder();
    for (String patternToken : tokenizePattern(pattern())) {
        Optional<DateTimeFormatToken> formatToken = DateTimeFormatToken.ofSafe(patternToken);
        if (formatToken.isPresent()) {
            formatterBuilder.appendPattern(formatToken.get().pattern());
        } else {
            formatterBuilder.appendLiteral(patternToken);
        }
    }
    return formatterBuilder.toFormatter();
}
 
源代码16 项目: jdk8u-jdk   文件: TestReducedPrinter.java
@Test(dataProvider="PrintAdjacent")
public void test_printAdjacent(String pattern, String text, int year, int month, int day) {
    builder = new DateTimeFormatterBuilder();
    builder.appendPattern(pattern);
    DateTimeFormatter dtf = builder.toFormatter();

    LocalDate ld = LocalDate.of(year, month, day);
    String actual = dtf.format(ld);
    assertEquals(actual, text, "formatter output: " + dtf);
}
 
源代码17 项目: org.openntf.domino   文件: Session.java
@Override
public DateTimeFormatter getGMTDateTimeFormatter() {
	if (null == dateTimeFormatter_) {
		DateTimeFormatterBuilder dfb1 = new DateTimeFormatterBuilder();
		DateTimeFormatterBuilder dfb2 = new DateTimeFormatterBuilder();
		International i = getInternational();
		String sep = i.getDateSep();
		if (i.isDateMDY()) {
			dfb1.appendPattern("MM" + sep + "dd" + sep + "uuuu");
			dfb2.appendPattern("MM" + sep + "dd" + sep).appendValueReduced(ChronoField.YEAR, 2, 2, Year.now().getValue() - 80);
		} else if (i.isDateDMY()) {
			dfb1.appendPattern("dd" + sep + "MM" + sep + "uuuu");
			dfb2.appendPattern("dd" + sep + "MM" + sep).appendValueReduced(ChronoField.YEAR, 2, 2, Year.now().getValue() - 80);
		} else {
			dfb1.appendPattern("uuuu" + sep + "MM" + sep + "dd");
			dfb2.appendValueReduced(ChronoField.YEAR, 2, 2, Year.now().getValue() - 80).appendPattern(sep + "MM" + sep + "dd");
		}
		dfb1.appendPattern(" " + getTimeFormatForDateTimeFormatter());
		dfb2.appendPattern(" " + getTimeFormatForDateTimeFormatter());
		DateTimeFormatterBuilder dfb = new DateTimeFormatterBuilder();
		dfb.appendOptional(dfb1.parseCaseInsensitive().toFormatter(Locale.ENGLISH))
			.appendOptional(dfb2.parseCaseInsensitive().toFormatter(Locale.ENGLISH));
		dateTimeFormatter_ = dfb.parseCaseInsensitive().toFormatter(Locale.ENGLISH).withResolverStyle(ResolverStyle.LENIENT)
			.withZone(ZoneId.ofOffset("GMT", ZoneOffset.UTC));
	}
	return dateTimeFormatter_;
}
 
源代码18 项目: jackcess   文件: FormatUtil.java
@Override
public void build(DateTimeFormatterBuilder dtfb, Args args,
                  boolean hasAmPm, Value.Type dtType) {
  dtfb.appendPattern(args._ctx.getTemporalConfig().getDateTimeFormat(_type));
}
 
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
        BeanProperty property) throws JsonMappingException
{
    JsonFormat.Value format = findFormatOverrides(ctxt, property, handledType());
    JSR310DateTimeDeserializerBase<?> deser = this;
    if (format != null) {
        // 17-Aug-2019, tatu: For 2.10 let's start considering leniency/strictness too
        if (format.hasLenient()) {
            Boolean leniency = format.getLenient();
            if (leniency != null) {
                deser = deser.withLeniency(leniency);
            }
        }
        if (format.hasPattern()) {
            final String pattern = format.getPattern();
            final Locale locale = format.hasLocale() ? format.getLocale() : ctxt.getLocale();
            DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
            if (acceptCaseInsensitiveValues(ctxt, format)) {
                builder.parseCaseInsensitive();
            }
            builder.appendPattern(pattern);
            DateTimeFormatter df;
            if (locale == null) {
                df = builder.toFormatter();
            } else {
                df = builder.toFormatter(locale);
            }

            // [#148]: allow strict parsing
            if (!deser.isLenient()) {
                df = df.withResolverStyle(ResolverStyle.STRICT);
            }

            // [#69]: For instant serializers/deserializers we need to configure the formatter with
            //a time zone picked up from JsonFormat annotation, otherwise serialization might not work
            if (format.hasTimeZone()) {
                df = df.withZone(format.getTimeZone().toZoneId());
            }
            deser = deser.withDateFormat(df);
        }
        // [#58]: For LocalDate deserializers we need to configure the formatter with
        //a shape picked up from JsonFormat annotation, to decide if the value is EpochSeconds
        JsonFormat.Shape shape = format.getShape();
        if (shape != null && shape != _shape) {
            deser = deser.withShape(shape);
        }
        // any use for TimeZone?
    }
    return deser;
}
 
源代码20 项目: jackcess   文件: FormatUtil.java
@Override
public void build(DateTimeFormatterBuilder dtfb, Args args,
                  boolean hasAmPm, Value.Type dtType) {
  dtfb.appendPattern(_pat);
}