mirror of
https://github.com/google/nomulus
synced 2026-05-16 12:51:47 +00:00
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
47 lines
1.6 KiB
Java
47 lines
1.6 KiB
Java
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package google.registry.util;
|
|
|
|
import java.io.Serializable;
|
|
import java.time.Instant;
|
|
import java.time.ZoneOffset;
|
|
import java.time.ZonedDateTime;
|
|
import javax.annotation.concurrent.ThreadSafe;
|
|
import org.joda.time.DateTime;
|
|
|
|
/**
|
|
* A clock that tells the current time in milliseconds or nanoseconds.
|
|
*
|
|
* <p>Clocks are technically serializable because they are either a stateless wrapper around the
|
|
* system clock, or for testing, are just a wrapper around a DateTime. This means that if you
|
|
* serialize a clock and deserialize it elsewhere, you won't necessarily get the same time or time
|
|
* zone -- what you will get is a functioning clock.
|
|
*/
|
|
@ThreadSafe
|
|
public interface Clock extends Serializable {
|
|
|
|
/** Returns current time in UTC timezone. */
|
|
@Deprecated
|
|
DateTime nowUtc();
|
|
|
|
/** Returns current Instant (which is always in UTC). */
|
|
Instant now();
|
|
|
|
/** Returns the current time as a {@link ZonedDateTime} in UTC. */
|
|
default ZonedDateTime nowDate() {
|
|
return ZonedDateTime.ofInstant(now(), ZoneOffset.UTC);
|
|
}
|
|
}
|