001    /**
002     * Implements the CFML Function quarter
003     */
004    package railo.runtime.functions.dateTime;
005    
006    import java.util.TimeZone;
007    
008    import railo.commons.date.DateTimeUtil;
009    import railo.commons.date.TimeZoneUtil;
010    import railo.runtime.PageContext;
011    import railo.runtime.exp.ExpressionException;
012    import railo.runtime.exp.PageException;
013    import railo.runtime.ext.function.Function;
014    import railo.runtime.functions.BIF;
015    import railo.runtime.op.Caster;
016    import railo.runtime.type.dt.DateTime;
017    
018    public final class Quarter extends BIF {
019    
020            private static final long serialVersionUID = 297634314192413459L;
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().getMonth(tz, date)-1)/3+1;
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    }