michael@0: /** michael@0: * Copyright (c) 2012, Ben Fortuna michael@0: * All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * michael@0: * o Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * michael@0: * o Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * michael@0: * o Neither the name of Ben Fortuna nor the names of any other contributors michael@0: * may be used to endorse or promote products derived from this software michael@0: * without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR michael@0: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, michael@0: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, michael@0: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR michael@0: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF michael@0: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING michael@0: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS michael@0: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: package net.fortuna.ical4j.util; michael@0: michael@0: import java.util.TimeZone; michael@0: michael@0: /** michael@0: * $Id$ [5/07/2004] michael@0: * michael@0: * Utility methods relevant to Java timezones. michael@0: * michael@0: * @author Ben Fortuna michael@0: */ michael@0: public final class TimeZones { michael@0: michael@0: /** michael@0: * The timezone identifier for UTC time. michael@0: */ michael@0: public static final String UTC_ID = "Etc/UTC"; michael@0: michael@0: /** michael@0: * The timezone identifier for UTC time in the IBM JVM. michael@0: */ michael@0: public static final String IBM_UTC_ID = "GMT"; michael@0: michael@0: /** michael@0: * The timezone identifier for GMT time. michael@0: */ michael@0: public static final String GMT_ID = "Etc/GMT"; michael@0: michael@0: private static final TimeZone UTC_TIMEZONE; michael@0: static { michael@0: UTC_TIMEZONE = TimeZone.getTimeZone(UTC_ID); michael@0: } michael@0: michael@0: /** michael@0: * Constructor made private to enforce static nature. michael@0: */ michael@0: private TimeZones() { michael@0: } michael@0: michael@0: /** michael@0: * Indicates whether the specified timezone is equivalent to michael@0: * UTC time. michael@0: * @param timezone a timezone instance michael@0: * @return true if the timezone is UTC time, otherwise false michael@0: */ michael@0: public static boolean isUtc(final TimeZone timezone) { michael@0: // return timezone.hasSameRules(TimeZone.getTimeZone(UTC_ID)); michael@0: // return timezone.getRawOffset() == 0; michael@0: return UTC_ID.equals(timezone.getID()) michael@0: || IBM_UTC_ID.equals(timezone.getID()); michael@0: } michael@0: michael@0: /** michael@0: * Although timezones are not really applicable to DATE instances in iCalendar, the implementation michael@0: * in iCal4j requires the use of a timezone. Dates in iCal4j may be either "floating", in that they michael@0: * use the default Java timezone, or alternatively will use UTC (this is the default). michael@0: * michael@0: * The use of floating dates may be configured by specifying the following as a system property or in michael@0: * a file called "ical4j.properties" in the classpath: michael@0: * michael@0: *
net.fortuna.ical4j.timezone.date.floating=truemichael@0: * michael@0: * @return the timezone used for date instances michael@0: */ michael@0: public static TimeZone getDateTimeZone() { michael@0: if ("true".equals(Configurator.getProperty("net.fortuna.ical4j.timezone.date.floating"))) { michael@0: return TimeZone.getDefault(); michael@0: } michael@0: return getUtcTimeZone(); michael@0: } michael@0: michael@0: /** michael@0: * Get the UTC Timezone. michael@0: */ michael@0: public static TimeZone getUtcTimeZone() { michael@0: return UTC_TIMEZONE; michael@0: } michael@0: }