HHH-17080 Fix LocalDateTime resolved value precision

This commit is contained in:
Chris Cranford 2023-09-08 22:34:28 -04:00 committed by Christian Beikov
parent bea9d12115
commit 86ade8d4ca
2 changed files with 13 additions and 3 deletions

View File

@ -69,7 +69,7 @@ public class RevisionTimestampValueResolver {
return localDateTime;
}
else {
return localDateTime.atZone( ZoneId.systemDefault() ).toInstant().getEpochSecond();
return localDateTime.atZone( ZoneId.systemDefault() ).toInstant().toEpochMilli();
}
}
return null;

View File

@ -6,6 +6,8 @@
*/
package org.hibernate.orm.test.envers.integration.reventity;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
@ -71,8 +73,16 @@ public class Custom extends BaseEnversJPAFunctionalTestCase {
@Test
public void testTimestamps() {
assert getAuditReader().getRevisionNumberForDate( new Date( timestamp2 ) ).intValue() == 1;
assert getAuditReader().getRevisionNumberForDate( new Date( timestamp3 ) ).intValue() == 2;
final Date date1 = new Date( timestamp2 );
final Date date2 = new Date( timestamp3 );
assert getAuditReader().getRevisionNumberForDate( date1 ).intValue() == 1;
assert getAuditReader().getRevisionNumberForDate( date2 ).intValue() == 2;
final LocalDateTime localDateTime1 = LocalDateTime.ofInstant( date1.toInstant(), ZoneId.systemDefault() );
final LocalDateTime localDateTime2 = LocalDateTime.ofInstant( date2.toInstant(), ZoneId.systemDefault() );
assert getAuditReader().getRevisionNumberForDate( localDateTime1 ).intValue() == 1;
assert getAuditReader().getRevisionNumberForDate( localDateTime2 ).intValue() == 2;
}
@Test