001    /**
002     * Implements the Cold Fusion Function gettimezoneinfo
003     */
004    package railo.runtime.functions.international;
005    
006    import java.util.Calendar;
007    import java.util.Date;
008    import java.util.TimeZone;
009    
010    import railo.commons.date.JREDateTimeUtil;
011    import railo.runtime.PageContext;
012    import railo.runtime.ext.function.Function;
013    import railo.runtime.type.Struct;
014    import railo.runtime.type.StructImpl;
015    
016    public final class GetTimeZoneInfo implements Function {
017    
018            private static String id="";
019            private static Calendar calendar;
020            
021            public synchronized static railo.runtime.type.Struct call(PageContext pc ) {
022                    
023            //Date date = ;
024            TimeZone timezone = pc.getTimeZone();
025                    
026           
027            synchronized(id) {
028                    if(!id.equals(timezone.getID())) {
029                            id=timezone.getID();
030                            calendar = JREDateTimeUtil.newInstance(timezone);
031                    }
032                else calendar.clear();
033                    
034                    calendar.setTime(new Date());
035            }
036            
037            int dstOffset=calendar.get(Calendar.DST_OFFSET);
038            int total = calendar.get(Calendar.ZONE_OFFSET) / 1000 + dstOffset / 1000;
039            total *= -1;
040            int j = total / 60;
041            int hour = total / 60 / 60;
042            int minutes = j % 60;
043            
044            Struct struct = new StructImpl();
045            struct.setEL("utcTotalOffset", new Double(total));
046            struct.setEL("utcHourOffset", new Double(hour));
047            struct.setEL("utcMinuteOffset", new Double(minutes));
048            struct.setEL("isDSTon", (dstOffset > 0)?Boolean.TRUE:Boolean.FALSE);
049            struct.setEL("id", timezone.getID());
050            
051           
052            return struct;
053                    
054            //return new StructImpl();
055            }
056    }