< prev index next >

test/java/time/tck/java/time/format/TCKDateTimeFormatterBuilder.java

Print this page




 776     @Test(dataProvider="modJulianFieldPattern")
 777     public void test_modJulianFieldPattern(String pattern, String input) throws Exception {
 778         DateTimeFormatter.ofPattern(pattern).parse(input);
 779     }
 780 
 781     @DataProvider(name="modJulianFieldValues")
 782     Object[][] data_modJuilanFieldValues() {
 783         return new Object[][] {
 784             {1970, 1, 1, "40587"},
 785             {1858, 11, 17, "0"},
 786             {1858, 11, 16, "-1"},
 787         };
 788     }
 789 
 790     @Test(dataProvider="modJulianFieldValues")
 791     public void test_modJulianFieldValues(int y, int m, int d, String expected) throws Exception {
 792         DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern("g").toFormatter();
 793          assertEquals(LocalDate.of(y, m, d).format(df), expected);
 794     }
 795 

















 796 



















 797     //-----------------------------------------------------------------------
 798     @Test
 799     public void test_adjacent_strict_firstFixedWidth() throws Exception {
 800         // succeeds because both number elements are fixed width
 801         DateTimeFormatter f = builder.appendValue(HOUR_OF_DAY, 2).appendValue(MINUTE_OF_HOUR, 2).appendLiteral('9').toFormatter(Locale.UK);
 802         ParsePosition pp = new ParsePosition(0);
 803         TemporalAccessor parsed = f.parseUnresolved("12309", pp);
 804         assertEquals(pp.getErrorIndex(), -1);
 805         assertEquals(pp.getIndex(), 5);
 806         assertEquals(parsed.getLong(HOUR_OF_DAY), 12L);
 807         assertEquals(parsed.getLong(MINUTE_OF_HOUR), 30L);
 808     }
 809 
 810     @Test
 811     public void test_adjacent_strict_firstVariableWidth_success() throws Exception {
 812         // succeeds greedily parsing variable width, then fixed width, to non-numeric Z
 813         DateTimeFormatter f = builder.appendValue(HOUR_OF_DAY).appendValue(MINUTE_OF_HOUR, 2).appendLiteral('Z').toFormatter(Locale.UK);
 814         ParsePosition pp = new ParsePosition(0);
 815         TemporalAccessor parsed = f.parseUnresolved("12309Z", pp);
 816         assertEquals(pp.getErrorIndex(), -1);




 776     @Test(dataProvider="modJulianFieldPattern")
 777     public void test_modJulianFieldPattern(String pattern, String input) throws Exception {
 778         DateTimeFormatter.ofPattern(pattern).parse(input);
 779     }
 780 
 781     @DataProvider(name="modJulianFieldValues")
 782     Object[][] data_modJuilanFieldValues() {
 783         return new Object[][] {
 784             {1970, 1, 1, "40587"},
 785             {1858, 11, 17, "0"},
 786             {1858, 11, 16, "-1"},
 787         };
 788     }
 789 
 790     @Test(dataProvider="modJulianFieldValues")
 791     public void test_modJulianFieldValues(int y, int m, int d, String expected) throws Exception {
 792         DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern("g").toFormatter();
 793          assertEquals(LocalDate.of(y, m, d).format(df), expected);
 794     }
 795 
 796     //-----------------------------------------------------------------------
 797     @DataProvider(name="dayOfYearFieldPattern")
 798     Object[][] data_dayOfYearFieldPattern() {
 799         return new Object[][] {
 800                 {"D", "1"},
 801                 {"D", "123"},
 802                 {"DD", "12"},
 803                 {"DD", "123"},
 804                 {"DDD", "123"},
 805                 {"DDD", "12345"},
 806         };
 807     }
 808 
 809     @Test(dataProvider="dayOfYearFieldPattern")
 810     public void test_dayOfYearFieldPattern(String pattern, String input) throws Exception {
 811         DateTimeFormatter.ofPattern(pattern).parse(input);
 812     }
 813 
 814     @DataProvider(name="dayOfYearFieldValues")
 815     Object[][] data_dayOfYearFieldValues() {
 816         return new Object[][] {
 817                 {2016, 1, 1, "D", "1"},
 818                 {2016, 1, 31, "D", "31"},
 819                 {2016, 1, 1, "DD", "01"},
 820                 {2016, 1, 31, "DD", "31"},
 821                 {2016, 4, 9, "DD", "100"},
 822                 {2016, 1, 1, "DDD", "001"},
 823                 {2016, 1, 31, "DDD", "031"},
 824                 {2016, 4, 9, "DDD", "100"},
 825         };
 826     }
 827 
 828     @Test(dataProvider="dayOfYearFieldValues")
 829     public void test_dayOfYearFieldValues(int y, int m, int d, String pattern, String expected) throws Exception {
 830         DateTimeFormatter df = new DateTimeFormatterBuilder().appendPattern(pattern).toFormatter();
 831         assertEquals(LocalDate.of(y, m, d).format(df), expected);
 832     }
 833     //-----------------------------------------------------------------------
 834     @Test
 835     public void test_adjacent_strict_firstFixedWidth() throws Exception {
 836         // succeeds because both number elements are fixed width
 837         DateTimeFormatter f = builder.appendValue(HOUR_OF_DAY, 2).appendValue(MINUTE_OF_HOUR, 2).appendLiteral('9').toFormatter(Locale.UK);
 838         ParsePosition pp = new ParsePosition(0);
 839         TemporalAccessor parsed = f.parseUnresolved("12309", pp);
 840         assertEquals(pp.getErrorIndex(), -1);
 841         assertEquals(pp.getIndex(), 5);
 842         assertEquals(parsed.getLong(HOUR_OF_DAY), 12L);
 843         assertEquals(parsed.getLong(MINUTE_OF_HOUR), 30L);
 844     }
 845 
 846     @Test
 847     public void test_adjacent_strict_firstVariableWidth_success() throws Exception {
 848         // succeeds greedily parsing variable width, then fixed width, to non-numeric Z
 849         DateTimeFormatter f = builder.appendValue(HOUR_OF_DAY).appendValue(MINUTE_OF_HOUR, 2).appendLiteral('Z').toFormatter(Locale.UK);
 850         ParsePosition pp = new ParsePosition(0);
 851         TemporalAccessor parsed = f.parseUnresolved("12309Z", pp);
 852         assertEquals(pp.getErrorIndex(), -1);


< prev index next >