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

org.mockserver.time.TimeService Maven / Gradle / Ivy

There is a newer version: 5.15.0
Show newest version
package org.mockserver.time;

import java.time.Clock;
import java.time.Instant;
import java.time.OffsetDateTime;

public class TimeService {

    public static final Instant FIXED_INSTANT_FOR_TESTS = Instant.now();
    public static boolean fixedTime = false;

    public static Instant now() {
        if (!fixedTime) {
            return Instant.now();
        } else {
            return FIXED_INSTANT_FOR_TESTS;
        }
    }

    public static OffsetDateTime offsetNow() {
        Instant now = TimeService.now();
        return OffsetDateTime.ofInstant(now, Clock.systemDefaultZone().getZone().getRules().getOffset(now));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy