public final class HumanTime extends Object implements Externalizable, Comparable<HumanTime>
Use HumanTime by creating an instance that contains the time delta (HumanTime(long)), create an
empty instance through (HumanTime()) and set the delta using the y(), d(),
h(), s() and ms() methods or parse a CharSequence representation
(eval(CharSequence)). Parsing ignores whitespace and is case insensitive.
HumanTime will format time deltas in years ("y"), days ("d"), hours ("h"), minutes ("m"), seconds ("s") and milliseconds ("ms"), separated by a blank character. For approximate representations, the time delta will be round up or down if necessary.
getApproximately() and getExactly().eval(CharSequence),
approximately(CharSequence),
Date
Formatting and Parsing for Humans in Java with HumanTime,
Serialized Form| Constructor and Description |
|---|
HumanTime()
No-argument Constructor for HumanTime.
|
HumanTime(long delta)
Constructor for HumanTime.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
approximately(CharSequence in)
Parses and formats the given char sequence, potentially removing some data to make the output easier to
understand.
|
static String |
approximately(long l)
Formats the given time delta, preserving all data.
|
int |
compareTo(HumanTime t) |
HumanTime |
d()
Adds one day to the time delta.
|
HumanTime |
d(int n)
Adds n days to the time delta.
|
boolean |
equals(Object obj) |
static HumanTime |
eval(CharSequence s)
Parses a
CharSequence argument and returns a HumanTime instance. |
static String |
exactly(CharSequence in)
Parses and formats the given char sequence, preserving all data.
|
static String |
exactly(long l)
Formats the given time delta, preserving all data.
|
String |
getApproximately()
Returns an approximate, human-formatted representation of the time delta.
|
<T extends Appendable> |
getApproximately(T a)
Appends an approximate, human-formatted representation of the time delta to the given
Appendable object. |
long |
getDelta()
Returns the time delta.
|
String |
getExactly()
Returns a human-formatted representation of the time delta.
|
<T extends Appendable> |
getExactly(T a)
Appends a human-formatted representation of the time delta to the given
Appendable object. |
HumanTime |
h()
Adds one hour to the time delta.
|
HumanTime |
h(int n)
Adds n hours to the time delta.
|
int |
hashCode() |
HumanTime |
m()
Adds one month to the time delta.
|
HumanTime |
m(int n)
Adds n months to the time delta.
|
HumanTime |
ms()
Adds one millisecond to the time delta.
|
HumanTime |
ms(int n)
Adds n milliseconds to the time delta.
|
void |
readExternal(ObjectInput in) |
HumanTime |
s()
Adds one second to the time delta.
|
HumanTime |
s(int n)
Adds n seconds to the time delta.
|
String |
toString() |
void |
writeExternal(ObjectOutput out) |
HumanTime |
y()
Adds one year to the time delta.
|
HumanTime |
y(int n)
Adds n years to the time delta.
|
public HumanTime()
Equivalent to calling
new HumanTime(0L).
public HumanTime(long delta)
delta - the initial time delta, interpreted as a positive numberpublic static HumanTime eval(CharSequence s)
CharSequence argument and returns a HumanTime instance.s - the char sequence, may not be nullnullpublic static String exactly(CharSequence in)
Equivalent to
eval(in).getExactly()
in - the char sequence, may not be nullnullpublic static String exactly(long l)
Equivalent to
new HumanTime(in).getExactly()
l - the time deltanullpublic static String approximately(CharSequence in)
Equivalent to
eval(in).getApproximately()
in - the char sequence, may not be nullnullpublic static String approximately(long l)
Equivalent to
new HumanTime(l).getApproximately()
l - the time deltanullpublic HumanTime y()
public HumanTime y(int n)
n - npublic HumanTime d()
public HumanTime d(int n)
n - npublic HumanTime h()
public HumanTime h(int n)
n - npublic HumanTime m()
public HumanTime m(int n)
n - npublic HumanTime s()
public HumanTime s(int n)
n - secondspublic HumanTime ms()
public HumanTime ms(int n)
n - npublic String getExactly()
nullpublic <T extends Appendable> T getExactly(T a)
Appendable object.T - the return typea - the Appendable object, may not be nullnullpublic String getApproximately()
nullpublic <T extends Appendable> T getApproximately(T a)
Appendable object.T - the return typea - the Appendable object, may not be nullnullpublic long getDelta()
public int compareTo(HumanTime t)
compareTo in interface Comparable<HumanTime>public void readExternal(ObjectInput in) throws IOException
readExternal in interface ExternalizableIOExceptionpublic void writeExternal(ObjectOutput out) throws IOException
writeExternal in interface ExternalizableIOExceptionCopyright © 2018 Erudika. All rights reserved.