时间精度问题
- Dominant language
- Java
- Stars
- 4.1k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
### Search before asking
- [X] I had searched in the [issues](https://github.com/DTStack/chunjun/issues) and found no similar issues.
### What happened
目前项目上使用 时间戳当作增量字段【startLocation】,同步dm数据,当同步2009年9月9号之前的数据的时候,项目报错:
```txt
Unknown time unit:startLocation=xxxxxxxxxx
```
经查验源代码中有如下逻辑,代码位置
`com.dtstack.chunjun.connector.jdbc.util.JdbcUtil#getMillis`
代码如下:
```java
/**
* 将边界位置时间转换成对应饿的毫秒时间
*
* @param startLocation 边界位置(起始/结束)
* @return
*/
public static long getMillis(long startLocation) {
String timeStr = String.valueOf(startLocation);
long millisSecond;
if (timeStr.length() == SECOND_LENGTH) {
millisSecond = startLocation * 1000;
} else if (timeStr.length() == MILLIS_LENGTH) {
millisSecond = startLocation;
} else if (timeStr.length() == MICRO_LENGTH) {
millisSecond = startLocation / 1000;
} else if (timeStr.length() == NANOS_LENGTH) {
millisSecond = startLocation / 1000000;
} else {
throw new IllegalArgumentException("Unknown time unit:startLocation=" + startLocation);
}
return millisSecond;
}
```
经查验,上述代码对于时间单位的判断是基于时间戳长度来判断的
```java
/** 秒级时间戳的长度为10位 */
private static final int SECOND_LENGTH = 10;
/** 毫秒级时间戳的长度为13位 */
private static final int MILLIS_LENGTH = 13;
/** 微秒级时间戳的长度为16位 */
private static final int MICRO_LENGTH = 16;
/** 纳秒级时间戳的长度为19位 */
private static final int NANOS_LENGTH = 19;
```
但是 `2001-09-09 09:46:39` 之前的毫秒级时间戳为 `999999999999`,长度为12位,导致在上述代码判断中,出现无法判断单位的情况!所以报错:
```txt
Unknown time unit:startLocation=999517080000
```
### What you expected to happen
当我使用毫秒且时间为 2001-09-09 09:46:39 之前的数据,希望可用!
### How to reproduce
rdb类型的数据,startLocation数值为`2001-09-09 09:46:39`之前的时间
### Anything else
_No response_
### Version
master
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
Contributor guide
Assessment
This issue has not been assessed yet.