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

sirius.kernel.commons.TimeProvider Maven / Gradle / Ivy

Go to download

Provides common core classes and the microkernel powering all Sirius applications

There is a newer version: 12.9.1
Show newest version
/*
 * Made with all the love in the world
 * by scireum in Remshalden, Germany
 *
 * Copyright by scireum GmbH
 * http://www.scireum.de - [email protected]
 */

package sirius.kernel.commons;

import sirius.kernel.di.std.Register;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * Wrapper for static time functions which can be injected using a {@link sirius.kernel.di.std.Part} annotation.
 * 

* Using this wrapper instead of the static methods permits to use mocking in tests. */ @Register(classes = TimeProvider.class) public class TimeProvider { /** * Wrapper for {@link LocalDateTime#now()}. * * @return the current time as {@link LocalDateTime}. */ public LocalDateTime localDateTimeNow() { return LocalDateTime.now(); } /** * Wrapper for {@link LocalDate#now()}. * * @return the current time as {@link LocalDate}. */ public LocalDate localDateNow() { return LocalDate.now(); } /** * Wrapper for {@link LocalTime#now()}. * * @return the current time as {@link LocalTime}. */ public LocalTime localTimeNow() { return LocalTime.now(); } /** * Wrapper for {@link Instant#now()}. * * @return current time as {@link Instant}. */ public Instant instantNow() { return Instant.now(); } /** * Wrapper for {@link System#currentTimeMillis()}. * * @return the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC. */ public long currentTimeMillis() { return System.currentTimeMillis(); } /** * Wrapper for {@link System#nanoTime()}. * * @return the current value of the running Java Virtual Machine's high-resolution time source, in nanoseconds. */ public long nanoTime() { return System.nanoTime(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy