Package org.compiere.util
Class TimeUtil
java.lang.Object
org.compiere.util.TimeUtil
Time and Date Utilities
- Version:
- $Id: TimeUtil.java,v 1.3 2006/07/30 00:54:35 jjanke Exp $
- Author:
- Jorg Janke, Teo Sarca, SC ARHIPAC SERVICE SRL
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Timestamp
Return Day + offset (truncate the time portion)static Timestamp
addMinutess
(Timestamp dateTime, int offset) Return DateTime + offset in minutesstatic Timestamp
[ ARHIPAC ] Return Day + offset (truncate the time portion)static Timestamp
addOnlyBusinessDays
(Timestamp startDate, int nbDays, int clientID, String trxName) Add n days to startDate, skipping non business day.static String
formatElapsed
(long elapsedMS) Format Elapsed Timestatic String
formatElapsed
(Timestamp start) Format Elapsed Time until nowstatic String
formatElapsed
(Timestamp start, Timestamp end) Format Elapsed Timestatic int
getBusinessDaysBetween
(Timestamp startDate, Timestamp endDate, int clientID, boolean includeEndDate, String trxName) Get number of business day between startDate and endDatestatic int
getBusinessDaysBetween
(Timestamp startDate, Timestamp endDate, int clientID, int countryID, boolean includeEndDate, String trxName) Get number of business day between startDate and endDatestatic int
getBusinessDaysBetween
(Timestamp startDate, Timestamp endDate, int clientID, int countryID, String trxName) Get number of business day between startDate and endDatestatic int
getBusinessDaysBetween
(Timestamp startDate, Timestamp endDate, int clientID, String trxName) Get number of business day between startDate and endDatestatic Calendar
getCalendar
(Timestamp date) [ ARHIPAC ] Gets calendar instance of given datestatic Timestamp
getDay
(int year, int month, int day) Create day only timestamp (setting all time values to zero)static Timestamp
getDay
(long time) Get day only timestamp from time (setting all the time values to zero).static Timestamp
Truncate timestamp to day only timestamp (setting all the time values to zero)static Timestamp
getDayBorder
(Timestamp dateTime, Timestamp timeSlot, boolean end) Returns timestamp by combining the date part from dateTime and time part form timeSlot.
If timeSlot is null, then first millisecond of the day will be used (if end == false) or last millisecond of the day (if end == true).static int
getDaysBetween
(Timestamp start, Timestamp end) Calculate the number of days between start and end.static Timestamp
getDayTime
(Timestamp day, Timestamp time) Create a new timestamp from the day and time part (millisecond is set to 0).static Timestamp
[ ARHIPAC ] Get first date in monthstatic Timestamp
getMonthLastDay
(Timestamp day) Get last date in month (truncate the time portion)static int
getMonthsBetween
(Timestamp start, Timestamp end) Get number of months between start and endstatic Timestamp
getNextDay
(Timestamp day) Get next day timestamp (truncate the time portion)static Timestamp
getPreviousDay
(Timestamp day) Get previous day timestamp (truncate the time portion)static Calendar
getToday()
Get today (truncate the time portion)static boolean
inRange
(Timestamp start, Timestamp end, boolean OnMonday, boolean OnTuesday, boolean OnWednesday, boolean OnThursday, boolean OnFriday, boolean OnSaturday, boolean OnSunday) Is start..end include one of the days ?static boolean
Is the _1 in the Range of _2static boolean
Is all daystatic boolean
Is it the same daystatic boolean
isSameHour
(Timestamp one, Timestamp two) Is it the same day and same hourstatic boolean
Is today a valid date ?static boolean
Is it valid on test datestatic Timestamp
Get the greater of ts1 and ts2static Timestamp
Get truncated timestamp (without time)
-
Field Details
-
TRUNC_DAY
Truncate Day - D- See Also:
-
TRUNC_WEEK
Truncate Week - W- See Also:
-
TRUNC_MONTH
Truncate Month - MM- See Also:
-
TRUNC_QUARTER
Truncate Quarter - Q- See Also:
-
TRUNC_YEAR
Truncate Year - Y- See Also:
-
-
Constructor Details
-
TimeUtil
public TimeUtil()
-
-
Method Details
-
getDay
Get day only timestamp from time (setting all the time values to zero).- Parameters:
time
- timestamp in millisecond. 0 for current time.- Returns:
- day with 00:00
-
getDay
Truncate timestamp to day only timestamp (setting all the time values to zero)- Parameters:
dayTime
- day and time- Returns:
- day with 00:00
-
getDay
Create day only timestamp (setting all time values to zero)- Parameters:
year
- year (if two digits: < 50 is 2000; > 50 is 1900)month
- month 1..12day
- day 1..31- Returns:
- timestamp ** not too reliable
-
getToday
Get today (truncate the time portion)- Returns:
- day with 00:00
-
getNextDay
Get next day timestamp (truncate the time portion)- Parameters:
day
- day- Returns:
- next day with 00:00
-
getPreviousDay
Get previous day timestamp (truncate the time portion)- Parameters:
day
- day- Returns:
- previous day with 00:00
-
getMonthLastDay
Get last date in month (truncate the time portion)- Parameters:
day
- day- Returns:
- last day of month with 00:00
-
getDayTime
Create a new timestamp from the day and time part (millisecond is set to 0).- Parameters:
day
- day parttime
- time part- Returns:
- new timestamp from day + time
-
inRange
public static boolean inRange(Timestamp start_1, Timestamp end_1, Timestamp start_2, Timestamp end_2) Is the _1 in the Range of _2Time_1 +--x--+ Time_2 +a+ +---b---+ +c+
The function returns true for b and false for a/c.- Parameters:
start_1
- start (1)end_1
- not included end (1)start_2
- start (2)end_2
- not included (2)- Returns:
- true if in range
-
inRange
public static boolean inRange(Timestamp start, Timestamp end, boolean OnMonday, boolean OnTuesday, boolean OnWednesday, boolean OnThursday, boolean OnFriday, boolean OnSaturday, boolean OnSunday) Is start..end include one of the days ?- Parameters:
start
- start dayend
- end day (not including)OnMonday
- true if OKOnTuesday
- true if OKOnWednesday
- true if OKOnThursday
- true if OKOnFriday
- true if OKOnSaturday
- true if OKOnSunday
- true if OK- Returns:
- true if on one of the days
-
isSameDay
Is it the same day- Parameters:
one
- daytwo
- compared day- Returns:
- true if one and two is same day
-
isSameHour
Is it the same day and same hour- Parameters:
one
- day/timetwo
- compared day/time- Returns:
- true if one and two is same day and same hour
-
isAllDay
Is all day- Parameters:
start
- start dateend
- end date- Returns:
- true if all day (00:00-00:00 next day)
-
getDaysBetween
Calculate the number of days between start and end.- Parameters:
start
- start dateend
- end date- Returns:
- number of days (0 = same)
-
addDays
Return Day + offset (truncate the time portion)- Parameters:
day
- Dayoffset
- day offset- Returns:
- Day + offset at 00:00
-
addMinutess
Return DateTime + offset in minutes- Parameters:
dateTime
- Date and Timeoffset
- minute offset- Returns:
- dateTime + offset in minutes
-
formatElapsed
Format Elapsed Time- Parameters:
start
- start time or null for nowend
- end time or null for now- Returns:
- formatted elapsed time string 1'23:59:59.999
-
formatElapsed
Format Elapsed Time until now- Parameters:
start
- start time- Returns:
- formatted elapsed time string 1'23:59:59.999
-
formatElapsed
Format Elapsed Time- Parameters:
elapsedMS
- elapsed time in ms- Returns:
- formatted elapsed time string 1'23:59:59.999 - d'hh:mm:ss.xxx
-
isValid
Is today a valid date ?- Parameters:
validFrom
- valid fromvalidTo
- valid to- Returns:
- true if today is between validFrom and validTo
-
isValid
Is it valid on test date- Parameters:
validFrom
- valid fromvalidTo
- valid totestDate
- Date- Returns:
- true if testDate is null or between validFrom and validTo
-
max
Get the greater of ts1 and ts2- Parameters:
ts1
- p1ts2
- p2- Returns:
- the greater of ts1 and ts2
-
trunc
Get truncated timestamp (without time)- Parameters:
dayTime
- daytrunc
-TRUNC_DAY
,TRUNC_WEEK
,TRUNC_MONTH
,TRUNC_QUARTER
orTRUNC_YEAR
- Returns:
- truncated timestamp (without time)
-
getDayBorder
Returns timestamp by combining the date part from dateTime and time part form timeSlot.
If timeSlot is null, then first millisecond of the day will be used (if end == false) or last millisecond of the day (if end == true).- Parameters:
dateTime
-timeSlot
-end
-- Returns:
Timestamp
-
getCalendar
[ ARHIPAC ] Gets calendar instance of given date- Parameters:
date
- calendar initialization date; if null, the current date is used- Returns:
- calendar
-
getMonthFirstDay
[ ARHIPAC ] Get first date in month- Parameters:
day
- day; if null current time will be used- Returns:
- first day of the month (time will be 00:00)
-
addMonths
[ ARHIPAC ] Return Day + offset (truncate the time portion)- Parameters:
day
- Day; if null current time will be usedoffset
- months offset- Returns:
- Day + offset (time will be 00:00)
-
getMonthsBetween
Get number of months between start and end- Parameters:
start
-end
-- Returns:
- number of months between start and end
-
addOnlyBusinessDays
public static Timestamp addOnlyBusinessDays(Timestamp startDate, int nbDays, int clientID, String trxName) Add n days to startDate, skipping non business day.- Parameters:
startDate
-nbDays
- number of daysclientID
- AD_Client_IDtrxName
-- Returns:
- start date + nbDays which cannot be saturday or sunday or non business days
-
getBusinessDaysBetween
public static int getBusinessDaysBetween(Timestamp startDate, Timestamp endDate, int clientID, String trxName) Get number of business day between startDate and endDate- Parameters:
startDate
-endDate
- (not inclusive)clientID
-trxName
-- Returns:
- number of business days between 2 dates for the country based on current default country
-
getBusinessDaysBetween
public static int getBusinessDaysBetween(Timestamp startDate, Timestamp endDate, int clientID, boolean includeEndDate, String trxName) Get number of business day between startDate and endDate- Parameters:
startDate
-endDate
-clientID
-includeEndDate
-trxName
-- Returns:
- number of business days between 2 dates for the country based on current default country
-
getBusinessDaysBetween
public static int getBusinessDaysBetween(Timestamp startDate, Timestamp endDate, int clientID, int countryID, String trxName) Get number of business day between startDate and endDate- Parameters:
startDate
-endDate
- (not inclusive)clientID
-countryID
-trxName
-- Returns:
- number of business days between 2 dates for a specified country
-
getBusinessDaysBetween
public static int getBusinessDaysBetween(Timestamp startDate, Timestamp endDate, int clientID, int countryID, boolean includeEndDate, String trxName) Get number of business day between startDate and endDate- Parameters:
startDate
-endDate
-clientID
-countryID
-includeEndDate
-trxName
-- Returns:
- number of business days between 2 dates for a specified country, with ability to include the end date in the count
-