Sha256: 01eb5de7b079e603a862e44738cae20d367869131423ec248fbd0a5b33bfab6e

Contents?: true

Size: 1.94 KB

Versions: 27

Compression:

Stored size: 1.94 KB

Contents

package org.embulk.output;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.embulk.output.jdbc.TimestampFormat;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class TimestampFormatTest {

    @Test
    public void test() throws ParseException
    {
        Date date = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").parse("2015/03/04 17:08:09");
        Timestamp t = new Timestamp(date.getTime());

        {
            TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 9);
            assertEquals("2015-03-04 17:08:09.000000000", format.format(t));
        }
        {
            TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 0);
            assertEquals("2015-03-04 17:08:09", format.format(t));
        }
        {
            TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 1);
            assertEquals("2015-03-04 17:08:09.0", format.format(t));
        }

        t.setNanos(1234567);
        {
            TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 9);
            assertEquals("2015-03-04 17:08:09.001234567", format.format(t));
        }
        {
            TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 2);
            assertEquals("2015-03-04 17:08:09.00", format.format(t));
        }
        {
            TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 3);
            assertEquals("2015-03-04 17:08:09.001", format.format(t));
        }

        t.setNanos(123456789);
        {
            TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 9);
            assertEquals("2015-03-04 17:08:09.123456789", format.format(t));
        }
        {
            TimestampFormat format = new TimestampFormat("yyyy-MM-dd HH:mm:ss", 1);
            assertEquals("2015-03-04 17:08:09.1", format.format(t));
        }
    }

}

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
embulk-output-jdbc-0.6.5 src/test/java/org/embulk/output/TimestampFormatTest.java
embulk-output-jdbc-0.6.4 src/test/java/org/embulk/output/TimestampFormatTest.java
embulk-output-jdbc-0.6.3 src/test/java/org/embulk/output/TimestampFormatTest.java
embulk-output-jdbc-0.6.2 src/test/java/org/embulk/output/TimestampFormatTest.java
embulk-output-jdbc-0.6.1 src/test/java/org/embulk/output/TimestampFormatTest.java
embulk-output-jdbc-0.6.0 src/test/java/org/embulk/output/TimestampFormatTest.java
embulk-output-jdbc-0.5.1 src/test/java/org/embulk/output/TimestampFormatTest.java