Package jetbrains.buildServer.util
Class Dates
- java.lang.Object
-
- jetbrains.buildServer.util.Dates
-
public class Dates extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static int
APR
static int
AUG
static int
DEC
static 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 Date
after(Date date)
static Date
after(Date date, long timeMs)
static Date
afterNow(long timeMs)
static Date
before(Date date)
static Date
before(Date date, long timeMs)
static Date
beforeNow(long timeMs)
static String
convertDateToFormalString(Date date)
Converts a date to a formal string like 19991231, independent of current locale.static String
convertTimeToFormalString(Date time)
Converts a timestamp to a formal string like 19991231.235959, independent of current locale.static Calendar
copy(Calendar to, Calendar from)
static long
days(double num)
static Date
daysAfter(Date date, int days)
static Date
daysAfterNow(int days)
static Date
daysBefore(Date date, int days)
static Date
daysBeforeNow(int days)
static int
daysBetween(Date startDate, Date endDate)
Returns number of calendar days between two dates.static String
formatDate(Date date, String format)
static String
formatDate(Date date, String pattern, TimeZone tz)
Formats date according to specified timezone.static String
formatInterval(Date from, Date to, TimeZone tz)
static String
formatNanos(long nanos)
Returns string representation of nanoseconds in {seconds}s{millis}ms{micros}us{nanos}ns format.static String
formatTimeZoneID(TimeZone tz)
static String
formatTimeZoneLong(TimeZone tz)
static String
formatTimeZoneUTCOffset()
static String
formatTimeZoneUTCOffset(TimeZone tz)
static SimpleDateFormat
getSimpleFileDateFormatter()
static TimeZone[]
getSortedTimeZones()
static String
getTimeZoneDescription(String timeZone)
static long
hours(double num)
static boolean
isBeforeWithError(Date before, Date after, long allowedError)
static boolean
isDayChanged(Date date1, Date date2)
static boolean
isSameDay(Calendar cal1, Calendar cal2)
Return true if two dates have the same day of the same year (but may have different time).static boolean
isValidTimeZoneID(String tzID)
static Date
makeDate(int year, int month, int day)
static Date
makeDate(int year, int month, int day, int hour, int minute, int second, String timeZone)
static Date
makeDate(int year, int month, int day, Calendar calendar)
static long
minutes(double num)
static Date
now()
static long
seconds(double num)
static Date
today()
static Date
tomorrow()
static Date
toStandardDate(Date date)
Prevents using inheritors of java.util.Date (e.g.static Calendar
translateFromTimeZone(Calendar initDate, TimeZone timeZone)
static Calendar
transletoToTimeZone(Calendar initDate, TimeZone timeZone)
static void
truncateCalendar(Calendar calendar)
static void
truncateCalendarToEndOfDay(Calendar calendar)
static Date
truncateTime(Date dateAndTime)
static Date
yesterday()
-
-
-
Field Detail
-
DEFAULT_DATE_FORMAT
public static final 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 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)
-
afterNow
public static Date afterNow(long timeMs)
-
beforeNow
public static Date beforeNow(long timeMs)
-
now
public static Date now()
-
today
public static Date today()
-
tomorrow
public static Date tomorrow()
-
yesterday
public static Date yesterday()
- Since:
- 6.5
-
makeDate
public static Date makeDate(int year, int month, int day, int hour, int minute, int second, String timeZone)
-
isBeforeWithError
public static boolean isBeforeWithError(Date before, Date after, long allowedError)
-
daysBeforeNow
public static Date daysBeforeNow(int days)
-
daysAfterNow
public static Date daysAfterNow(int days)
-
truncateCalendar
public static void truncateCalendar(Calendar calendar)
-
truncateCalendarToEndOfDay
public static void truncateCalendarToEndOfDay(Calendar calendar)
-
formatDate
@NotNull public static String formatDate(@NotNull Date date, @NotNull String pattern, @NotNull TimeZone tz)
Formats date according to specified timezone.- Parameters:
date
- datepattern
- patterntz
- timezone- Returns:
- formatted date in specified timezone
-
convertDateToFormalString
public static String convertDateToFormalString(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 String convertTimeToFormalString(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 Calendar cal1, @NotNull 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 Date startDate, @NotNull 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 Date toStandardDate(@NotNull 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 TimeZone[] getSortedTimeZones()
-
formatNanos
@NotNull public static 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
-
getTimeZoneDescription
@NotNull public static String getTimeZoneDescription(@Nullable String timeZone)
-
formatTimeZoneUTCOffset
public static String formatTimeZoneUTCOffset()
-
isValidTimeZoneID
public static boolean isValidTimeZoneID(@NotNull String tzID)
-
translateFromTimeZone
public static Calendar translateFromTimeZone(Calendar initDate, TimeZone timeZone)
-
transletoToTimeZone
public static Calendar transletoToTimeZone(Calendar initDate, TimeZone timeZone)
-
getSimpleFileDateFormatter
public static SimpleDateFormat getSimpleFileDateFormatter()
-
-