1
0
mirror of https://github.com/google/nomulus synced 2026-05-20 14:51:48 +00:00

Set clock precision to milliseconds for Datetime->Instant migration (#2999)

Our existing precision is milliseconds so we want to stick with that for
Instants. If we want to increase the precision globally after that we can do so
all in one go post-migration, but for now, it would be a bad thing to have mixed
precision going on just depending on whether a class happens to be migrated yet
or not.

This PR also migrates all existing DateTime.nowUtc() calls to use the Clock
interface, so that when they are migrated they will get the benefit of this
precision-setting as well.

BUG= http://b/496985355
This commit is contained in:
Ben McIlwain
2026-04-03 16:38:26 -04:00
committed by GitHub
parent d2881b47dc
commit 49f14b5e1b
69 changed files with 466 additions and 320 deletions

View File

@@ -170,6 +170,12 @@ public abstract class DateTimeUtils {
return (instant == null) ? null : new DateTime(instant.toEpochMilli(), DateTimeZone.UTC);
}
/** Convert a java.time {@link java.time.Instant} to a joda {@link org.joda.time.Instant}. */
@Nullable
public static org.joda.time.Instant toJodaInstant(@Nullable java.time.Instant instant) {
return (instant == null) ? null : org.joda.time.Instant.ofEpochMilli(instant.toEpochMilli());
}
public static Instant plusYears(Instant instant, int years) {
return instant.atZone(ZoneOffset.UTC).plusYears(years).toInstant();
}