org.apache.velocity.tools.generic.ComparisonDateTool Java Examples

The following examples show how to use org.apache.velocity.tools.generic.ComparisonDateTool. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VelocityTemplateEngine.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Initializes Velocity engine
 */
private void init() {
       velocityEngine.setProperty(VelocityEngine.RESOURCE_LOADER, "class");
       velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
       setLogFile();

       DateTool dateTool = new DateTool();
       dateTool.configure(this.configMap);
       MathTool mathTool = new MathTool();
       NumberTool numberTool = new NumberTool();
       numberTool.configure(this.configMap);
       SortTool sortTool = new SortTool();
       
       defaultContext = new VelocityContext();
       defaultContext.put("dateTool", dateTool);
       defaultContext.put("dateComparisonTool", new ComparisonDateTool());
       defaultContext.put("mathTool", mathTool);
       defaultContext.put("numberTool", numberTool);
       defaultContext.put("sortTool", sortTool);
       // Following tools need VelocityTools version 2.0+
       //defaultContext.put("displayTool", new DisplayTool());
       //defaultContext.put("xmlTool", new XmlTool());
       
       try {
		velocityEngine.init();
	} catch (Exception e) {
		throw new VelocityException(e);
	}
}
 
Example #2
Source File: GenericToolsTests.java    From velocity-tools with Apache License 2.0 5 votes vote down vote up
public @Test void testComparisonDateTool() {
    ComparisonDateTool dateTool = (ComparisonDateTool)toolbox.get("date");
    assertNotNull(dateTool);
    Calendar date1 = new GregorianCalendar(2007,0,2);
    Calendar date2 = new GregorianCalendar(2007,1,15);
    /* test comparing */
    ComparisonDateTool.Comparison whenIs = dateTool.whenIs(date1, date2);
    assertEquals(0l, whenIs.getYears());
    assertEquals(1l, whenIs.getMonths());
    assertEquals(44l, whenIs.getDays());
    // the toolbox config says to skip months, so this should be in weeks
    assertStringEquals("6 weeks later", whenIs);
}
 
Example #3
Source File: GenericToolsTests.java    From velocity-tools with Apache License 2.0 5 votes vote down vote up
public @Test void testComparisonDateTool2() {
    ComparisonDateTool dateTool = (ComparisonDateTool)toolbox.get("date");
    assertNotNull(dateTool);
    Calendar date1 = new GregorianCalendar(1954,5,26);
    Calendar date2 = new GregorianCalendar(2019,5,20);
    /* test comparing */
    ComparisonDateTool.Comparison whenIs = dateTool.timespan(date1, date2);
    assertEquals(64l, whenIs.getYears());
    assertEquals(11l, whenIs.getMonths());
    assertEquals(25l, whenIs.getDays());
}
 
Example #4
Source File: ReportGenerator.java    From acmeair with Apache License 2.0 5 votes vote down vote up
private void generateHtmlfile(Map<String, Object> input) {	   
 try{
 	VelocityEngine ve = new VelocityEngine();
 	ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
 	ve.setProperty("classpath.resource.loader.class",ClasspathResourceLoader.class.getName());
 	ve.init();
 	Template template = ve.getTemplate("templates/acmeair-report.vtl");
 	VelocityContext context = new VelocityContext();
 	 	    
 	 
 	for(Map.Entry<String, Object> entry: input.entrySet()){
 		context.put(entry.getKey(), entry.getValue());
 	}
 	context.put("math", new MathTool());
 	context.put("number", new NumberTool());
 	context.put("date", new ComparisonDateTool());
 	
 	Writer file = new FileWriter(new File(searchingLocation
	+ System.getProperty("file.separator") + RESULTS_FILE));	    
 	template.merge( context, file );
 	file.flush();
 	file.close();
   
 }catch(Exception e){
 	e.printStackTrace();
 }
}
 
Example #5
Source File: DateTool.java    From document-management-software with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Calculates how many days are contained in a given amount of milliseconds
 * 
 * @param ms the milliseconds
 * 
 * @return number of days
 */
public long toDays(long ms) {
	return ComparisonDateTool.toDays(ms);
}
 
Example #6
Source File: DateTool.java    From document-management-software with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Calculates how many hours are contained in a given amount of milliseconds
 * 
 * @param ms the milliseconds
 * 
 * @return number of hours
 */
public long toHours(long ms) {
	return ComparisonDateTool.toHours(ms);
}
 
Example #7
Source File: DateTool.java    From document-management-software with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Calculates how many minutes are contained in a given amount of milliseconds
 * 
 * @param ms the milliseconds
 * 
 * @return number of minutes
 */
public long toMinutes(long ms) {
	return ComparisonDateTool.toMinutes(ms);
}
 
Example #8
Source File: DateTool.java    From document-management-software with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Calculates how many months are contained in a given amount of milliseconds
 * 
 * @param ms the milliseconds
 * 
 * @return number of months
 */
public long toMonths(long ms) {
	return ComparisonDateTool.toMonths(ms);
}
 
Example #9
Source File: DateTool.java    From document-management-software with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Calculates how many seconds are contained in a given amount of milliseconds
 * 
 * @param ms the milliseconds
 * 
 * @return number of seconds
 */
public long toSeconds(long ms) {
	return ComparisonDateTool.toSeconds(ms);
}
 
Example #10
Source File: DateTool.java    From document-management-software with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Calculates how many weeks are contained in a given amount of milliseconds
 * 
 * @param ms the milliseconds
 * 
 * @return number of weeks
 */
public long toWeeks(long ms) {
	return ComparisonDateTool.toWeeks(ms);
}
 
Example #11
Source File: DateTool.java    From document-management-software with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Calculates how many years are contained in a given amount of milliseconds
 * 
 * @param ms the milliseconds
 * 
 * @return number of years
 */
public long toYears(long ms) {
	return ComparisonDateTool.toYears(ms);
}