Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Panel
nameblue

Useful methods frequently used in the system concerning date, SQL and metadata handling.

What does this section cover?

Table of Contents

...

Date handling methods can be found in com.crm.framework.util.DateUtil class. 

Handling Java Dates

Expand
titleTruncate Date

truncate(

...

Date date) method returns the date rounded to the day with a time of 00:00:00:00. setEndOfDay(

...

1

Date date) method returns the date rounded to the day with a time of 23:59:59:999.

Code Block
titleExample
public DateRange getDateRange(Date fromDate, Date toDate){
	if (fromDate!=null && toDate!=null )
	{
		fromDate = DateUtil.truncate(fromDate);
		toDate = DateUtil.setEndOfDay(toDate);
		range = new DateRange(fromDate, toDate);
	}
		
	return range;
}
2
Expand
titleDifference between two dates

getDateDiff( int calculationUnit, Date d1, Date d2 ) method returns the difference of the two dates in the given calculation unit. 

Code Block
titleExample
public Boolean expired(Date fromDate, Date toDate, Integer daysValid){
	
	Integer numberOfDays = DateUtil.getDateDiff(Calendar.DAY_OF_YEAR, fromDate, toDate);
	
	if(numberOfDays>daysValid)
	{
		return true;
	}
		
	return false;
}
Expand
titleAdd period of time to date

 add(Date date, int timeValue,

...

UnitOfTime uot)

...

 method adds the given number(time value) of units to the given date.

Code Block
titleExample
public Boolean getCompletionDate(Date startDate, Integer timeValue, UnitOfTime uot){
	
	Date completionDate = DateUtil.add(startDate, timeValue, uot);
		
	return completionDate ;
}

Alternatively, any of the following methods can be used if the unit of time is known and not given. 

addYears(Date date, int numberOfYears) method adds the given number of years to the given date.

addMonths(Date date, int numberOfMonths) method adds the given number of months to the given date.

addWeeks(Date date, int numberOfWeeks) method adds the given number of weeks to the given date.

addDays(Date date, int numberOfDays)

...

 method adds the given number of days to the given date.

addHours(Date date, int numberOfHours) method adds the given number of hours to the given date.

addMinutes(Date date, int numberOfMinutes) method adds the given number

...

code

of minutesto the given date.

addSeconds(Date date, int numberOfSeconds) method adds the given number of seconds to the given date.

Handling SQL Dates

...

titleExample 3

...

 

 

SQL Handling Methods

 

Metadata Handling Methods

...