Java Code Examples for java.time.format.DateTimeFormatterBuilder#appendPattern()
The following examples show how to use
java.time.format.DateTimeFormatterBuilder#appendPattern() .
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: TestReducedParser.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@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)); } }
Example 2
Source File: TestReducedParser.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@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)); } }
Example 3
Source File: TestReducedParser.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@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)); } }
Example 4
Source File: TestReducedParser.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@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)); } }
Example 5
Source File: TestReducedParser.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@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)); } }
Example 6
Source File: TestReducedParser.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@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)); } }
Example 7
Source File: TestReducedParser.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@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)); } }
Example 8
Source File: TestReducedPrinter.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@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); }
Example 9
Source File: Session.java From org.openntf.domino with Apache License 2.0 | 5 votes |
@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_; }
Example 10
Source File: TestReducedPrinter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@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); }
Example 11
Source File: SlackDateTimeFormatter.java From roboslack with Apache License 2.0 | 5 votes |
/** * 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(); }
Example 12
Source File: TestReducedPrinter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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); }
Example 13
Source File: TestReducedPrinter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@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); }
Example 14
Source File: TestReducedPrinter.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@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); }
Example 15
Source File: TestReducedPrinter.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@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); }
Example 16
Source File: TestReducedPrinter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@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); }
Example 17
Source File: TestReducedPrinter.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@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); }
Example 18
Source File: JSR310DateTimeDeserializerBase.java From jackson-modules-java8 with Apache License 2.0 | 4 votes |
@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; }
Example 19
Source File: FormatUtil.java From jackcess with Apache License 2.0 | 4 votes |
@Override public void build(DateTimeFormatterBuilder dtfb, Args args, boolean hasAmPm, Value.Type dtType) { dtfb.appendPattern(_pat); }
Example 20
Source File: FormatUtil.java From jackcess with Apache License 2.0 | 4 votes |
@Override public void build(DateTimeFormatterBuilder dtfb, Args args, boolean hasAmPm, Value.Type dtType) { dtfb.appendPattern(args._ctx.getTemporalConfig().getDateTimeFormat(_type)); }