Package org.compiere.util
Class TimeUtil
- java.lang.Object
-
- org.compiere.util.TimeUtil
-
public class TimeUtil extends Object
Time Utilities- Version:
- $Id: TimeUtil.java,v 1.3 2006/07/30 00:54:35 jjanke Exp $
- Author:
- Jorg Janke
-
-
Field Summary
Fields Modifier and Type Field Description static String
TRUNC_DAY
Truncate Day - Dstatic String
TRUNC_MONTH
Truncate Month - MMstatic String
TRUNC_QUARTER
Truncate Quarter - Qstatic String
TRUNC_WEEK
Truncate Week - Wstatic String
TRUNC_YEAR
Truncate Year - Y
-
Constructor Summary
Constructors Constructor Description TimeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Timestamp
addDays(Timestamp day, int offset)
Return Day + offset (truncates)static Timestamp
addMinutess(Timestamp dateTime, int offset)
Return DateTime + offset in minutesstatic Timestamp
addMonths(Timestamp day, int offset)
[ ARHIPAC ] Return Day + offset (truncates)static Timestamp
addOnlyBusinessDays(Timestamp startDate, int nbDays, int clientID, String trxName)
Returns start date + nbDays which cannot be saturday or sunday or non business daysstatic 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, String trxName)
Returns number of non business days between 2 datesstatic Calendar
getCalendar(Timestamp date)
[ ARHIPAC ] Gets calendar instance of given datestatic Timestamp
getDay(int year, int month, int day)
Get earliest time of a day (truncate)static Timestamp
getDay(long time)
Get earliest time of a day (truncate)static Timestamp
getDay(Timestamp dayTime)
Get earliest time of a day (truncate)static Timestamp
getDayBorder(Timestamp dateTime, Timestamp timeSlot, boolean end)
Returns the day border by combining the date part from dateTime and time part form timeSlot.static int
getDaysBetween(Timestamp start, Timestamp end)
Calculate the number of days between start and end.static Timestamp
getDayTime(Timestamp day, Timestamp time)
Return the day and timestatic Timestamp
getMonthFirstDay(Timestamp day)
[ ARHIPAC ] Get first date in monthstatic Timestamp
getMonthLastDay(Timestamp day)
Get last date in monthstatic int
getMonthsBetween(Timestamp start, Timestamp end)
static Timestamp
getNextDay(Timestamp day)
Get earliest time of next daystatic Timestamp
getPreviousDay(Timestamp day)
Get earliest time of next daystatic Calendar
getToday()
Get today (truncate)static boolean
inRange(Timestamp start, Timestamp end, boolean OnMonday, boolean OnTuesday, boolean OnWednesday, boolean OnThursday, boolean OnFriday, boolean OnSaturday, boolean OnSunday)
Is start..end on one of the days ?static boolean
inRange(Timestamp start_1, Timestamp end_1, Timestamp start_2, Timestamp end_2)
Is the _1 in the Range of _2static boolean
isAllDay(Timestamp start, Timestamp end)
Is all daystatic boolean
isSameDay(Timestamp one, Timestamp two)
Is it the same daystatic boolean
isSameHour(Timestamp one, Timestamp two)
Is it the same hourstatic boolean
isValid(Timestamp validFrom, Timestamp validTo)
Is it valid today?static boolean
isValid(Timestamp validFrom, Timestamp validTo, Timestamp testDate)
Is it valid on test datestatic void
main(String[] args)
Teststatic Timestamp
max(Timestamp ts1, Timestamp ts2)
Max datestatic Timestamp
trunc(Timestamp dayTime, String trunc)
Get truncated day/time
-
-
-
Field Detail
-
TRUNC_DAY
public static final String TRUNC_DAY
Truncate Day - D- See Also:
- Constant Field Values
-
TRUNC_WEEK
public static final String TRUNC_WEEK
Truncate Week - W- See Also:
- Constant Field Values
-
TRUNC_MONTH
public static final String TRUNC_MONTH
Truncate Month - MM- See Also:
- Constant Field Values
-
TRUNC_QUARTER
public static final String TRUNC_QUARTER
Truncate Quarter - Q- See Also:
- Constant Field Values
-
TRUNC_YEAR
public static final String TRUNC_YEAR
Truncate Year - Y- See Also:
- Constant Field Values
-
-
Method Detail
-
getDay
public static Timestamp getDay(long time)
Get earliest time of a day (truncate)- Parameters:
time
- day and time- Returns:
- day with 00:00
-
getDay
public static Timestamp getDay(Timestamp dayTime)
Get earliest time of a day (truncate)- Parameters:
dayTime
- day and time- Returns:
- day with 00:00
-
getDay
public static Timestamp getDay(int year, int month, int day)
Get earliest time of a day (truncate)- 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
public static Calendar getToday()
Get today (truncate)- Returns:
- day with 00:00
-
getNextDay
public static Timestamp getNextDay(Timestamp day)
Get earliest time of next day- Parameters:
day
- day- Returns:
- next day with 00:00
-
getPreviousDay
public static Timestamp getPreviousDay(Timestamp day)
Get earliest time of next day- Parameters:
day
- day- Returns:
- next day with 00:00
-
getMonthLastDay
public static Timestamp getMonthLastDay(Timestamp day)
Get last date in month- Parameters:
day
- day- Returns:
- last day with 00:00
-
getDayTime
public static Timestamp getDayTime(Timestamp day, Timestamp time)
Return the day and time- Parameters:
day
- day parttime
- time part- Returns:
- 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/b.- 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 on 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
public static boolean isSameDay(Timestamp one, Timestamp two)
Is it the same day- Parameters:
one
- daytwo
- compared day- Returns:
- true if the same day
-
isSameHour
public static boolean isSameHour(Timestamp one, Timestamp two)
Is it the same hour- Parameters:
one
- day/timetwo
- compared day/time- Returns:
- true if the same day
-
isAllDay
public static boolean isAllDay(Timestamp start, Timestamp end)
Is all day- Parameters:
start
- start dateend
- end date- Returns:
- true if all day (00:00-00:00 next day)
-
getDaysBetween
public static int getDaysBetween(Timestamp start, Timestamp end)
Calculate the number of days between start and end.- Parameters:
start
- start dateend
- end date- Returns:
- number of days (0 = same)
-
addDays
public static Timestamp addDays(Timestamp day, int offset)
Return Day + offset (truncates)- Parameters:
day
- Dayoffset
- day offset- Returns:
- Day + offset at 00:00
-
addMinutess
public static Timestamp addMinutess(Timestamp dateTime, int offset)
Return DateTime + offset in minutes- Parameters:
dateTime
- Date and Timeoffset
- minute offset- Returns:
- dateTime + offset in minutes
-
formatElapsed
public static String formatElapsed(Timestamp start, Timestamp end)
Format Elapsed Time- Parameters:
start
- start time or null for nowend
- end time or null for now- Returns:
- formatted time string 1'23:59:59.999
-
formatElapsed
public static String formatElapsed(Timestamp start)
Format Elapsed Time until now- Parameters:
start
- start time- Returns:
- formatted time string 1'23:59:59.999
-
formatElapsed
public static String formatElapsed(long elapsedMS)
Format Elapsed Time- Parameters:
elapsedMS
- time in ms- Returns:
- formatted time string 1'23:59:59.999 - d'hh:mm:ss.xxx
-
isValid
public static boolean isValid(Timestamp validFrom, Timestamp validTo)
Is it valid today?- Parameters:
validFrom
- valid fromvalidTo
- valid to- Returns:
- true if walid
-
isValid
public static boolean isValid(Timestamp validFrom, Timestamp validTo, Timestamp testDate)
Is it valid on test date- Parameters:
validFrom
- valid fromvalidTo
- valid totestDate
- Date- Returns:
- true if walid
-
max
public static Timestamp max(Timestamp ts1, Timestamp ts2)
Max date- Parameters:
ts1
- p1ts2
- p2- Returns:
- max time
-
trunc
public static Timestamp trunc(Timestamp dayTime, String trunc)
Get truncated day/time- Parameters:
dayTime
- daytrunc
- how to truncate TRUNC_*- Returns:
- next day with 00:00
-
getDayBorder
public static Timestamp getDayBorder(Timestamp dateTime, Timestamp timeSlot, boolean end)
Returns the day border by combining the date part from dateTime and time part form timeSlot. If timeSlot is null, then first milli of the day will be used (if end == false) or last milli of the day (if end == true).- Parameters:
dateTime
-timeSlot
-end
-- Returns:
-
main
public static void main(String[] args)
Test- Parameters:
args
- ignored
-
getCalendar
public static Calendar getCalendar(Timestamp date)
[ ARHIPAC ] Gets calendar instance of given date- Parameters:
date
- calendar initialization date; if null, the current date is used- Returns:
- calendar author Teo Sarca, SC ARHIPAC SERVICE SRL
-
getMonthFirstDay
public static Timestamp getMonthFirstDay(Timestamp day)
[ 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
public static Timestamp addMonths(Timestamp day, int offset)
[ ARHIPAC ] Return Day + offset (truncates)- Parameters:
day
- Day; if null current time will be usedoffset
- months offset- Returns:
- Day + offset (time will be 00:00)
-
addOnlyBusinessDays
public static Timestamp addOnlyBusinessDays(Timestamp startDate, int nbDays, int clientID, String trxName)
Returns start date + nbDays which cannot be saturday or sunday or non business days
-
-