001 /** 002 * Implements the Cold Fusion Function dayofweekasstring 003 */ 004 package railo.runtime.functions.string; 005 006 import java.util.Date; 007 import java.util.Locale; 008 009 import railo.commons.date.TimeZoneConstants; 010 import railo.commons.i18n.DateFormatPool; 011 import railo.runtime.PageContext; 012 import railo.runtime.exp.ExpressionException; 013 import railo.runtime.exp.FunctionException; 014 import railo.runtime.ext.function.Function; 015 import railo.runtime.i18n.LocaleFactory; 016 017 public final class DayOfWeekAsString implements Function { 018 private static final int DAY=1000*60*60*24; 019 020 021 private static Date[] dates=new Date[]{ 022 new Date(0+(3*DAY)), 023 new Date(0+(4*DAY)), 024 new Date(0+(5*DAY)), 025 new Date(0+(6*DAY)), 026 new Date(0), 027 new Date(0+(1*DAY)), 028 new Date(0+(2*DAY)) 029 }; 030 031 public static String call(PageContext pc , double dow) throws ExpressionException { 032 return call(pc,dow, pc.getLocale(),true); 033 } 034 public static String call(PageContext pc , double dow, String strLocale) throws ExpressionException { 035 return call(pc,dow, strLocale==null?pc.getLocale():LocaleFactory.getLocale(strLocale),true); 036 } 037 protected static String call(PageContext pc , double dow, Locale locale,boolean _long) throws ExpressionException { 038 039 int dayOfWeek=(int)dow; 040 if(dayOfWeek>=1 && dayOfWeek<=7) { 041 return DateFormatPool.format(locale,TimeZoneConstants.GMT0,_long?"EEEE":"EEE",dates[dayOfWeek-1]); 042 } 043 throw new FunctionException( 044 pc, 045 _long?"DayOfWeekAsString":"DayOfWeekShortAsString", 046 1,"dayOfWeek", 047 "must be between 1 and 7 now ["+dayOfWeek+"]"); 048 //throw new ExpressionException("invalid dayOfWeek definition in function DayOfWeekAsString, must be between 1 and 7 now ["+dayOfWeek+"]"); 049 } 050 }