Sha256: 9aa25ccbb68e55182351bcf977d55fd3532981217c98b277b77f1f1e34a2d019

Contents?: true

Size: 1.96 KB

Versions: 2

Compression:

Stored size: 1.96 KB

Contents

package org.embulk.output.oracle;

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

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

2 entries across 2 versions & 1 rubygems

Version Path
embulk-output-oracle-0.4.1 src/test/java/org/embulk/output/oracle/TimestampFormatTest.java
embulk-output-oracle-0.2.4 src/test/java/org/embulk/output/oracle/TimestampFormatTest.java