Skip to content

Commit

Permalink
refactor:extract method getDateStr from dataESWriter.Task for issue d…
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Oct 5, 2023
1 parent 911cacc commit 29d218b
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 169 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.alibaba.datax.plugin.writer.elasticsearchwriter;

import com.alibaba.datax.common.element.Column;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

/**
* @author 百岁 ([email protected])
* @date 2023/10/5
*/
public class DataConvertUtils {
public static String getDateStr(ESColumn esColumn, Column column) {
DateTime date = null;
DateTimeZone dtz = DateTimeZone.getDefault();
if (esColumn.getTimezone() != null) {
// 所有时区参考 http://www.joda.org/joda-time/timezones.html
dtz = DateTimeZone.forID(esColumn.getTimezone());
}
if (column.getType() != Column.Type.DATE && esColumn.getFormat() != null) {
DateTimeFormatter formatter = DateTimeFormat.forPattern(esColumn.getFormat());
date = formatter.withZone(dtz).parseDateTime(column.asString());
return date.toString();
} else if (column.getType() == Column.Type.DATE) {
date = new DateTime(column.asLong(), dtz);
return date.toString();
} else {
return column.asString();
}
}
}
Loading

0 comments on commit 29d218b

Please sign in to comment.