Class FixedDateFormat
java.lang.Object
org.apache.logging.log4j.core.util.datetime.FixedDateFormat
Custom time formatter that trades flexibility for performance. This formatter only supports the date patterns defined
in
FixedDateFormat.FixedFormat. For any other date patterns use FastDateFormat.
Related benchmarks: /log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/TimeFormatBenchmark.java and /log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ThreadsafeDateFormatBenchmark.java
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration over the supported date/time format patterns.static enumFixed time zone formats. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate char[]private intprivate final int[]private final FastDateFormatprivate final FixedDateFormat.FixedFormatprivate final FixedDateFormat.FixedTimeZoneFormatprivate final intprivate longprivate longprivate final charprivate final intprivate static final charprivate final int(package private) static int[]private final charprivate final intprivate final TimeZone -
Constructor Summary
ConstructorsConstructorDescriptionFixedDateFormat(FixedDateFormat.FixedFormat fixedFormat, TimeZone tz) Constructs a FixedDateFormat for the specified fixed format.FixedDateFormat(FixedDateFormat.FixedFormat fixedFormat, TimeZone tz, int secondFractionDigits) Constructs a FixedDateFormat for the specified fixed format. -
Method Summary
Modifier and TypeMethodDescriptionprivate longcalcMidnightMillis(long time, int addDays) static FixedDateFormatcreate(FixedDateFormat.FixedFormat format) Returns a newFixedDateFormatobject for the specifiedFixedFormatand aTimeZone.getDefault()TimeZone.static FixedDateFormatcreate(FixedDateFormat.FixedFormat format, TimeZone tz) Returns a newFixedDateFormatobject for the specifiedFixedFormatand TimeZone.static FixedDateFormatcreateIfSupported(String... options) private intdaylightSavingTime(int hourOfDay) private intformat(long epochMillis) intformat(long epochMillis, char[] buffer, int startPos) formatInstant(Instant instant) intformatInstant(Instant instant, char[] buffer, int startPos) private intformatNanoOfMillisecond(int nanoOfMillisecond, char[] buffer, int pos) Returns the full pattern of the selected fixed format.Returns the time zone.booleanisEquivalent(long oldEpochSecond, int oldNanoOfSecond, long epochSecond, int nanoOfSecond) Returnstrueif the old and new date values will result in the same formatted output,falseif results may differ.longmillisSinceMidnight(long currentTime) Returns the number of milliseconds since midnight in the time zone that thisFixedDateFormatwas constructed with for the specified currentTime.private voidupdateCachedDate(long now) private voidprivate voidupdateMidnightMillis(long now) private voidwriteDate(char[] buffer, int startPos) private intwriteTime(int ms, char[] buffer, int pos) private intwriteTimeZone(long epochMillis, char[] buffer, int pos)
-
Field Details
-
NONE
private static final char NONE- See Also:
-
fixedFormat
-
timeZone
-
length
private final int length -
secondFractionDigits
private final int secondFractionDigits -
fastDateFormat
-
timeSeparatorChar
private final char timeSeparatorChar -
millisSeparatorChar
private final char millisSeparatorChar -
timeSeparatorLength
private final int timeSeparatorLength -
millisSeparatorLength
private final int millisSeparatorLength -
fixedTimeZoneFormat
-
midnightToday
private volatile long midnightToday -
midnightTomorrow
private volatile long midnightTomorrow -
dstOffsets
private final int[] dstOffsets -
cachedDate
private char[] cachedDate -
dateLength
private int dateLength -
TABLE
static int[] TABLE
-
-
Constructor Details
-
FixedDateFormat
FixedDateFormat(FixedDateFormat.FixedFormat fixedFormat, TimeZone tz) Constructs a FixedDateFormat for the specified fixed format.Package protected for unit tests.
- Parameters:
fixedFormat- the fixed formattz- time zone
-
FixedDateFormat
FixedDateFormat(FixedDateFormat.FixedFormat fixedFormat, TimeZone tz, int secondFractionDigits) Constructs a FixedDateFormat for the specified fixed format.Package protected for unit tests.
- Parameters:
fixedFormat- the fixed formattz- time zonesecondFractionDigits- the number of digits specifying the fraction of the second to show
-
-
Method Details
-
createIfSupported
-
create
Returns a newFixedDateFormatobject for the specifiedFixedFormatand aTimeZone.getDefault()TimeZone.- Parameters:
format- the format to use- Returns:
- a new
FixedDateFormatobject
-
create
Returns a newFixedDateFormatobject for the specifiedFixedFormatand TimeZone.- Parameters:
format- the format to usetz- the time zone to use- Returns:
- a new
FixedDateFormatobject
-
getFormat
Returns the full pattern of the selected fixed format.- Returns:
- the full date-time pattern
-
getTimeZone
Returns the time zone.- Returns:
- the time zone
-
millisSinceMidnight
public long millisSinceMidnight(long currentTime) Returns the number of milliseconds since midnight in the time zone that this
FixedDateFormatwas constructed with for the specified currentTime.As a side effect, this method updates the cached formatted date and the cached date demarcation timestamps when the specified current time is outside the previously set demarcation timestamps for the start or end of the current day.
- Parameters:
currentTime- the current time in millis since the epoch- Returns:
- the number of milliseconds since midnight for the specified time
-
updateMidnightMillis
private void updateMidnightMillis(long now) -
calcMidnightMillis
private long calcMidnightMillis(long time, int addDays) -
updateDaylightSavingTime
private void updateDaylightSavingTime() -
updateCachedDate
private void updateCachedDate(long now) -
formatInstant
-
formatInstant
-
digitsLessThanThree
private int digitsLessThanThree() -
format
-
format
public int format(long epochMillis, char[] buffer, int startPos) -
writeDate
private void writeDate(char[] buffer, int startPos) -
writeTime
private int writeTime(int ms, char[] buffer, int pos) -
writeTimeZone
private int writeTimeZone(long epochMillis, char[] buffer, int pos) -
formatNanoOfMillisecond
private int formatNanoOfMillisecond(int nanoOfMillisecond, char[] buffer, int pos) -
daylightSavingTime
private int daylightSavingTime(int hourOfDay) -
isEquivalent
public boolean isEquivalent(long oldEpochSecond, int oldNanoOfSecond, long epochSecond, int nanoOfSecond) Returnstrueif the old and new date values will result in the same formatted output,falseif results may differ.
-