fix(s3): truncate LastModified timestamps to second precision (#24)

This commit is contained in:
Hector Ventura authored and GitHub committed 2026-03-24 10:27:26 -05:00
1 parent 38f7c5c2eb
commit ad31e7a7b7
3 files changed
+11 -2

No files matched your search

@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.s3.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
@RegisterForReflection
public class Part {
@@ -18,7 +19,7 @@ public class Part {
this.partNumber = partNumber;
this.eTag = eTag;
this.size = size;
this.lastModified = Instant.now();
this.lastModified = Instant.now().truncatedTo(ChronoUnit.SECONDS);
}
public int getPartNumber() { return partNumber; }
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.Map;
@@ -42,7 +43,7 @@ public class S3Object {
this.data = data;
this.contentType = contentType != null ? contentType : "application/octet-stream";
this.size = data.length;
this.lastModified = Instant.now();
this.lastModified = Instant.now().truncatedTo(ChronoUnit.SECONDS);
this.eTag = computeETag(data);
this.metadata = new HashMap<>();
this.tags = new HashMap<>();
@@ -81,6 +81,13 @@ class S3ServiceTest {
assertEquals(2, buckets.size());
}
@Test
void putObjectLastModifiedHasSecondPrecision() {
s3Service.createBucket("test-bucket");
S3Object obj = s3Service.putObject("test-bucket", "file.txt", "data".getBytes(), null, null);
assertEquals(0, obj.getLastModified().getNano());
}
@Test
void putAndGetObject() {
s3Service.createBucket("test-bucket", "us-east-1");