001    /**
002     * Implements the CFML Function dayofweek
003     */
004    package railo.runtime.functions.dateTime;
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.op.Caster;
016    import railo.runtime.type.dt.DateTime;
017    
018    public final class DayOfWeek extends BIF {
019    
020            private static final long serialVersionUID = 8025414014490122478L;
021    
022            public static double call(PageContext pc , DateTime date) {
023                    return _call(pc, date, pc.getTimeZone());
024            }
025            
026            public static double call(PageContext pc , DateTime date, String strTimezone) throws ExpressionException {
027                    return _call(pc, date, strTimezone==null?pc.getTimeZone():TimeZoneUtil.toTimeZone(strTimezone));
028            }
029    
030            private static double _call(PageContext pc , DateTime date,TimeZone tz) {
031                    return DateTimeUtil.getInstance().getDayOfWeek(Locale.US,tz, date);
032            }
033            
034            @Override
035            public Object invoke(PageContext pc, Object[] args) throws PageException {
036                    if(args.length==1)return call(pc,Caster.toDatetime(args[0],pc.getTimeZone()));
037                    return call(pc,Caster.toDatetime(args[0],pc.getTimeZone()),Caster.toString(args[1]));
038            }
039    }