Time.java revision adc14d0be45af50dbde99eb71c21de3bc1ddb1c6
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2016 ForgeRock AS.
*/
/**
* The source of all time-based information in OpenAM.
* <p>
* Use the methods on this class where you would have otherwise used {@code System.currentTimeMillis()},
* {@code new Date()}, {@code Calendar.getInstance()} or the various constructors and {@code now} methods
* in {@code org.joda.time.DateTime}.
* <p>
*
*/
@SuppressWarnings({"PMD.AvoidCalenderGetInstance"})
/** Singleton Instance. */
private final TimeService timeService;
Time() {
+ " Defaulting to TimeService.SYSTEM");
} else {
}
} else {
}
}
public long getMillis() {
return timeService.now();
}
/**
* Get the current time in milliseconds from the {@code TimeService} - this replaces
* {@code System.currentTimeMillis()}.
* @return The current time since the epoch in milliseconds.
* @see System#currentTimeMillis()
*/
public static long currentTimeMillis() {
}
/**
* Get a {@code Date} with current time in milliseconds from the {@code TimeService} - this replaces
* {@code new Date()}.
* @return A date with the current time since the epoch in milliseconds.
* @see Date#Date()
*/
return new Date(currentTimeMillis());
}
/**
* Get a {@code Date} with the specified time in milliseconds - this replaces {@code new Date(long)}.
* @param time The time in milliseconds.
* @return A date with the time since the epoch in milliseconds.
* @see Date#Date()
*/
}
/**
* Get a {@code Calendar} with current time in milliseconds from the {@code TimeService} - this replaces
* {@code Calendar.getInstance()}.
* @return A date with the current time since the epoch in milliseconds.
* @see Calendar#getInstance()
*/
public static Calendar getCalendarInstance() {
return setCalendarTime(calendar);
}
/**
* Get a {@code Calendar} with current time in milliseconds from the {@code TimeService} - this replaces
* {@code Calendar.getInstance(Locale)}.
* @param locale The locale to use for the calendar instance.
* @return A date with the current time since the epoch in milliseconds.
* @see Calendar#getInstance(Locale)
*/
return setCalendarTime(calendar);
}
/**
* Get a {@code Calendar} with current time in milliseconds from the {@code TimeService} - this replaces
* {@code Calendar.getInstance(TimeZone)}.
* @param tz The timezone to use for the calendar instance.
* @return A date with the current time since the epoch in milliseconds.
* @see Calendar#getInstance(TimeZone)
*/
return setCalendarTime(calendar);
}
/**
* Get a {@code Calendar} with current time in milliseconds from the {@code TimeService} - this replaces
* {@code Calendar.getInstance(TimeZone, Locale)}.
* @param tz The timezone to use for the calendar instance.
* @param locale The locale to use for the calendar instance.
* @return A date with the current time since the epoch in milliseconds.
* @see Calendar#getInstance(TimeZone, Locale)
*/
return setCalendarTime(calendar);
}
return calendar;
}
}