Package jetbrains.buildServer.util
Class Dates
- java.lang.Object
-
- jetbrains.buildServer.util.Dates
-
public class Dates extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static int
APR
static int
AUG
static int
DEC
static java.lang.String
DEFAULT_DATE_FORMAT
static int
FEB
static int
JAN
static int
JUL
static int
JUN
static int
MAR
static int
MAY
static int
NOV
static int
OCT
static long
ONE_DAY
static long
ONE_HOUR
static long
ONE_MINUTE
static long
ONE_SECOND
static long
ONE_WEEK
static int
SEP
-
Constructor Summary
Constructors Constructor Description Dates()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Date
after(java.util.Date date)
static java.util.Date
after(java.util.Date date, long timeMs)
static java.util.Date
afterNow(long timeMs)
static java.util.Date
before(java.util.Date date)
static java.util.Date
before(java.util.Date date, long timeMs)
static java.util.Date
beforeNow(long timeMs)
static java.lang.String
convertDateToFormalString(java.util.Date date)
Converts a date to a formal string like 19991231, independent of current locale.static java.lang.String
convertTimeToFormalString(java.util.Date time)
Converts a timestamp to a formal string like 19991231.235959, independent of current locale.static java.util.Calendar
copy(java.util.Calendar to, java.util.Calendar from)
static long
days(double num)
static java.util.Date
daysAfter(java.util.Date date, int days)
static java.util.Date
daysAfterNow(int days)
static java.util.Date
daysBefore(java.util.Date date, int days)
static java.util.Date
daysBeforeNow(int days)
static int
daysBetween(java.util.Date startDate, java.util.Date endDate)
Returns number of calendar days between two dates.static java.lang.String
formatDate(java.util.Date date, java.lang.String format)
static java.lang.String
formatDate(java.util.Date date, java.lang.String pattern, java.util.TimeZone tz)
Formats date according to specified timezone.static java.lang.String
formatInterval(java.util.Date from, java.util.Date to, java.util.TimeZone tz)
static java.lang.String
formatNanos(long nanos)
Returns string representation of nanoseconds in {seconds}s{millis}ms{micros}us{nanos}ns format.static java.lang.String
formatTimeZoneID(java.util.TimeZone tz)
static java.lang.String
formatTimeZoneLong(java.util.TimeZone tz)
static java.lang.String
formatTimeZoneUTCOffset()
static java.lang.String
formatTimeZoneUTCOffset(java.util.TimeZone tz)
static java.text.SimpleDateFormat
getSimpleFileDateFormatter()
static java.util.TimeZone[]
getSortedTimeZones()
static java.lang.String
getTimeZoneDescription(java.lang.String timeZone)
static long
hours(double num)
static boolean
isBeforeWithError(java.util.Date before, java.util.Date after, long allowedError)
static boolean
isDayChanged(java.util.Date date1, java.util.Date date2)
static boolean
isSameDay(java.util.Calendar cal1, java.util.Calendar cal2)
Return true if two dates have the same day of the same year (but may have different time).static boolean
isValidTimeZoneID(java.lang.String tzID)
static java.util.Date
makeDate(int year, int month, int day)
static java.util.Date
makeDate(int year, int month, int day, int hour, int minute, int second, java.lang.String timeZone)
static java.util.Date
makeDate(int year, int month, int day, java.util.Calendar calendar)
static long
minutes(double num)
static java.util.Date
now()
static long
seconds(double num)
static java.util.Date
today()
static java.util.Date
tomorrow()
static java.util.Date
toStandardDate(java.util.Date date)
Prevents using inheritors of java.util.Date (e.g.static java.util.Calendar
translateFromTimeZone(java.util.Calendar initDate, java.util.TimeZone timeZone)
static java.util.Calendar
transletoToTimeZone(java.util.Calendar initDate, java.util.TimeZone timeZone)
static void
truncateCalendar(java.util.Calendar calendar)
static void
truncateCalendarToEndOfDay(java.util.Calendar calendar)
static java.util.Date
truncateTime(java.util.Date dateAndTime)
static java.util.Date
yesterday()
-
-
-
Field Detail
-
DEFAULT_DATE_FORMAT
public static final java.lang.String DEFAULT_DATE_FORMAT
- See Also:
- Constant Field Values
-
JAN
public static final int JAN
- See Also:
- Constant Field Values
-
FEB
public static final int FEB
- See Also:
- Constant Field Values
-
MAR
public static final int MAR
- See Also:
- Constant Field Values
-
APR
public static final int APR
- See Also:
- Constant Field Values
-
MAY
public static final int MAY
- See Also:
- Constant Field Values
-
JUN
public static final int JUN
- See Also:
- Constant Field Values
-
JUL
public static final int JUL
- See Also:
- Constant Field Values
-
AUG
public static final int AUG
- See Also:
- Constant Field Values
-
SEP
public static final int SEP
- See Also:
- Constant Field Values
-
OCT
public static final int OCT
- See Also:
- Constant Field Values
-
NOV
public static final int NOV
- See Also:
- Constant Field Values
-
DEC
public static final int DEC
- See Also:
- Constant Field Values
-
ONE_SECOND
public static final long ONE_SECOND
-
ONE_MINUTE
public static final long ONE_MINUTE
-
ONE_HOUR
public static final long ONE_HOUR
-
ONE_DAY
public static final long ONE_DAY
-
ONE_WEEK
public static final long ONE_WEEK
-
-
Method Detail
-
makeDate
public static java.util.Date makeDate(int year, int month, int day)
-
seconds
public static long seconds(double num)
-
minutes
public static long minutes(double num)
-
hours
public static long hours(double num)
-
days
public static long days(double num)
-
after
public static java.util.Date after(java.util.Date date, long timeMs)
-
before
public static java.util.Date before(java.util.Date date, long timeMs)
-
afterNow
public static java.util.Date afterNow(long timeMs)
-
beforeNow
public static java.util.Date beforeNow(long timeMs)
-
makeDate
public static java.util.Date makeDate(int year, int month, int day, java.util.Calendar calendar)
-
now
public static java.util.Date now()
-
today
public static java.util.Date today()
-
tomorrow
public static java.util.Date tomorrow()
-
yesterday
public static java.util.Date yesterday()
- Since:
- 6.5
-
after
public static java.util.Date after(java.util.Date date)
-
before
public static java.util.Date before(java.util.Date date)
-
makeDate
public static java.util.Date makeDate(int year, int month, int day, int hour, int minute, int second, java.lang.String timeZone)
-
isBeforeWithError
public static boolean isBeforeWithError(java.util.Date before, java.util.Date after, long allowedError)
-
daysBeforeNow
public static java.util.Date daysBeforeNow(int days)
-
daysAfterNow
public static java.util.Date daysAfterNow(int days)
-
daysBefore
public static java.util.Date daysBefore(java.util.Date date, int days)
-
daysAfter
public static java.util.Date daysAfter(java.util.Date date, int days)
-
truncateTime
public static java.util.Date truncateTime(java.util.Date dateAndTime)
-
truncateCalendar
public static void truncateCalendar(java.util.Calendar calendar)
-
truncateCalendarToEndOfDay
public static void truncateCalendarToEndOfDay(java.util.Calendar calendar)
-
isDayChanged
public static boolean isDayChanged(@NotNull java.util.Date date1, @NotNull java.util.Date date2)
-
formatInterval
public static java.lang.String formatInterval(java.util.Date from, java.util.Date to, @NotNull java.util.TimeZone tz)
-
formatDate
public static java.lang.String formatDate(java.util.Date date, java.lang.String format)
-
formatDate
@NotNull public static java.lang.String formatDate(@NotNull java.util.Date date, @NotNull java.lang.String pattern, @NotNull java.util.TimeZone tz)
Formats date according to specified timezone.- Parameters:
date
- datepattern
- patterntz
- timezone- Returns:
- formatted date in specified timezone
-
convertDateToFormalString
public static java.lang.String convertDateToFormalString(java.util.Date date)
Converts a date to a formal string like 19991231, independent of current locale.Nulls are converted to empty strings.
- Parameters:
date
- date to convert.- Returns:
- 8-digits string in form YYYYMMDD.
-
convertTimeToFormalString
public static java.lang.String convertTimeToFormalString(java.util.Date time)
Converts a timestamp to a formal string like 19991231.235959, independent of current locale.Nulls are converted to empty strings.
- Parameters:
time
- timestamp to convert.- Returns:
- 15-character string in form YYYYMMDD.HHMMSS.
-
isSameDay
public static boolean isSameDay(@NotNull java.util.Calendar cal1, @NotNull java.util.Calendar cal2)
Return true if two dates have the same day of the same year (but may have different time). We use Calendar because timezone issue is very important for the comparison.- Returns:
- see above
- Since:
- 6.0
-
daysBetween
public static int daysBetween(@NotNull java.util.Date startDate, @NotNull java.util.Date endDate)
Returns number of calendar days between two dates.- Parameters:
startDate
- start dateendDate
- end date, endDate must be after the startDate- Returns:
- number of days between specified dates
-
toStandardDate
@NotNull public static java.util.Date toStandardDate(@NotNull java.util.Date date)
Prevents using inheritors of java.util.Date (e.g. java.sql.Date, java.sql.Time, java.sql.Timestamp). This method should be used when you need to serialize date value (e.g. for XML-RPC).- Parameters:
date
- original date value- Returns:
- instance of exactly java.util.Date with the specified date value
-
getSortedTimeZones
public static java.util.TimeZone[] getSortedTimeZones()
-
formatNanos
@NotNull public static java.lang.String formatNanos(long nanos)
Returns string representation of nanoseconds in {seconds}s{millis}ms{micros}us{nanos}ns format. If some component is a zero it is not included.- Parameters:
nanos
- interval in nanoseconds- Returns:
- see above
-
formatTimeZoneLong
public static java.lang.String formatTimeZoneLong(@NotNull java.util.TimeZone tz)
-
formatTimeZoneID
public static java.lang.String formatTimeZoneID(@NotNull java.util.TimeZone tz)
-
getTimeZoneDescription
@NotNull public static java.lang.String getTimeZoneDescription(@Nullable java.lang.String timeZone)
-
formatTimeZoneUTCOffset
public static java.lang.String formatTimeZoneUTCOffset()
-
formatTimeZoneUTCOffset
public static java.lang.String formatTimeZoneUTCOffset(@NotNull java.util.TimeZone tz)
-
isValidTimeZoneID
public static boolean isValidTimeZoneID(@NotNull java.lang.String tzID)
-
translateFromTimeZone
public static java.util.Calendar translateFromTimeZone(java.util.Calendar initDate, java.util.TimeZone timeZone)
-
transletoToTimeZone
public static java.util.Calendar transletoToTimeZone(java.util.Calendar initDate, java.util.TimeZone timeZone)
-
copy
public static java.util.Calendar copy(java.util.Calendar to, java.util.Calendar from)
-
getSimpleFileDateFormatter
public static java.text.SimpleDateFormat getSimpleFileDateFormatter()
-
-