Sha256: c23f0cf63a03828cb405dc9b695ab99146c71fc072d1cf7e879c4813ef419dbb
Contents?: true
Size: 1.58 KB
Versions: 6
Compression:
Stored size: 1.58 KB
Contents
package org.embulk.spi.time; import java.util.Locale; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.jruby.embed.ScriptingContainer; import org.jruby.util.RubyDateFormat; import com.fasterxml.jackson.annotation.JacksonInject; import org.embulk.config.Task; import org.embulk.config.Config; import org.embulk.config.ConfigDefault; import org.embulk.config.ConfigException; import org.embulk.spi.util.LineEncoder; public class TimestampFormatter { public interface FormatterTask extends Task { @Config("timezone") @ConfigDefault("\"UTC\"") public DateTimeZone getTimeZone(); @JacksonInject public ScriptingContainer getJRuby(); } private final RubyDateFormat dateFormat; private final DateTimeZone timeZone; public TimestampFormatter(String format, FormatterTask task) { this(task.getJRuby(), format, task.getTimeZone()); } public TimestampFormatter(ScriptingContainer jruby, String format, DateTimeZone timeZone) { this.timeZone = timeZone; this.dateFormat = new RubyDateFormat(format, Locale.ENGLISH, true); } public void format(Timestamp value, LineEncoder encoder) { // TODO optimize by directly appending to internal buffer encoder.addText(format(value)); } public String format(Timestamp value) { // TODO optimize by using reused StringBuilder dateFormat.setDateTime(new DateTime(value.toEpochMilli(), timeZone)); dateFormat.setNSec(value.getNano()); return dateFormat.format(null); } }
Version data entries
6 entries across 6 versions & 1 rubygems