Package com.fizzed.crux.util
Class DateTimes
- java.lang.Object
-
- com.fizzed.crux.util.DateTimes
-
public class DateTimes extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description DateTimes()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static TimeDurationage(org.joda.time.DateTime dt)Calculates the age of a datetime from 'now'.static TimeDurationage(org.joda.time.DateTime dt, long epochMillis)Calculates the age of a datetime against a reference epoch millis.static org.joda.time.DateTimedateTime(java.time.Instant instant)static booleanequals(org.joda.time.DateTime a, org.joda.time.DateTime b)Tests equality (ignoring timezones).static booleangt(org.joda.time.DateTime a, org.joda.time.DateTime b)Isavalue greater thanb.static booleangte(org.joda.time.DateTime a, org.joda.time.DateTime b)Isavalue greater than or equal tob.static java.time.DurationjavaDuration(org.joda.time.Duration duration)static java.time.InstantjavaInstant(org.joda.time.DateTime dt)static booleanlt(org.joda.time.DateTime a, org.joda.time.DateTime b)Isavalue less thanb.static booleanlte(org.joda.time.DateTime a, org.joda.time.DateTime b)Isavalue less than or equal tob.static org.joda.time.DateTimemax(org.joda.time.DateTime... dts)Returns the minimum of all datetimes.static org.joda.time.DateTimemax(org.joda.time.DateTime a, org.joda.time.DateTime b)Returns a if greater than or equal to b, otherwise b.static org.joda.time.DateTimemin(org.joda.time.DateTime... dts)Returns the minimum of all datetimes.static org.joda.time.DateTimemin(org.joda.time.DateTime a, org.joda.time.DateTime b)Returns a if less than or equal to b, otherwise b.static org.joda.time.DateTimenow()Returns now() in UTC.static java.lang.Stringuptime(org.joda.time.DateTime dt)Formats a string of "uptime" relative to NOW such as "6m 1s 467ms"static java.lang.Stringuptime(org.joda.time.DateTime end, org.joda.time.DateTime start)static java.lang.Stringuptime(org.joda.time.Duration duration)static org.joda.time.DateTimeutc(org.joda.time.DateTime dt)Returns a new DateTime in UTC.static booleanwithin(org.joda.time.DateTime dt, org.joda.time.DateTime start, org.joda.time.DateTime end)Whether datetime is within start and end datetimes.static booleanwithin(org.joda.time.DateTime dt, org.joda.time.DateTime start, org.joda.time.DateTime end, boolean endInclusive)Whether datetime is within start and end datetimes.The min of start and end is detected so the ordering does not matter.static booleanwithin(org.joda.time.DateTime dt, org.joda.time.DateTime start, org.joda.time.DateTime end, boolean startInclusive, boolean endInclusive)Whether datetime is within start and end datetimes.The min of start and end is detected so the ordering does not matter.By default, this method makes the start date INCLUSIVE and the end date EXCLUSIVE/INCLUSIVE depending on what you pass in.
-
-
-
Method Detail
-
dateTime
public static org.joda.time.DateTime dateTime(java.time.Instant instant)
-
javaInstant
public static java.time.Instant javaInstant(org.joda.time.DateTime dt)
-
javaDuration
public static java.time.Duration javaDuration(org.joda.time.Duration duration)
-
now
public static org.joda.time.DateTime now()
Returns now() in UTC.- Returns:
- Now in UTC
-
utc
public static org.joda.time.DateTime utc(org.joda.time.DateTime dt)
Returns a new DateTime in UTC.- Parameters:
dt-- Returns:
-
equals
public static boolean equals(org.joda.time.DateTime a, org.joda.time.DateTime b)Tests equality (ignoring timezones).- Parameters:
a-b-- Returns:
-
min
public static org.joda.time.DateTime min(org.joda.time.DateTime a, org.joda.time.DateTime b)Returns a if less than or equal to b, otherwise b.- Parameters:
a-b-- Returns:
-
min
public static org.joda.time.DateTime min(org.joda.time.DateTime... dts)
Returns the minimum of all datetimes.- Parameters:
dts-- Returns:
-
max
public static org.joda.time.DateTime max(org.joda.time.DateTime a, org.joda.time.DateTime b)Returns a if greater than or equal to b, otherwise b.- Parameters:
a-b-- Returns:
-
max
public static org.joda.time.DateTime max(org.joda.time.DateTime... dts)
Returns the minimum of all datetimes.- Parameters:
dts-- Returns:
-
gt
public static boolean gt(org.joda.time.DateTime a, org.joda.time.DateTime b)Isavalue greater thanb. If a is not null and b is null then this is true.- Parameters:
a-b-- Returns:
-
gte
public static boolean gte(org.joda.time.DateTime a, org.joda.time.DateTime b)Isavalue greater than or equal tob. Will still be true if both values are null OR if a is non-null and b is null.- Parameters:
a-b-- Returns:
-
lt
public static boolean lt(org.joda.time.DateTime a, org.joda.time.DateTime b)Isavalue less thanb. If b is not null and a is null then this is true.- Parameters:
a-b-- Returns:
-
lte
public static boolean lte(org.joda.time.DateTime a, org.joda.time.DateTime b)Isavalue less than or equal tob. Will still be true if both values are null OR if a is non-null and b is null.- Parameters:
a-b-- Returns:
-
age
public static TimeDuration age(org.joda.time.DateTime dt)
Calculates the age of a datetime from 'now'. Just like your birthday, if the datetime is in the past then you a positive duration will be returned, if in the future then negative. For example, if the datetime is April 1 and 'now' is April 2, then the age will be a positive 1 day.- Parameters:
dt- The datetime to calculate the age of.- Returns:
-
age
public static TimeDuration age(org.joda.time.DateTime dt, long epochMillis)
Calculates the age of a datetime against a reference epoch millis. If the datetime is on April 1 and the epochMillis is on April 2, then the age will be a positive 1 day.- Parameters:
dt-epochMillis-- Returns:
-
within
public static boolean within(org.joda.time.DateTime dt, org.joda.time.DateTime start, org.joda.time.DateTime end)Whether datetime is within start and end datetimes. The min of start and end is detected so the ordering does not matter. By default, this method makes the start date INCLUSIVE and the end date EXCLUSIVE.- Parameters:
dt- The datetime to checkstart- The start (or end) of the datetime rangeend- The end (or start) of the datetime range- Returns:
- True if within range, otherwise false.
-
within
public static boolean within(org.joda.time.DateTime dt, org.joda.time.DateTime start, org.joda.time.DateTime end, boolean endInclusive)Whether datetime is within start and end datetimes.The min of start and end is detected so the ordering does not matter. By default, this method makes the start date INCLUSIVE and the end date EXCLUSIVE/INCLUSIVE depending on what you pass in.- Parameters:
dt- The datetime to checkstart- The start (or end) of the datetime rangeend- The end (or start) of the datetime rangeendInclusive- True if the end date is inclusive, otherwise exclusive.- Returns:
- True if within range, otherwise false.
-
within
public static boolean within(org.joda.time.DateTime dt, org.joda.time.DateTime start, org.joda.time.DateTime end, boolean startInclusive, boolean endInclusive)Whether datetime is within start and end datetimes.The min of start and end is detected so the ordering does not matter.By default, this method makes the start date INCLUSIVE and the end date EXCLUSIVE/INCLUSIVE depending on what you pass in.- Parameters:
dt- The datetime to checkstart- The start (or end) of the datetime rangeend- The end (or start) of the datetime rangestartInclusive- True if the start date is inclusive, otherwise exclusive.endInclusive- True if the end date is inclusive, otherwise exclusive.- Returns:
- True if within range, otherwise false.
-
uptime
public static java.lang.String uptime(org.joda.time.DateTime dt)
Formats a string of "uptime" relative to NOW such as "6m 1s 467ms"- Parameters:
dt-- Returns:
-
uptime
public static java.lang.String uptime(org.joda.time.DateTime end, org.joda.time.DateTime start)
-
uptime
public static java.lang.String uptime(org.joda.time.Duration duration)
-
-