All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.hibernate.validator.runtime.clockprovider.RuntimeReinitializedDefaultClockProvider Maven / Gradle / Ivy

Go to download

Validate object properties (field, getter) and method parameters for your beans (REST, CDI, Jakarta Persistence)

There is a newer version: 3.15.0
Show newest version
package io.quarkus.hibernate.validator.runtime.clockprovider;

import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;

import jakarta.validation.ClockProvider;

/**
 * A Quarkus-specific clock provider that can provide a clock based on a runtime system time zone.
 */
public class RuntimeReinitializedDefaultClockProvider implements ClockProvider {

    public static final RuntimeReinitializedDefaultClockProvider INSTANCE = new RuntimeReinitializedDefaultClockProvider();

    private static final RuntimeReinitializedDefaultClock clock = new RuntimeReinitializedDefaultClock();

    private RuntimeReinitializedDefaultClockProvider() {
    }

    @Override
    public Clock getClock() {
        return clock;
    }

    private static class RuntimeReinitializedDefaultClock extends Clock {

        @Override
        public ZoneId getZone() {
            // we delegate getting the zone id value to a helper class that is reinitialized at runtime
            // allowing to pick up an actual runtime timezone.
            return HibernateValidatorClockProviderSystemZoneIdHolder.SYSTEM_ZONE_ID;
        }

        @Override
        public Clock withZone(ZoneId zone) {
            return Clock.system(zone);
        }

        @Override
        public Instant instant() {
            return Instant.now();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy