Examples of TemporalAccessor


Examples of org.threeten.bp.temporal.TemporalAccessor

        int pos = 0;
        if (str.startsWith("-")) {
            pos = 1;
        }
        ParsePosition pp = new ParsePosition(pos);
        TemporalAccessor parsed = TIME_PARSER.parseUnresolved(str, pp);
        if (parsed == null || pp.getErrorIndex() >= 0) {
            throw new IllegalArgumentException(str);
        }
        long hour = parsed.getLong(HOUR_OF_DAY);
        Long min = (parsed.isSupported(MINUTE_OF_HOUR) ? parsed.getLong(MINUTE_OF_HOUR) : null);
        Long sec = (parsed.isSupported(SECOND_OF_MINUTE) ? parsed.getLong(SECOND_OF_MINUTE) : null);
        int secs = (int) (hour * 60 * 60 + (min != null ? min : 0) * 60 + (sec != null ? sec : 0));
        if (pos == 1) {
            secs = -secs;
        }
        return secs;
View Full Code Here

Examples of org.threeten.bp.temporal.TemporalAccessor

    //-----------------------------------------------------------------------
    @Test
    public void test_parseBest_firstOption() throws Exception {
        DateTimeFormatter test = DateTimeFormatter.ofPattern("uuuu-MM[-dd]");
        TemporalAccessor result = test.parseBest("2011-06-30", LocalDate.FROM, YearMonth.FROM);
        assertEquals(result, LocalDate.of(2011, 6, 30));
    }
View Full Code Here

Examples of org.threeten.bp.temporal.TemporalAccessor

    }

    @Test
    public void test_parseBest_secondOption() throws Exception {
        DateTimeFormatter test = DateTimeFormatter.ofPattern("uuuu-MM[-dd]");
        TemporalAccessor result = test.parseBest("2011-06", LocalDate.FROM, YearMonth.FROM);
        assertEquals(result, YearMonth.of(2011, 6));
    }
View Full Code Here

Examples of org.threeten.bp.temporal.TemporalAccessor

    //-----------------------------------------------------------------------
    @Test
    public void test_parseToBuilder_StringParsePosition() throws Exception {
        DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
        ParsePosition pos = new ParsePosition(0);
        TemporalAccessor result = test.parseUnresolved("ONE30XXX", pos);
        assertEquals(pos.getIndex(), 5);
        assertEquals(pos.getErrorIndex(), -1);
        assertEquals(result.getLong(DAY_OF_MONTH), 30L);
    }
View Full Code Here

Examples of org.threeten.bp.temporal.TemporalAccessor

    @Test
    public void test_parseToBuilder_StringParsePosition_parseError() throws Exception {
        DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
        ParsePosition pos = new ParsePosition(0);
        TemporalAccessor result = test.parseUnresolved("ONEXXX", pos);
        assertEquals(pos.getIndex(), 0)// TODO: is this right?
        assertEquals(pos.getErrorIndex(), 3);
        assertEquals(result, null);
    }
View Full Code Here

Examples of org.threeten.bp.temporal.TemporalAccessor

    @Test
    public void test_toFormat_parseObject_StringParsePosition_parseError() throws Exception {
        DateTimeFormatter test = fmt.withLocale(Locale.ENGLISH).withDecimalStyle(DecimalStyle.STANDARD);
        Format format = test.toFormat();
        ParsePosition pos = new ParsePosition(0);
        TemporalAccessor result = (TemporalAccessor) format.parseObject("ONEXXX", pos);
        assertEquals(pos.getIndex(), 0)// TODO: is this right?
        assertEquals(pos.getErrorIndex(), 3);
        assertEquals(result, null);
    }
View Full Code Here

Examples of org.threeten.bp.temporal.TemporalAccessor

    @Test(dataProvider="sample_isoLocalDate")
    public void test_print_isoLocalDate(
            Integer year, Integer month, Integer day, String offsetId, String zoneId,
            String expected, Class<?> expectedEx) {
        TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
        if (expectedEx == null) {
            assertEquals(DateTimeFormatter.ISO_LOCAL_DATE.format(test), expected);
        } else {
            try {
                DateTimeFormatter.ISO_LOCAL_DATE.format(test);
View Full Code Here

Examples of org.threeten.bp.temporal.TemporalAccessor

    @Test(dataProvider="sample_isoOffsetDate")
    public void test_print_isoOffsetDate(
            Integer year, Integer month, Integer day, String offsetId, String zoneId,
            String expected, Class<?> expectedEx) {
        TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
        if (expectedEx == null) {
            assertEquals(DateTimeFormatter.ISO_OFFSET_DATE.format(test), expected);
        } else {
            try {
                DateTimeFormatter.ISO_OFFSET_DATE.format(test);
View Full Code Here

Examples of org.threeten.bp.temporal.TemporalAccessor

    @Test(dataProvider="sample_isoDate")
    public void test_print_isoDate(
            Integer year, Integer month, Integer day, String offsetId, String zoneId,
            String expected, Class<?> expectedEx) {
        TemporalAccessor test = buildAccessor(year, month, day, null, null, null, null, offsetId, zoneId);
        if (expectedEx == null) {
            assertEquals(DateTimeFormatter.ISO_DATE.format(test), expected);
        } else {
            try {
                DateTimeFormatter.ISO_DATE.format(test);
View Full Code Here

Examples of org.threeten.bp.temporal.TemporalAccessor

    @Test(dataProvider="sample_isoLocalTime")
    public void test_print_isoLocalTime(
            Integer hour, Integer min, Integer sec, Integer nano, String offsetId, String zoneId,
            String expected, Class<?> expectedEx) {
        TemporalAccessor test = buildAccessor(null, null, null, hour, min, sec, nano, offsetId, zoneId);
        if (expectedEx == null) {
            assertEquals(DateTimeFormatter.ISO_LOCAL_TIME.format(test), expected);
        } else {
            try {
                DateTimeFormatter.ISO_LOCAL_TIME.format(test);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.