Class Duration
- java.lang.Object
-
- org.apache.logging.log4j.core.appender.rolling.action.Duration
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<Duration>
@Deprecated public class Duration extends java.lang.Object implements java.io.Serializable, java.lang.Comparable<Duration>
Deprecated.since 2.24.0 useDurationinstead.Simplified implementation of the ISO-8601 Durations standard. The supported format isPnDTnHnMnS, with 'P' and 'T' optional. Days are considered to be exactly 24 hours.Similarly to the
java.time.Durationclass, this class does not support year or month sections in the format. This implementation does not support fractions or negative values.- See Also:
parse(CharSequence), Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static intHOURS_PER_DAYDeprecated.Hours per day.private static intMINUTES_PER_HOURDeprecated.Minutes per hour.private static java.util.regex.PatternPATTERNDeprecated.The pattern for parsing.private longsecondsDeprecated.The number of seconds in the duration.private static intSECONDS_PER_DAYDeprecated.Seconds per day.private static intSECONDS_PER_HOURDeprecated.Seconds per hour.private static intSECONDS_PER_MINUTEDeprecated.Seconds per minute.private static longserialVersionUIDDeprecated.static DurationZERODeprecated.Constant for a duration of zero.
-
Constructor Summary
Constructors Modifier Constructor Description privateDuration(long seconds)Deprecated.Constructs an instance ofDurationusing seconds.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description intcompareTo(Duration other)Deprecated.private static Durationcreate(long seconds)Deprecated.Obtains an instance ofDurationusing seconds.private static Durationcreate(long daysAsSecs, long hoursAsSecs, long minsAsSecs, long secs)Deprecated.booleanequals(java.lang.Object obj)Deprecated.inthashCode()Deprecated.static DurationofMillis(long millis)Deprecated.static Durationparse(java.lang.CharSequence text)Deprecated.Obtains aDurationfrom a text string such asPnDTnHnMnS.private static longparseNumber(java.lang.CharSequence text, java.lang.String parsed, int multiplier, java.lang.String errorText)Deprecated.longtoMillis()Deprecated.Converts this duration to the total length in milliseconds.java.lang.StringtoString()Deprecated.A string representation of this duration using ISO-8601 seconds based representation, such asPT8H6M12S.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Deprecated.- See Also:
- Constant Field Values
-
ZERO
public static final Duration ZERO
Deprecated.Constant for a duration of zero.
-
HOURS_PER_DAY
private static final int HOURS_PER_DAY
Deprecated.Hours per day.- See Also:
- Constant Field Values
-
MINUTES_PER_HOUR
private static final int MINUTES_PER_HOUR
Deprecated.Minutes per hour.- See Also:
- Constant Field Values
-
SECONDS_PER_MINUTE
private static final int SECONDS_PER_MINUTE
Deprecated.Seconds per minute.- See Also:
- Constant Field Values
-
SECONDS_PER_HOUR
private static final int SECONDS_PER_HOUR
Deprecated.Seconds per hour.- See Also:
- Constant Field Values
-
SECONDS_PER_DAY
private static final int SECONDS_PER_DAY
Deprecated.Seconds per day.- See Also:
- Constant Field Values
-
PATTERN
private static final java.util.regex.Pattern PATTERN
Deprecated.The pattern for parsing.
-
seconds
private final long seconds
Deprecated.The number of seconds in the duration.
-
-
Method Detail
-
ofMillis
public static Duration ofMillis(long millis)
Deprecated.- Since:
- 2.24.0
-
parse
public static Duration parse(java.lang.CharSequence text)
Deprecated.Obtains aDurationfrom a text string such asPnDTnHnMnS.This will parse a textual representation of a duration, including the string produced by
toString(). The formats accepted are based on the ISO-8601 duration formatPnDTnHnMnSwith days considered to be exactly 24 hours.This implementation does not support negative numbers or fractions (so the smallest non-zero value a Duration can have is one second).
The string optionally starts with the ASCII letter "P" in upper or lower case. There are then four sections, each consisting of a number and a suffix. The sections have suffixes in ASCII of "D", "H", "M" and "S" for days, hours, minutes and seconds, accepted in upper or lower case. The suffixes must occur in order. The ASCII letter "T" may occur before the first occurrence, if any, of an hour, minute or second section. At least one of the four sections must be present, and if "T" is present there must be at least one section after the "T". The number part of each section must consist of one or more ASCII digits. The number may not be prefixed by the ASCII negative or positive symbol. The number of days, hours, minutes and seconds must parse to a
long.Examples:
"PT20S" -- parses as "20 seconds" "PT15M" -- parses as "15 minutes" (where a minute is 60 seconds) "PT10H" -- parses as "10 hours" (where an hour is 3600 seconds) "P2D" -- parses as "2 days" (where a day is 24 hours or 86400 seconds) "P2DT3H4M" -- parses as "2 days, 3 hours and 4 minutes"- Parameters:
text- the text to parse, not null- Returns:
- the parsed duration, not null
- Throws:
java.lang.IllegalArgumentException- if the text cannot be parsed to a duration
-
parseNumber
private static long parseNumber(java.lang.CharSequence text, java.lang.String parsed, int multiplier, java.lang.String errorText)Deprecated.
-
create
private static Duration create(long daysAsSecs, long hoursAsSecs, long minsAsSecs, long secs)
Deprecated.
-
create
private static Duration create(long seconds)
Deprecated.Obtains an instance ofDurationusing seconds.- Parameters:
seconds- the length of the duration in seconds, positive only
-
toMillis
public long toMillis()
Deprecated.Converts this duration to the total length in milliseconds.- Returns:
- the total length of the duration in milliseconds
-
equals
public boolean equals(java.lang.Object obj)
Deprecated.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Deprecated.- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Deprecated.A string representation of this duration using ISO-8601 seconds based representation, such asPT8H6M12S.The format of the returned string will be
PnDTnHnMnS, where n is the relevant days, hours, minutes or seconds part of the duration. If a section has a zero value, it is omitted. The hours, minutes and seconds are all positive.Examples:
"20 seconds" -- "PT20S "15 minutes" (15 * 60 seconds) -- "PT15M" "10 hours" (10 * 3600 seconds) -- "PT10H" "2 days" (2 * 86400 seconds) -- "P2D"- Overrides:
toStringin classjava.lang.Object- Returns:
- an ISO-8601 representation of this duration, not null
-
-