Package com.asakusafw.runtime.value

Examples of com.asakusafw.runtime.value.DateTimeOption


    static final class FromDateTimeOption extends AbstractWriter {

        @Override
        protected String toString(Object value) {
            DateTimeOption option = (DateTimeOption) value;
            return TemporalUtil.toTimestampString(option.get().getElapsedSeconds());
        }
View Full Code Here


    static class StringDateTimeOptionInspector extends AbstractStringInspector {

        @Override
        protected ValueOption<?> newObject() {
            return new DateTimeOption();
        }
View Full Code Here

    @Test
    public void datetime_by_string() {
        ValueSerde serde = StringValueSerdeFactory.DATETIME;
        StringObjectInspector inspector = (StringObjectInspector) serde.getInspector();

        DateTimeOption option = new DateTimeOption(new DateTime(2014, 7, 1, 12, 5, 59));
        String value = "2014-07-01 12:05:59";

        assertThat(inspector.copyObject(option), is((Object) option));
        assertThat(inspector.copyObject(option), is(not(sameInstance((Object) option))));
        assertThat(inspector.copyObject(null), is(nullValue()));
        assertThat(inspector.getPrimitiveJavaObject(option), is(value));
        assertThat(inspector.getPrimitiveJavaObject(null), is(nullValue()));
        assertThat(inspector.getPrimitiveWritableObject(option), is(new Text(value)));
        assertThat(inspector.getPrimitiveWritableObject(null), is(nullValue()));

        ValueDriver driver = serde.getDriver(inspector);
        DateTimeOption copy = new DateTimeOption();

        driver.set(copy, option);
        assertThat(copy, is(option));
        driver.set(copy, null);
        assertThat(copy.isNull(), is(true));
    }
View Full Code Here

        super(TypeInfoFactory.timestampTypeInfo);
    }

    @Override
    protected ValueOption<?> newObject() {
        return new DateTimeOption();
    }
View Full Code Here

        return new DateTimeOption();
    }

    @Override
    public java.sql.Timestamp getPrimitiveJavaObject(Object o) {
        DateTimeOption object = (DateTimeOption) o;
        if (object == null || object.isNull()) {
            return null;
        }
        DateTime value = object.get();

        // FIXME for optimization
        @SuppressWarnings("deprecation")
        java.sql.Timestamp result = new java.sql.Timestamp(
                value.getYear() - 1900, value.getMonth() - 1, value.getDay(),
View Full Code Here

        dateTimeFormat = "yyyy/MM/dd HH:mm:ss";
        CsvParser parser = create(
                "2011/03/31 23:59:59,"
                + "1971/4/1 1:2:3,"
                + " 1971/4/1 1:2:3 ,");
        DateTimeOption option = new DateTimeOption();

        assertThat(parser.next(), is(true));

        parser.fill(option);
        assertThat(option.get(), is(new DateTime(2011, 3, 31, 23, 59, 59)));

        parser.fill(option);
        assertThat(option.get(), is(new DateTime(1971, 4, 1, 1, 2, 3)));

        parser.fill(option);
        assertThat(option.get(), is(new DateTime(1971, 4, 1, 1, 2, 3)));

        parser.fill(option);
        assertThat(option.isNull(), is(true));

        parser.endRecord();
        assertThat(parser.next(), is(false));
    }
View Full Code Here

        dateTimeFormat = "yyyyMMddHHmmss";
        CsvParser parser = create(
                "20110331235959,"
                + "19710401010203,"
                + " 19710401010203 ,");
        DateTimeOption option = new DateTimeOption();

        assertThat(parser.next(), is(true));

        parser.fill(option);
        assertThat(option.get(), is(new DateTime(2011, 3, 31, 23, 59, 59)));

        parser.fill(option);
        assertThat(option.get(), is(new DateTime(1971, 4, 1, 1, 2, 3)));

        parser.fill(option);
        assertThat(option.get(), is(new DateTime(1971, 4, 1, 1, 2, 3)));

        parser.fill(option);
        assertThat(option.isNull(), is(true));

        parser.endRecord();
        assertThat(parser.next(), is(false));
    }
View Full Code Here

    @Test
    public void invalid_datetime() throws Exception {
        CsvParser parser = create(String.valueOf("?"));
        assertThat(parser.next(), is(true));
        try {
            parser.fill(new DateTimeOption());
            fail();
        } catch (CsvFormatException e) {
            assertThat(e.getStatus().getReason(), is(Reason.INVALID_CELL_FORMAT));
        }
    }
View Full Code Here

        CsvConfiguration conf = createConfiguration();
        RCReader reader = new RCReader("1999-12-31 01:23:45\r\n".getBytes(conf.getCharset()), count);
        try {
            int rows = 0;
            CsvParser parser = new CsvParser(reader, "testing", conf);
            DateTimeOption date = new DateTimeOption();
            while (parser.next()) {
                parser.fill(date);
                parser.endRecord();
                if (rows == 0) {
                    assertThat(date, is(new DateTimeOption(new DateTime(1999, 12, 31, 1, 23, 45))));
                }
                rows++;
            }
            parser.close();
            assertThat(rows, is(count));
View Full Code Here

     * datetimeの値を解析するテスト。
     * @throws Exception 例外が発生した場合
     */
    @Test
    public void fillDateTime() throws Exception {
        DateTimeOption value = new DateTimeOption();
        create("datetime");

        assertThat(parser.next(), is(true));
        parser.fill(value);
        assertThat(value.get(), is(time(2000, 2, 9, 1, 2, 3)));
        parser.fill(value);
        assertThat(value.get(), is(time(2000, 3, 1, 8, 9, 10)));
        parser.fill(value);
        assertThat(value.get(), is(time(100, 3, 30, 11, 12, 0)));
        parser.endRecord();

        assertThat(parser.next(), is(true));
        parser.fill(value);
        assertThat(value.isNull(), is(true));
        parser.fill(value);
        assertThat(value.get(), is(time(1, 1, 1, 0, 0, 0)));
        parser.fill(value);
        assertThat(value.get(), is(time(9999, 12, 31, 23, 59, 59)));
        parser.endRecord();

        assertThat(parser.next(), is(true));
        parser.fill(value);
        assertThat(value.isNull(), is(true));
        parser.fill(value);
        assertThat(value.isNull(), is(true));
        parser.fill(value);
        assertThat(value.isNull(), is(true));
        parser.endRecord();

        assertThat(parser.next(), is(false));
    }
View Full Code Here

TOP

Related Classes of com.asakusafw.runtime.value.DateTimeOption

Copyright © 2018 www.massapicom. 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.