001 /** 002 * Implements the CFML Function firstdayofmonth 003 */ 004 package railo.runtime.functions.dateTime; 005 006 import java.util.Calendar; 007 import java.util.TimeZone; 008 009 import railo.commons.date.JREDateTimeUtil; 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 FirstDayOfMonth extends BIF { 019 020 private static final long serialVersionUID = 2771139908016254661L; 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 //synchronized (calendar) { 032 Calendar calendar=JREDateTimeUtil.getCalendar(); 033 calendar.clear(); 034 calendar.setTimeZone(tz); 035 calendar.setTime(date); 036 calendar.set(Calendar.DATE,1); 037 return calendar.get(Calendar.DAY_OF_YEAR); 038 //} 039 } 040 041 @Override 042 public Object invoke(PageContext pc, Object[] args) throws PageException { 043 if(args.length==1)return call(pc,Caster.toDatetime(args[0],pc.getTimeZone())); 044 return call(pc,Caster.toDatetime(args[0],pc.getTimeZone()),Caster.toString(args[1])); 045 } 046 }