1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.util;
24
25 import java.util.MissingResourceException;
26 import java.util.TimeZone;
27
28 import de.bea.domingo.i18n.ResourceManager;
29 import de.bea.domingo.i18n.Resources;
30
31 /***
32 * Static utility methods for time zone operations and conversions.
33 *
34 * @author <a href="mailto:kriede@users.sourceforge.net">Kurt Riede </a>
35 */
36 public final class Timezones {
37
38 /*** Maps time zone strings to Lotus Notes format. */
39 private static final Resources TIME_ZONES = ResourceManager.getClassResources(Timezones.class).withFailOnError(true);
40
41 /*** Default time zone. */
42 public static final String DEFAULT = getLotusTimeZoneString(TimeZone.getDefault().getID());
43
44
45
46 /***
47 * Private default constructor to prevent instantiation.
48 */
49 private Timezones() {
50 }
51
52 /***
53 * Converts a Java time zone to a Lotus timezone string.
54 * if the given java time zone string is null, empry or unknown,
55 * the default lotus time zone string is returned (<tt>""</tt>).
56 *
57 * @param timeZone the time zone
58 * @return Lotus time zone string
59 * @throws NullPointerException if the given time zone string is null
60 * @throws IllegalArgumentException if the length of the given time zone string is zero
61 */
62 public static String getLotusTimeZoneString(final TimeZone timeZone) throws NullPointerException, IllegalArgumentException {
63 return getLotusTimeZoneString(timeZone.getID());
64 }
65
66 /***
67 * Converts a Java time zone string to a Lotus timezone string.
68 * if the given java time zone string is null, empry or unknown,
69 * the default lotus time zone string is returned (<tt>""</tt>).
70 *
71 * @param javaTimeZoneString the java time zone string
72 * @return Lotus time zone string
73 * @throws NullPointerException if the given time zone string is null
74 * @throws IllegalArgumentException if the given time zone string is empty or unknown
75 */
76 public static String getLotusTimeZoneString(final String javaTimeZoneString) throws NullPointerException,
77 IllegalArgumentException {
78 if (javaTimeZoneString == null) {
79 throw new NullPointerException("timezone must not be null");
80 }
81 if (javaTimeZoneString.length() == 0) {
82 throw new IllegalArgumentException("timezone must not be empty");
83 }
84 try {
85 return TIME_ZONES.getString(javaTimeZoneString);
86 } catch (MissingResourceException e) {
87 throw new IllegalArgumentException("unknown timezone: " + javaTimeZoneString);
88 }
89 }
90 }