001 /** 002 * Implements the Cold Fusion Function datepart 003 */ 004 package railo.runtime.functions.dateTime; 005 006 import railo.runtime.PageContext; 007 import railo.runtime.exp.ExpressionException; 008 import railo.runtime.ext.function.Function; 009 import railo.runtime.type.dt.DateTime; 010 011 public final class DatePart implements Function { 012 013 private static final long serialVersionUID = -4203375459570986511L; 014 015 public static double call(PageContext pc , String datepart, DateTime date) throws ExpressionException { 016 return call(pc, datepart, date, null); 017 } 018 019 public static double call(PageContext pc , String datepart, DateTime date,String strTimezone) throws ExpressionException { 020 datepart=datepart.toLowerCase(); 021 char first=datepart.length()==1?datepart.charAt(0):(char)0; 022 023 if(datepart.equals("yyyy")) return Year.call(pc,date,strTimezone); 024 else if(datepart.equals("ww")) return Week.call(pc,date,strTimezone); 025 else if(first=='w') return DayOfWeek.call(pc,date,strTimezone); 026 else if(first=='q') return Quarter.call(pc,date,strTimezone); 027 else if(first=='m') return Month.call(pc,date,strTimezone); 028 else if(first=='y') return DayOfYear.call(pc,date,strTimezone); 029 else if(first=='d') return Day.call(pc,date,strTimezone); 030 else if(first=='h') return Hour.call(pc,date,strTimezone); 031 else if(first=='n') return Minute.call(pc,date,strTimezone); 032 else if(first=='s') return Second.call(pc,date,strTimezone); 033 else if(first=='l') return MilliSecond.call(pc, date,strTimezone); 034 throw new ExpressionException("invalid datepart type ["+datepart+"] for function datePart"); 035 } 036 }