|
1 /** |
|
2 * Copyright (c) 2012, Ben Fortuna |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions |
|
7 * are met: |
|
8 * |
|
9 * o Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * o Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * o Neither the name of Ben Fortuna nor the names of any other contributors |
|
17 * may be used to endorse or promote products derived from this software |
|
18 * without specific prior written permission. |
|
19 * |
|
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
31 */ |
|
32 package net.fortuna.ical4j.util; |
|
33 |
|
34 import java.util.TimeZone; |
|
35 |
|
36 /** |
|
37 * $Id$ [5/07/2004] |
|
38 * |
|
39 * Utility methods relevant to Java timezones. |
|
40 * |
|
41 * @author Ben Fortuna |
|
42 */ |
|
43 public final class TimeZones { |
|
44 |
|
45 /** |
|
46 * The timezone identifier for UTC time. |
|
47 */ |
|
48 public static final String UTC_ID = "Etc/UTC"; |
|
49 |
|
50 /** |
|
51 * The timezone identifier for UTC time in the IBM JVM. |
|
52 */ |
|
53 public static final String IBM_UTC_ID = "GMT"; |
|
54 |
|
55 /** |
|
56 * The timezone identifier for GMT time. |
|
57 */ |
|
58 public static final String GMT_ID = "Etc/GMT"; |
|
59 |
|
60 private static final TimeZone UTC_TIMEZONE; |
|
61 static { |
|
62 UTC_TIMEZONE = TimeZone.getTimeZone(UTC_ID); |
|
63 } |
|
64 |
|
65 /** |
|
66 * Constructor made private to enforce static nature. |
|
67 */ |
|
68 private TimeZones() { |
|
69 } |
|
70 |
|
71 /** |
|
72 * Indicates whether the specified timezone is equivalent to |
|
73 * UTC time. |
|
74 * @param timezone a timezone instance |
|
75 * @return true if the timezone is UTC time, otherwise false |
|
76 */ |
|
77 public static boolean isUtc(final TimeZone timezone) { |
|
78 // return timezone.hasSameRules(TimeZone.getTimeZone(UTC_ID)); |
|
79 // return timezone.getRawOffset() == 0; |
|
80 return UTC_ID.equals(timezone.getID()) |
|
81 || IBM_UTC_ID.equals(timezone.getID()); |
|
82 } |
|
83 |
|
84 /** |
|
85 * Although timezones are not really applicable to DATE instances in iCalendar, the implementation |
|
86 * in iCal4j requires the use of a timezone. Dates in iCal4j may be either "floating", in that they |
|
87 * use the default Java timezone, or alternatively will use UTC (this is the default). |
|
88 * |
|
89 * The use of floating dates may be configured by specifying the following as a system property or in |
|
90 * a file called "ical4j.properties" in the classpath: |
|
91 * |
|
92 * <pre>net.fortuna.ical4j.timezone.date.floating=true</pre> |
|
93 * |
|
94 * @return the timezone used for date instances |
|
95 */ |
|
96 public static TimeZone getDateTimeZone() { |
|
97 if ("true".equals(Configurator.getProperty("net.fortuna.ical4j.timezone.date.floating"))) { |
|
98 return TimeZone.getDefault(); |
|
99 } |
|
100 return getUtcTimeZone(); |
|
101 } |
|
102 |
|
103 /** |
|
104 * Get the UTC Timezone. |
|
105 */ |
|
106 public static TimeZone getUtcTimeZone() { |
|
107 return UTC_TIMEZONE; |
|
108 } |
|
109 } |