Sha256: 210272d0fd9aab9b300d589a1adff149beb05dc0cf07ba03cda947c352d43de1

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 KB

Contents

package org.embulk.parser.avro;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.embulk.spi.time.Timestamp;


@JsonDeserialize(using=TimestampUnitDeserializer.class)
public enum TimestampUnit {
    Second {
        @Override
        public Timestamp toTimestamp(Long value)
        {
            return Timestamp.ofEpochSecond(value);
        }

        @Override
        public Timestamp toTimestamp(Double value)
        {
            long sec = value.longValue();
            double rest = value - sec;
            return Timestamp.ofEpochSecond(0, sec * 1000000000L + (long) (rest * 1000000000L));
        }
    },
    MilliSecond {
        @Override
        public Timestamp toTimestamp(Long value)
        {
            return Timestamp.ofEpochSecond(0, value * 1000000L);
        }

        @Override
        public Timestamp toTimestamp(Double value)
        {
            long sec = value.longValue();
            double rest = value - sec;
            return Timestamp.ofEpochSecond(0, sec * 1000000L + (long) (rest * 1000000L));
        }
    },
    MicroSecond {
        @Override
        public Timestamp toTimestamp(Long value)
        {
            return Timestamp.ofEpochSecond(0, value * 1000L);
        }

        @Override
        public Timestamp toTimestamp(Double value)
        {
            long sec = value.longValue();
            double rest = value - sec;
            return Timestamp.ofEpochSecond(0, sec * 1000L + (long) (rest * 1000L));
        }
    },
    NanoSecond {
        @Override
        public Timestamp toTimestamp(Long value)
        {
            return Timestamp.ofEpochSecond(0, value);
        }

        @Override
        public Timestamp toTimestamp(Double value)
        {
            return Timestamp.ofEpochSecond(0, value.longValue());
        }
    };

    abstract public Timestamp toTimestamp(Long value);
    abstract public Timestamp toTimestamp(Double value);
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
embulk-parser-avro-0.4.0 src/main/java/org/embulk/parser/avro/TimestampUnit.java
embulk-parser-avro-0.3.0 src/main/java/org/embulk/parser/avro/TimestampUnit.java