001    /**
002     * Implements the Cold Fusion Function lsisdate
003     */
004    package railo.runtime.functions.international;
005    
006    import java.util.Date;
007    import java.util.Locale;
008    import java.util.TimeZone;
009    
010    import railo.commons.date.TimeZoneUtil;
011    import railo.runtime.PageContext;
012    import railo.runtime.exp.ExpressionException;
013    import railo.runtime.ext.function.Function;
014    import railo.runtime.i18n.LocaleFactory;
015    import railo.runtime.op.Decision;
016    
017    public final class LSIsDate implements Function {
018    
019            private static final long serialVersionUID = -8517171925554806088L;
020    
021    
022            public static boolean call(PageContext pc , Object object) {
023                    return call(pc, object, pc.getLocale(),pc.getTimeZone());
024            }
025    
026            public static boolean call(PageContext pc , Object object,String strLocale) throws ExpressionException {
027                    return call(pc, object, LocaleFactory.getLocale(strLocale),pc.getTimeZone());
028            }
029            public static boolean call(PageContext pc , Object object,String strLocale,String strTimezone) throws ExpressionException {
030                    return call(pc, object, 
031                                    strLocale==null?pc.getLocale():LocaleFactory.getLocale(strLocale),
032                                    strTimezone==null?pc.getTimeZone():TimeZoneUtil.toTimeZone(strTimezone));
033            }
034            
035            
036            private static boolean call(PageContext pc  , Object object,Locale locale,TimeZone tz) {
037                    if(object instanceof Date) return true;
038                    else if(object instanceof String) {
039                        String str=object.toString();
040                        if(str.length()<2) return false;
041                        //print.out(Caster.toDateTime(locale,str,pc.getTimeZone(),null));
042                            return Decision.isDate(str,locale,tz,locale.equals(Locale.US));
043                            //return Caster.toDateTime(locale,str,pc.getTimeZone(),null)!=null;
044                    }
045                    return false;
046            }
047            
048    }