001 package railo.runtime.functions.displayFormatting; 002 003 import java.util.Locale; 004 import java.util.TimeZone; 005 006 import railo.commons.date.TimeZoneUtil; 007 import railo.runtime.PageContext; 008 import railo.runtime.engine.ThreadLocalPageContext; 009 import railo.runtime.exp.ExpressionException; 010 import railo.runtime.ext.function.Function; 011 import railo.runtime.op.Caster; 012 import railo.runtime.type.dt.DateTime; 013 014 /** 015 * Implements the Cold Fusion Function dateformat 016 */ 017 public final class TimeFormat implements Function { 018 019 /** 020 * @param pc 021 * @param object 022 * @return Formated Time Object as String 023 * @throws ExpressionException 024 */ 025 public static String call(PageContext pc , Object object) throws ExpressionException { 026 return _call(pc,object,"hh:mm tt",ThreadLocalPageContext.getTimeZone(pc)); 027 } 028 029 /** 030 * @param pc 031 * @param object 032 * @param mask Characters that show how CFML displays a date: 033 * @return Formated Time Object as String 034 * @throws ExpressionException 035 */ 036 public static String call(PageContext pc , Object object, String mask) throws ExpressionException { 037 return _call(pc,object,mask,ThreadLocalPageContext.getTimeZone(pc)); 038 } 039 040 public static String call(PageContext pc , Object object, String mask,String strTimezone) throws ExpressionException { 041 return _call(pc,object,mask, strTimezone==null?ThreadLocalPageContext.getTimeZone(pc):TimeZoneUtil.toTimeZone(strTimezone)); 042 } 043 044 private static String _call(PageContext pc , Object object, String mask,TimeZone tz) throws ExpressionException { 045 Locale locale=Locale.US;//:pc.getConfig().getLocale(); 046 DateTime datetime = Caster.toDate(object,true,tz,null); 047 if(datetime==null) { 048 if(object.toString().trim().length()==0) return ""; 049 throw new ExpressionException("can't convert value "+object+" to a datetime value"); 050 } 051 052 053 return new railo.runtime.format.TimeFormat(locale).format(datetime,mask,tz); 054 //return new railo.runtime.text.TimeFormat(locale).format(datetime,mask); 055 } 056 }