forked from alibaba/DataX
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor:extract method getDateStr from dataESWriter.Task for issue d…
- Loading branch information
1 parent
911cacc
commit 29d218b
Showing
3 changed files
with
188 additions
and
169 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...r/src/main/java/com/alibaba/datax/plugin/writer/elasticsearchwriter/DataConvertUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.