Class DateUtils
java.lang.Object
org.archive.util.DateUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanbyteArrayEquals(byte[] lhs, byte[] rhs) check that two byte arrays are equal.static StringdoubleToString(double val, int maxFractionDigits) Converts a double to a string.static StringformatBytesForDisplay(long amount) Takes a byte size and formats it for display with 'friendly' units.static StringformatMillisecondsToConventional(long time) Convert milliseconds value to a human-readable durationstatic StringformatMillisecondsToConventional(long duration, int unitCount) Convert milliseconds value to a human-readable duration of mixed units, using units no larger than days.static StringUtility function for creating 12-digit(no seconds!)static Stringget12DigitDate(long date) Utility function for creating 12-digit(no seconds!)static StringUtility function for creating 12-digit(no seconds!)static StringUtility function for creating arc-style date stamps in the format yyyyMMddHHmmss.static Stringget14DigitDate(long date) Utility function for creating arc-style date stamps in the format yyyyMMddHHmmss.static StringUtility function for creating arc-style date stamps in the format yyyyMMddHHmmss.static StringUtility function for creating arc-style date stamps in the format yyyMMddHHmmssSSS.static Stringget17DigitDate(long date) Utility function for creating warc-style date stamps in the format yyyyMMddHHmmssSSS.static Stringget17DigitDate(Date date) Utility function for creating warc-style date stamps in the format yyyyMMddHHmmssSSS.static DateParses an ARC-style date.static StringUtility function for creating log timestamps, in W3C/ISO8601 format, assuming UTC.static StringgetLog14Date(long date) Utility function for creating log timestamps, in W3C/ISO8601 format, assuming UTC.static StringgetLog14Date(Date date) Utility function for creating log timestamps, in W3C/ISO8601 format, assuming UTC.static StringUtility function for creating log timestamps, in W3C/ISO8601 format, assuming UTC.static StringgetLog17Date(long date) Utility function for creating log timestamps, in W3C/ISO8601 format, assuming UTC.static StringgetLog17Date(Date date) Utility function for creating log timestamps, in W3C/ISO8601 format, assuming UTC.static StringgetRFC1123Date(Date date) Utility function for creating HTTP header style date strings, specifically, RFC 1123: EEE, dd MMM yyyy HH:mm:ss z.static DategetSecondsSinceEpoch(String timestamp) static StringUtility function for creating UNIQUE-from-this-class arc-style date stamps in the format yyyMMddHHmmss.static StringpadTo(int i, int pad) Convert anintto aString, and pad it topadspaces.static StringPad the givenStringtopadcharacters wide by pre-pending spaces.static StringPad the givenStringtopadcharacters wide by pre-pendingpadChar.static Dateparse12DigitDate(String date) Utility function for parsing arc-style date stamps in the format yyyMMddHHmm.static Dateparse14DigitDate(String date) Utility function for parsing arc-style date stamps in the format yyyMMddHHmmss.static Dateparse17DigitDate(String date) Utility function for parsing arc-style date stamps in the format yyyMMddHHmmssSSS.static StringsecondsSinceEpoch(String timestamp) static StringzeroPadInteger(int i)
-
Field Details
-
VERSION
- See Also:
-
MAX_INT_CHAR_WIDTH
public static int MAX_INT_CHAR_WIDTH
-
-
Constructor Details
-
DateUtils
public DateUtils()
-
-
Method Details
-
getRFC1123Date
-
get17DigitDate
Utility function for creating arc-style date stamps in the format yyyMMddHHmmssSSS. Date stamps are in the UTC time zone- Returns:
- the date stamp for NOW
-
get17DigitDate
Utility function for creating warc-style date stamps in the format yyyyMMddHHmmssSSS. Date stamps are in the UTC time zone- Parameters:
date- milliseconds since epoc- Returns:
- the date stamp
-
get17DigitDate
-
get14DigitDate
Utility function for creating arc-style date stamps in the format yyyyMMddHHmmss. Date stamps are in the UTC time zone- Returns:
- the date stamp for NOW
-
get14DigitDate
Utility function for creating arc-style date stamps in the format yyyyMMddHHmmss. Date stamps are in the UTC time zone- Parameters:
date- milliseconds since epoc- Returns:
- the date stamp
-
get14DigitDate
-
get12DigitDate
Utility function for creating 12-digit(no seconds!) date stamps in the format yyyyMMddHHmm. Date stamps are in the UTC time zone- Returns:
- the date stamp for NOW
-
get12DigitDate
Utility function for creating 12-digit(no seconds!) date stamps in the format yyyyMMddHHmm. Date stamps are in the UTC time zone- Parameters:
date- milliseconds since epoc- Returns:
- the date stamp
-
get12DigitDate
-
getLog17Date
Utility function for creating log timestamps, in W3C/ISO8601 format, assuming UTC. Use current time. Format is yyyy-MM-dd'T'HH:mm:ss.SSS'Z'- Returns:
- the date stamp for NOW
-
getLog17Date
Utility function for creating log timestamps, in W3C/ISO8601 format, assuming UTC. Format is yyyy-MM-dd'T'HH:mm:ss.SSS'Z'- Parameters:
date- milliseconds since epoc.- Returns:
- the date stamp
-
getLog17Date
-
getLog14Date
Utility function for creating log timestamps, in W3C/ISO8601 format, assuming UTC. Use current time. Format is yyyy-MM-dd'T'HH:mm:ss'Z'- Returns:
- the date stamp for NOW
-
getLog14Date
Utility function for creating log timestamps, in W3C/ISO8601 format, assuming UTC. Format is yyyy-MM-dd'T'HH:mm:ss'Z'- Parameters:
date- long timestamp to format.- Returns:
- the date stamp
-
getLog14Date
-
getDate
Parses an ARC-style date. If passed String is < 12 characters in length, we pad. At a minimum, String should contain a year (>=4 characters). Parse will also fail if day or month are incompletely specified. Depends on the above getXXDigitDate methods.- Parameters:
d- A 4-17 digit date in ARC style (yyyytoyyyyMMddHHmmssSSS) formatting.- Returns:
- A Date object representing the passed String.
- Throws:
ParseException
-
parse17DigitDate
Utility function for parsing arc-style date stamps in the format yyyMMddHHmmssSSS. Date stamps are in the UTC time zone. The whole string will not be parsed, only the first 17 digits.- Parameters:
date- an arc-style formatted date stamp- Returns:
- the Date corresponding to the date stamp string
- Throws:
ParseException- if the inputstring was malformed
-
parse14DigitDate
Utility function for parsing arc-style date stamps in the format yyyMMddHHmmss. Date stamps are in the UTC time zone. The whole string will not be parsed, only the first 14 digits.- Parameters:
date- an arc-style formatted date stamp- Returns:
- the Date corresponding to the date stamp string
- Throws:
ParseException- if the inputstring was malformed
-
parse12DigitDate
Utility function for parsing arc-style date stamps in the format yyyMMddHHmm. Date stamps are in the UTC time zone. The whole string will not be parsed, only the first 12 digits.- Parameters:
date- an arc-style formatted date stamp- Returns:
- the Date corresponding to the date stamp string
- Throws:
ParseException- if the inputstring was malformed
-
secondsSinceEpoch
- Parameters:
timestamp- A 14-digit timestamp or the suffix for a 14-digit timestamp: E.g. '20010909014640' or '20010101' or '1970'.- Returns:
- Seconds since the epoch as a string zero-pre-padded so always Integer.MAX_VALUE wide (Makes it so sorting of resultant string works properly).
- Throws:
ParseException
-
getSecondsSinceEpoch
- Parameters:
timestamp- A 14-digit timestamp or the suffix for a 14-digit timestamp: E.g. '20010909014640' or '20010101' or '1970'.- Returns:
- A date.
- Throws:
ParseException- See Also:
-
zeroPadInteger
- Parameters:
i- Integer to add prefix of zeros too. If passed 2005, will return the String0000002005. String width is the width of Integer.MAX_VALUE as a string (10 digits).- Returns:
- Padded String version of
i.
-
padTo
Convert anintto aString, and pad it topadspaces.- Parameters:
i- the intpad- the width to pad to.- Returns:
- String w/ padding.
-
padTo
-
padTo
Pad the givenStringtopadcharacters wide by pre-pendingpadChar.sshould not benull. Ifsis already wider thanpadno change is done.- Parameters:
s- the String to padpad- the width to pad to.padChar- The pad character to use.- Returns:
- String w/ padding.
-
byteArrayEquals
public static boolean byteArrayEquals(byte[] lhs, byte[] rhs) check that two byte arrays are equal. They may benull.- Parameters:
lhs- a byte arrayrhs- another byte array.- Returns:
trueif they are both equal (or bothnull)
-
doubleToString
Converts a double to a string.- Parameters:
val- The double to convertmaxFractionDigits- How many characters to include after '.'- Returns:
- the double as a string.
-
formatBytesForDisplay
Takes a byte size and formats it for display with 'friendly' units.This involves converting it to the largest unit (of B, KiB, MiB, GiB, TiB) for which the amount will be > 1.
Additionally, at least 2 significant digits are always displayed.
Negative numbers will be returned as '0 B'.
- Parameters:
amount- the amount of bytes- Returns:
- A string containing the amount, properly formated.
-
formatMillisecondsToConventional
Convert milliseconds value to a human-readable duration- Parameters:
time-- Returns:
- Human readable string version of passed
time
-
formatMillisecondsToConventional
Convert milliseconds value to a human-readable duration of mixed units, using units no larger than days. For example, "5d12h13m12s113ms" or "19h51m".- Parameters:
duration-unitCount- how many significant units to show, at most for example, a value of 2 would show days+hours or hours+seconds but not hours+second+milliseconds- Returns:
- Human readable string version of passed
time
-
getUnique14DigitDate
Utility function for creating UNIQUE-from-this-class arc-style date stamps in the format yyyMMddHHmmss. Rather than giving a duplicate datestamp on a subsequent call, will increment the seconds until a unique value is returned. Date stamps are in the UTC time zone- Returns:
- the date stamp
-