[java-core] Timestamp.of(java.sql.Timestamp) is one second late for a time less than a second before the epoch
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 sdk-platform-java/java-core/google-cloud-core/src/main/java/com/google/cloud/Timestamp.java 开始,查看 issue 中链接的 Timestamp.of(java.sql.Timestamp) 方法。将它的秒数计算与 Timestamp.of(Date) 以及 epoch 附近的复现值进行比较。负的亚秒案例转换正确且与 Timestamp.of(Date) 一致时,即表示完成;issue 没有指定测试文件。
由索引模型根据 Issue 内容生成。
描述
Issue Details
Timestamp.of(java.sql.Timestamp) returns a time one second late for a java.sql.Timestamp between one second before the epoch and the epoch:
The method takes the whole seconds as getTime() / 1000 and borrows a second only when that quotient is negative. For getTime() in (-1000, 0) the quotient is 0, so no second is borrowed, while getNanos() holds the positive fraction of the second before the epoch. new java.sql.Timestamp(-500) (1969-12-31T23:59:59.500Z) becomes 1970-01-01T00:00:00.500Z. The borrow was added for googleapis/java-core#159, whose example (-1001) has a nonzero quotient, so this range was left out. Math.floorDiv(getTime(), 1000) gives the right seconds for every value, as Timestamp.of(Date) already does through ofTimeMicroseconds.
Found while building an Apache Flink connector on google-cloud-firestore (flink-gcp/flink-connector-gcp).
Environment
- OS Type and Version: macOS 26 (arm64)
- Java Version and JDK Vendor: Eclipse Temurin 17.0.20
Dependencies
- Libraries-Bom: 26.90.0
- google-cloud-core 2.77.0
The affected code is identical in 2.77.0 and on main.
Reproducer
package repro;
import com.google.cloud.Timestamp;
public class SqlTimestampProbe {
public static void main(String[] args) {
for (long millis : new long[] {-1500, -500, -1, 0, 500}) {
java.sql.Timestamp sql = new java.sql.Timestamp(millis);
System.out.println(millis + " ms (" + sql.toInstant() + "): Timestamp.of(sql) = " + Timestamp.of(sql)
+ ", Timestamp.of(Date) = " + Timestamp.of(new java.util.Date(millis)));
}
}
}
Logs and Stack Trace
-1500 ms (1969-12-31T23:59:58.500Z): Timestamp.of(sql) = 1969-12-31T23:59:58.500000000Z, Timestamp.of(Date) = 1969-12-31T23:59:58.500000000Z
-500 ms (1969-12-31T23:59:59.500Z): Timestamp.of(sql) = 1970-01-01T00:00:00.500000000Z, Timestamp.of(Date) = 1969-12-31T23:59:59.500000000Z
-1 ms (1969-12-31T23:59:59.999Z): Timestamp.of(sql) = 1970-01-01T00:00:00.999000000Z, Timestamp.of(Date) = 1969-12-31T23:59:59.999000000Z
0 ms (1970-01-01T00:00:00Z): Timestamp.of(sql) = 1970-01-01T00:00:00Z, Timestamp.of(Date) = 1970-01-01T00:00:00Z
500 ms (1970-01-01T00:00:00.500Z): Timestamp.of(sql) = 1970-01-01T00:00:00.500000000Z, Timestamp.of(Date) = 1970-01-01T00:00:00.500000000Z
Behavior
Deterministic: any java.sql.Timestamp with -1000 < getTime() < 0.
- 主要语言
- Java
- 星标
- 2.1k
- 派生
- 1.2k
- 平均合并
- 2 天 21 小时
- 30 天内合并 PR
- 139
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
googleapis/google-cloud-java 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
googleapis/google-cloud-java#14635 ·
维护者通常 1 天内回复
-
[java-firestore] UserDataConverter throws IndexOutOfBoundsException on an empty __binary__ value未关闭
难度 2/5 1-3 小时 新手友好度 74/100
googleapis/google-cloud-java#14634 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
googleapis/google-cloud-java#14579 ·
维护者通常 1 天内回复
-
[java-firestore] CustomClassMapper.convertBigDecimal calls .abs() on Double, unintentionally flipping negative values to positive可能已有人在做 @wu-hui 于 14 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
googleapis/google-cloud-java#14533 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Github CI failing when trying to install xmllint可能已有人在做 @blakeli0 于 50 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
googleapis/google-cloud-java#14132 · 1 条评论 ·
维护者通常 1 天内回复
查看 googleapis/google-cloud-java 的全部 Issue
相似的 Issue
-
`timer` rule rejects dates the engine accepts可能已有人在做 @MFA-G 今天认领。 未关闭bug ready
难度 2/5 1-3 小时 新手友好度 72/100
camunda/bpmnlint-plugin-camunda-compat#281 · 3 条评论 ·
维护者通常 1 天内回复
-
status: waiting-for-triage
难度 2/5 1-3 小时 新手友好度 72/100
-
bug
难度 2/5 1-3 小时 新手友好度 62/100
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
AOT compilation fails for derived delete queries returning Set可能已有人在做 @ryujungkyun 今天认领。 未关闭status: waiting-for-triage
难度 2/5 1-3 小时 新手友好度 72/100
spring-projects/spring-data-jpa#4387 ·
维护者通常 3 天内回复