001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019/**
020 * Implements the CFML Function gettimezoneinfo
021 */
022package lucee.runtime.functions.international;
023
024import java.util.Calendar;
025import java.util.TimeZone;
026
027import lucee.commons.date.JREDateTimeUtil;
028import lucee.runtime.PageContext;
029import lucee.runtime.ext.function.Function;
030import lucee.runtime.type.Struct;
031import lucee.runtime.type.StructImpl;
032import lucee.runtime.type.util.KeyConstants;
033
034public final class GetTimeZoneInfo implements Function {
035
036        
037        public synchronized static lucee.runtime.type.Struct call(PageContext pc ) {
038                
039        //Date date = ;
040        TimeZone timezone = pc.getTimeZone();
041        Calendar c = JREDateTimeUtil.getThreadCalendar(timezone);
042        c.setTimeInMillis(System.currentTimeMillis());
043
044        int dstOffset=c.get(Calendar.DST_OFFSET);
045        int total = c.get(Calendar.ZONE_OFFSET) / 1000 + dstOffset / 1000;
046        total *= -1;
047        int j = total / 60;
048        int hour = total / 60 / 60;
049        int minutes = j % 60;
050        
051        Struct struct = new StructImpl();
052        struct.setEL("utcTotalOffset", new Double(total));
053        struct.setEL("utcHourOffset", new Double(hour));
054        struct.setEL("utcMinuteOffset", new Double(minutes));
055        struct.setEL("isDSTon", (dstOffset > 0)?Boolean.TRUE:Boolean.FALSE);
056        struct.setEL(KeyConstants._id, timezone.getID());
057        
058       
059        return struct;
060                
061        //return new StructImpl();
062        }
063}