Mercurial > projects > dwt2
comparison base/src/java/mangoicu/UTimeZone.d @ 27:1bf55a6eb092
Renamed java tree to base
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 21 Mar 2009 11:33:57 +0100 |
parents | java/src/java/mangoicu/UTimeZone.d@9b96950f2c3c |
children |
comparison
equal
deleted
inserted
replaced
26:f589fc20a5f9 | 27:1bf55a6eb092 |
---|---|
1 /******************************************************************************* | |
2 | |
3 @file UTimeZone.d | |
4 | |
5 Copyright (c) 2004 Kris Bell | |
6 | |
7 This software is provided 'as-is', without any express or implied | |
8 warranty. In no event will the authors be held liable for damages | |
9 of any kind arising from the use of this software. | |
10 | |
11 Permission is hereby granted to anyone to use this software for any | |
12 purpose, including commercial applications, and to alter it and/or | |
13 redistribute it freely, subject to the following restrictions: | |
14 | |
15 1. The origin of this software must not be misrepresented; you must | |
16 not claim that you wrote the original software. If you use this | |
17 software in a product, an acknowledgment within documentation of | |
18 said product would be appreciated but is not required. | |
19 | |
20 2. Altered source versions must be plainly marked as such, and must | |
21 not be misrepresented as being the original software. | |
22 | |
23 3. This notice may not be removed or altered from any distribution | |
24 of the source. | |
25 | |
26 4. Derivative works are permitted, but they must carry this notice | |
27 in full and credit the original source. | |
28 | |
29 | |
30 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
31 | |
32 | |
33 @version Initial version, November 2004 | |
34 @author Kris | |
35 | |
36 Note that this package and documentation is built around the ICU | |
37 project (http://oss.software.ibm.com/icu/). Below is the license | |
38 statement as specified by that software: | |
39 | |
40 | |
41 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
42 | |
43 | |
44 ICU License - ICU 1.8.1 and later | |
45 | |
46 COPYRIGHT AND PERMISSION NOTICE | |
47 | |
48 Copyright (c) 1995-2003 International Business Machines Corporation and | |
49 others. | |
50 | |
51 All rights reserved. | |
52 | |
53 Permission is hereby granted, free of charge, to any person obtaining a | |
54 copy of this software and associated documentation files (the | |
55 "Software"), to deal in the Software without restriction, including | |
56 without limitation the rights to use, copy, modify, merge, publish, | |
57 distribute, and/or sell copies of the Software, and to permit persons | |
58 to whom the Software is furnished to do so, provided that the above | |
59 copyright notice(s) and this permission notice appear in all copies of | |
60 the Software and that both the above copyright notice(s) and this | |
61 permission notice appear in supporting documentation. | |
62 | |
63 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
64 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
65 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT | |
66 OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
67 HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL | |
68 INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING | |
69 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, | |
70 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | |
71 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
72 | |
73 Except as contained in this notice, the name of a copyright holder | |
74 shall not be used in advertising or otherwise to promote the sale, use | |
75 or other dealings in this Software without prior written authorization | |
76 of the copyright holder. | |
77 | |
78 ---------------------------------------------------------------------- | |
79 | |
80 All trademarks and registered trademarks mentioned herein are the | |
81 property of their respective owners. | |
82 | |
83 *******************************************************************************/ | |
84 | |
85 module java.mangoicu.UTimeZone; | |
86 | |
87 private import java.mangoicu.ICU, | |
88 java.mangoicu.UString, | |
89 java.mangoicu.UEnumeration; | |
90 private import java.lang.util; | |
91 | |
92 /******************************************************************************* | |
93 | |
94 A representation of a TimeZone. Unfortunately, ICU does not expose | |
95 this as a seperate entity from the C-API, so we have to make do | |
96 with an approximation instead. | |
97 | |
98 *******************************************************************************/ | |
99 | |
100 struct UTimeZone | |
101 { | |
102 public CString16 name; | |
103 | |
104 public static UTimeZone Default = {null}; | |
105 public static UTimeZone Gmt = {"Etc/GMT"}; | |
106 public static UTimeZone Greenwich = {"Etc/Greenwich"}; | |
107 public static UTimeZone Uct = {"Etc/UCT"}; | |
108 public static UTimeZone Utc = {"Etc/UTC"}; | |
109 public static UTimeZone Universal = {"Etc/Universal"}; | |
110 | |
111 public static UTimeZone GmtPlus0 = {"Etc/GMT+0"}; | |
112 public static UTimeZone GmtPlus1 = {"Etc/GMT+1"}; | |
113 public static UTimeZone GmtPlus2 = {"Etc/GMT+2"}; | |
114 public static UTimeZone GmtPlus3 = {"Etc/GMT+3"}; | |
115 public static UTimeZone GmtPlus4 = {"Etc/GMT+4"}; | |
116 public static UTimeZone GmtPlus5 = {"Etc/GMT+5"}; | |
117 public static UTimeZone GmtPlus6 = {"Etc/GMT+6"}; | |
118 public static UTimeZone GmtPlus7 = {"Etc/GMT+7"}; | |
119 public static UTimeZone GmtPlus8 = {"Etc/GMT+8"}; | |
120 public static UTimeZone GmtPlus9 = {"Etc/GMT+9"}; | |
121 public static UTimeZone GmtPlus10 = {"Etc/GMT+10"}; | |
122 public static UTimeZone GmtPlus11 = {"Etc/GMT+11"}; | |
123 public static UTimeZone GmtPlus12 = {"Etc/GMT+12"}; | |
124 | |
125 public static UTimeZone GmtMinus0 = {"Etc/GMT-0"}; | |
126 public static UTimeZone GmtMinus1 = {"Etc/GMT-1"}; | |
127 public static UTimeZone GmtMinus2 = {"Etc/GMT-2"}; | |
128 public static UTimeZone GmtMinus3 = {"Etc/GMT-3"}; | |
129 public static UTimeZone GmtMinus4 = {"Etc/GMT-4"}; | |
130 public static UTimeZone GmtMinus5 = {"Etc/GMT-5"}; | |
131 public static UTimeZone GmtMinus6 = {"Etc/GMT-6"}; | |
132 public static UTimeZone GmtMinus7 = {"Etc/GMT-7"}; | |
133 public static UTimeZone GmtMinus8 = {"Etc/GMT-8"}; | |
134 public static UTimeZone GmtMinus9 = {"Etc/GMT-9"}; | |
135 public static UTimeZone GmtMinus10 = {"Etc/GMT-10"}; | |
136 public static UTimeZone GmtMinus11 = {"Etc/GMT-11"}; | |
137 public static UTimeZone GmtMinus12 = {"Etc/GMT-12"}; | |
138 | |
139 /*********************************************************************** | |
140 | |
141 Get the default time zone. | |
142 | |
143 ***********************************************************************/ | |
144 | |
145 static void getDefault (inout UTimeZone zone) | |
146 { | |
147 uint format (wchar* dst, uint length, inout ICU.UErrorCode e) | |
148 { | |
149 return ucal_getDefaultTimeZone (dst, length, e); | |
150 } | |
151 | |
152 UString s = new UString(64); | |
153 s.format (&format, "failed to get default time zone"); | |
154 zone.name = s.get(); | |
155 } | |
156 | |
157 /*********************************************************************** | |
158 | |
159 Set the default time zone. | |
160 | |
161 ***********************************************************************/ | |
162 | |
163 static void setDefault (inout UTimeZone zone) | |
164 { | |
165 ICU.UErrorCode e; | |
166 | |
167 ucal_setDefaultTimeZone (ICU.toString (zone.name), e); | |
168 ICU.testError (e, "failed to set default time zone"); | |
169 } | |
170 | |
171 /*********************************************************************** | |
172 | |
173 Return the amount of time in milliseconds that the clock | |
174 is advanced during daylight savings time for the given | |
175 time zone, or zero if the time zone does not observe daylight | |
176 savings time | |
177 | |
178 ***********************************************************************/ | |
179 | |
180 static uint getDSTSavings (inout UTimeZone zone) | |
181 { | |
182 ICU.UErrorCode e; | |
183 | |
184 uint x = ucal_getDSTSavings (ICU.toString (zone.name), e); | |
185 ICU.testError (e, "failed to get DST savings"); | |
186 return x; | |
187 } | |
188 | |
189 | |
190 /********************************************************************** | |
191 | |
192 Iterate over the available timezone names | |
193 | |
194 **********************************************************************/ | |
195 | |
196 static int opApply (int delegate(inout wchar[] element) dg) | |
197 { | |
198 ICU.UErrorCode e; | |
199 wchar[] name; | |
200 int result; | |
201 | |
202 void* h = ucal_openTimeZones (e); | |
203 ICU.testError (e, "failed to open timeszone iterator"); | |
204 | |
205 UEnumeration zones = new UEnumeration (cast(UEnumeration.Handle) h); | |
206 while (zones.next(name) && (result = dg(name)) != 0) {} | |
207 delete zones; | |
208 return result; | |
209 } | |
210 | |
211 | |
212 | |
213 /*********************************************************************** | |
214 | |
215 Bind the ICU functions from a shared library. This is | |
216 complicated by the issues regarding D and DLLs on the | |
217 Windows platform | |
218 | |
219 ***********************************************************************/ | |
220 | |
221 private static void* library; | |
222 | |
223 /*********************************************************************** | |
224 | |
225 ***********************************************************************/ | |
226 | |
227 private static extern (C) | |
228 { | |
229 void* function (inout ICU.UErrorCode) ucal_openTimeZones; | |
230 uint function (wchar*, uint, inout ICU.UErrorCode) ucal_getDefaultTimeZone; | |
231 void function (wchar*, inout ICU.UErrorCode) ucal_setDefaultTimeZone; | |
232 uint function (wchar*, inout ICU.UErrorCode) ucal_getDSTSavings; | |
233 } | |
234 | |
235 /*********************************************************************** | |
236 | |
237 ***********************************************************************/ | |
238 | |
239 static FunctionLoader.Bind[] targets = | |
240 [ | |
241 {cast(void**) &ucal_openTimeZones, "ucal_openTimeZones"}, | |
242 {cast(void**) &ucal_getDefaultTimeZone, "ucal_getDefaultTimeZone"}, | |
243 {cast(void**) &ucal_setDefaultTimeZone, "ucal_setDefaultTimeZone"}, | |
244 {cast(void**) &ucal_getDSTSavings, "ucal_getDSTSavings"}, | |
245 ]; | |
246 | |
247 /*********************************************************************** | |
248 | |
249 ***********************************************************************/ | |
250 | |
251 static this () | |
252 { | |
253 library = FunctionLoader.bind (ICU.icuin, targets); | |
254 } | |
255 | |
256 /*********************************************************************** | |
257 | |
258 ***********************************************************************/ | |
259 | |
260 static ~this () | |
261 { | |
262 FunctionLoader.unbind (library); | |
263 } | |
264 } |