Package com.atlassian.greenhopper.util
Class DateUtils
java.lang.Object
com.atlassian.greenhopper.util.DateUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.joda.time.DateTime
epochMillisToDateTime
(long timeSinceEpoch) Translates a field whose type is long into a DateTime.static org.joda.time.DateTime
getTodayAt
(org.joda.time.DateTimeZone timeZone) Gives today's local (server) time, at the given timezone (keeping the value)static boolean
isInRange
(org.joda.time.ReadableInstant date, org.joda.time.ReadableInstant startDate, org.joda.time.ReadableInstant endDate) Checks if the given date is in range, meaning equals or larger than the start date and less or equal to the end date.static boolean
isToday
(org.joda.time.DateMidnight date) Checks whether the given date is today.static org.joda.time.DateMidnight
toDateMidnight
(Long date, org.joda.time.DateTimeZone timeZone) Convert a Long instant (milliseconds) toDateMidnight
.static org.joda.time.DateMidnight
toDateMidnight
(Date date) Convert a java.util.Date instance toDateMidnight
.static org.joda.time.DateMidnight
toDateMidnight
(Date date, org.joda.time.DateMidnight defaultDate) Convert a java.util.Date instance toDateMidnight
.static org.joda.time.DateMidnight
toDateMidnight
(Date date, org.joda.time.DateTimeZone timeZone) Convert a java.util.Date instance toDateMidnight
.static org.joda.time.DateTime
toDateTime
(Date date) Converts a given date to a DateTime objectstatic org.joda.time.DateTime
toDateTime
(Date date, org.joda.time.DateTimeZone timeZone) Converts a given date to a DateTime object, setting the timezone to the given value (while keeping the value)static long
truncateMilliseconds
(long milliseconds) Takes the long representing the milliseconds and truncates it to seconds.static long
truncateMilliseconds
(Date date) Takes the long representing the milliseconds and truncates it to seconds.
-
Constructor Details
-
DateUtils
public DateUtils()
-
-
Method Details
-
toDateMidnight
public static org.joda.time.DateMidnight toDateMidnight(Date date, org.joda.time.DateTimeZone timeZone) Convert a java.util.Date instance toDateMidnight
. DateMidnight has a fixed time component of 00:00, which is considered the first instant of the day, with the given timeZone.- Returns:
- new DateMidnight instance of the same day, or null if the date parameter was null
-
toDateMidnight
public static org.joda.time.DateMidnight toDateMidnight(Long date, org.joda.time.DateTimeZone timeZone) Convert a Long instant (milliseconds) toDateMidnight
. DateMidnight has a fixed time component of 00:00, which is considered the first instant of the day, with the given timeZone.- Returns:
- new DateMidnight instance of the same day, or null if the date parameter was null
-
toDateMidnight
Convert a java.util.Date instance toDateMidnight
. DateMidnight has a fixed time component of 00:00, which is considered the first instant of the day. It is timezone-aware.- Returns:
- new DateMidnight instance of the same day, or null if the date parameter was null
-
toDateMidnight
public static org.joda.time.DateMidnight toDateMidnight(@Nullable Date date, org.joda.time.DateMidnight defaultDate) Convert a java.util.Date instance toDateMidnight
. DateMidnight has a fixed time component of 00:00, which is considered the first instant of the day. It is timezone-aware.- Returns:
- new DateMidnight instance of the same day, or defaultDate if the date parameter was null
-
isInRange
public static boolean isInRange(org.joda.time.ReadableInstant date, org.joda.time.ReadableInstant startDate, org.joda.time.ReadableInstant endDate) Checks if the given date is in range, meaning equals or larger than the start date and less or equal to the end date. If start date or end date is null, they're not taken into account, and any date is valid.- Parameters:
date
- : the date to checkstartDate
- : the lower boundary of the rangeendDate
- : the upper boundary of the range- Returns:
- true if the date is equal or between the lower and upper boundary
-
isToday
public static boolean isToday(org.joda.time.DateMidnight date) Checks whether the given date is today. -
toDateTime
Converts a given date to a DateTime object -
toDateTime
Converts a given date to a DateTime object, setting the timezone to the given value (while keeping the value) -
getTodayAt
public static org.joda.time.DateTime getTodayAt(org.joda.time.DateTimeZone timeZone) Gives today's local (server) time, at the given timezone (keeping the value) -
truncateMilliseconds
public static long truncateMilliseconds(long milliseconds) Takes the long representing the milliseconds and truncates it to seconds.- Parameters:
milliseconds
- Time to truncate.- Returns:
- Truncated milliseconds.
-
truncateMilliseconds
Takes the long representing the milliseconds and truncates it to seconds.- Parameters:
date
- Time to truncate.- Returns:
- Truncated milliseconds.
-
epochMillisToDateTime
public static org.joda.time.DateTime epochMillisToDateTime(long timeSinceEpoch) Translates a field whose type is long into a DateTime. As of 8.0, Jira uses long epoch-offsets to represent dates in the index.- Parameters:
timeSinceEpoch
- represents the number of milliseconds from the java epoch- Returns:
- DateTime represented by the dateString
-