001    /**
002     * Implements the CFML Function dayofweek
003     */
004    package railo.runtime.functions.international;
005    
006    import java.util.Locale;
007    import java.util.TimeZone;
008    
009    import railo.commons.date.DateTimeUtil;
010    import railo.commons.date.TimeZoneUtil;
011    import railo.runtime.PageContext;
012    import railo.runtime.exp.ExpressionException;
013    import railo.runtime.exp.PageException;
014    import railo.runtime.functions.BIF;
015    import railo.runtime.i18n.LocaleFactory;
016    import railo.runtime.op.Caster;
017    import railo.runtime.type.dt.DateTime;
018    
019    public final class LSDayOfWeek extends BIF {
020            
021            private static final long serialVersionUID = -9002250869621547151L;
022    
023            public static double call(PageContext pc , DateTime date) {
024                    return _call(pc, date, pc.getLocale(),pc.getTimeZone());
025            }
026            
027            public static double call(PageContext pc , DateTime date, String strLocale) throws ExpressionException {
028                    return _call(pc, date, LocaleFactory.getLocale(strLocale),pc.getTimeZone());
029            }
030            
031            public static double call(PageContext pc , DateTime date, String strLocale, String strTimezone) throws ExpressionException {
032                    return _call(pc, date, 
033                                    strLocale==null?pc.getLocale():LocaleFactory.getLocale(strLocale), 
034                                    strTimezone==null?pc.getTimeZone():TimeZoneUtil.toTimeZone(strTimezone));
035            }
036            
037            @Override
038            public Object invoke(PageContext pc, Object[] args) throws PageException {
039                    if(args.length==1)return call(pc,Caster.toDatetime(args[0],pc.getTimeZone()));
040                    if(args.length==2)return call(pc,Caster.toDatetime(args[0],pc.getTimeZone()),Caster.toString(args[1]));
041                    return call(pc,Caster.toDatetime(args[0],pc.getTimeZone()),Caster.toString(args[1]),Caster.toString(args[2]));
042            }
043    
044            private static double _call(PageContext pc , DateTime date,Locale locale,TimeZone tz) {
045                    return DateTimeUtil.getInstance().getDayOfWeek(locale,tz, date);
046            }
047    }