1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module glib.TimeZone; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.c.functions; 30 public import glib.c.types; 31 public import gtkc.glibtypes; 32 private import gtkd.Loader; 33 34 35 /** 36 * #GTimeZone is an opaque structure whose members cannot be accessed 37 * directly. 38 * 39 * Since: 2.26 40 */ 41 public class TimeZone 42 { 43 /** the main Gtk struct */ 44 protected GTimeZone* gTimeZone; 45 protected bool ownedRef; 46 47 /** Get the main Gtk struct */ 48 public GTimeZone* getTimeZoneStruct(bool transferOwnership = false) 49 { 50 if (transferOwnership) 51 ownedRef = false; 52 return gTimeZone; 53 } 54 55 /** the main Gtk struct as a void* */ 56 protected void* getStruct() 57 { 58 return cast(void*)gTimeZone; 59 } 60 61 /** 62 * Sets our main struct and passes it to the parent class. 63 */ 64 public this (GTimeZone* gTimeZone, bool ownedRef = false) 65 { 66 this.gTimeZone = gTimeZone; 67 this.ownedRef = ownedRef; 68 } 69 70 ~this () 71 { 72 if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef ) 73 g_time_zone_unref(gTimeZone); 74 } 75 76 77 /** 78 * Creates a #GTimeZone corresponding to @identifier. 79 * 80 * @identifier can either be an RFC3339/ISO 8601 time offset or 81 * something that would pass as a valid value for the `TZ` environment 82 * variable (including %NULL). 83 * 84 * In Windows, @identifier can also be the unlocalized name of a time 85 * zone for standard time, for example "Pacific Standard Time". 86 * 87 * Valid RFC3339 time offsets are `"Z"` (for UTC) or 88 * `"±hh:mm"`. ISO 8601 additionally specifies 89 * `"±hhmm"` and `"±hh"`. Offsets are 90 * time values to be added to Coordinated Universal Time (UTC) to get 91 * the local time. 92 * 93 * In UNIX, the `TZ` environment variable typically corresponds 94 * to the name of a file in the zoneinfo database, or string in 95 * "std offset [dst [offset],start[/time],end[/time]]" (POSIX) format. 96 * There are no spaces in the specification. The name of standard 97 * and daylight savings time zone must be three or more alphabetic 98 * characters. Offsets are time values to be added to local time to 99 * get Coordinated Universal Time (UTC) and should be 100 * `"[±]hh[[:]mm[:ss]]"`. Dates are either 101 * `"Jn"` (Julian day with n between 1 and 365, leap 102 * years not counted), `"n"` (zero-based Julian day 103 * with n between 0 and 365) or `"Mm.w.d"` (day d 104 * (0 <= d <= 6) of week w (1 <= w <= 5) of month m (1 <= m <= 12), day 105 * 0 is a Sunday). Times are in local wall clock time, the default is 106 * 02:00:00. 107 * 108 * In Windows, the "tzn[+|–]hh[:mm[:ss]][dzn]" format is used, but also 109 * accepts POSIX format. The Windows format uses US rules for all time 110 * zones; daylight savings time is 60 minutes behind the standard time 111 * with date and time of change taken from Pacific Standard Time. 112 * Offsets are time values to be added to the local time to get 113 * Coordinated Universal Time (UTC). 114 * 115 * g_time_zone_new_local() calls this function with the value of the 116 * `TZ` environment variable. This function itself is independent of 117 * the value of `TZ`, but if @identifier is %NULL then `/etc/localtime` 118 * will be consulted to discover the correct time zone on UNIX and the 119 * registry will be consulted or GetTimeZoneInformation() will be used 120 * to get the local time zone on Windows. 121 * 122 * If intervals are not available, only time zone rules from `TZ` 123 * environment variable or other means, then they will be computed 124 * from year 1900 to 2037. If the maximum year for the rules is 125 * available and it is greater than 2037, then it will followed 126 * instead. 127 * 128 * See 129 * [RFC3339 §5.6](http://tools.ietf.org/html/rfc3339#section-5.6) 130 * for a precise definition of valid RFC3339 time offsets 131 * (the `time-offset` expansion) and ISO 8601 for the 132 * full list of valid time offsets. See 133 * [The GNU C Library manual](http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html) 134 * for an explanation of the possible 135 * values of the `TZ` environment variable. See 136 * [Microsoft Time Zone Index Values](http://msdn.microsoft.com/en-us/library/ms912391%28v=winembedded.11%29.aspx) 137 * for the list of time zones on Windows. 138 * 139 * You should release the return value by calling g_time_zone_unref() 140 * when you are done with it. 141 * 142 * Params: 143 * identifier = a timezone identifier 144 * 145 * Returns: the requested timezone 146 * 147 * Since: 2.26 148 * 149 * Throws: ConstructionException GTK+ fails to create the object. 150 */ 151 public this(string identifier) 152 { 153 auto p = g_time_zone_new(Str.toStringz(identifier)); 154 155 if(p is null) 156 { 157 throw new ConstructionException("null returned by new"); 158 } 159 160 this(cast(GTimeZone*) p); 161 } 162 163 /** 164 * Creates a #GTimeZone corresponding to the given constant offset from UTC, 165 * in seconds. 166 * 167 * This is equivalent to calling g_time_zone_new() with a string in the form 168 * `[+|-]hh[:mm[:ss]]`. 169 * 170 * Params: 171 * seconds = offset to UTC, in seconds 172 * 173 * Returns: a timezone at the given offset from UTC 174 * 175 * Since: 2.58 176 * 177 * Throws: ConstructionException GTK+ fails to create the object. 178 */ 179 public this(int seconds) 180 { 181 auto p = g_time_zone_new_offset(seconds); 182 183 if(p is null) 184 { 185 throw new ConstructionException("null returned by new_offset"); 186 } 187 188 this(cast(GTimeZone*) p); 189 } 190 191 /** 192 * Finds an interval within @tz that corresponds to the given @time_, 193 * possibly adjusting @time_ if required to fit into an interval. 194 * The meaning of @time_ depends on @type. 195 * 196 * This function is similar to g_time_zone_find_interval(), with the 197 * difference that it always succeeds (by making the adjustments 198 * described below). 199 * 200 * In any of the cases where g_time_zone_find_interval() succeeds then 201 * this function returns the same value, without modifying @time_. 202 * 203 * This function may, however, modify @time_ in order to deal with 204 * non-existent times. If the non-existent local @time_ of 02:30 were 205 * requested on March 14th 2010 in Toronto then this function would 206 * adjust @time_ to be 03:00 and return the interval containing the 207 * adjusted time. 208 * 209 * Params: 210 * type = the #GTimeType of @time_ 211 * time = a pointer to a number of seconds since January 1, 1970 212 * 213 * Returns: the interval containing @time_, never -1 214 * 215 * Since: 2.26 216 */ 217 public int adjustTime(GTimeType type, long* time) 218 { 219 return g_time_zone_adjust_time(gTimeZone, type, time); 220 } 221 222 /** 223 * Finds an the interval within @tz that corresponds to the given @time_. 224 * The meaning of @time_ depends on @type. 225 * 226 * If @type is %G_TIME_TYPE_UNIVERSAL then this function will always 227 * succeed (since universal time is monotonic and continuous). 228 * 229 * Otherwise @time_ is treated as local time. The distinction between 230 * %G_TIME_TYPE_STANDARD and %G_TIME_TYPE_DAYLIGHT is ignored except in 231 * the case that the given @time_ is ambiguous. In Toronto, for example, 232 * 01:30 on November 7th 2010 occurred twice (once inside of daylight 233 * savings time and the next, an hour later, outside of daylight savings 234 * time). In this case, the different value of @type would result in a 235 * different interval being returned. 236 * 237 * It is still possible for this function to fail. In Toronto, for 238 * example, 02:00 on March 14th 2010 does not exist (due to the leap 239 * forward to begin daylight savings time). -1 is returned in that 240 * case. 241 * 242 * Params: 243 * type = the #GTimeType of @time_ 244 * time = a number of seconds since January 1, 1970 245 * 246 * Returns: the interval containing @time_, or -1 in case of failure 247 * 248 * Since: 2.26 249 */ 250 public int findInterval(GTimeType type, long time) 251 { 252 return g_time_zone_find_interval(gTimeZone, type, time); 253 } 254 255 /** 256 * Determines the time zone abbreviation to be used during a particular 257 * @interval of time in the time zone @tz. 258 * 259 * For example, in Toronto this is currently "EST" during the winter 260 * months and "EDT" during the summer months when daylight savings time 261 * is in effect. 262 * 263 * Params: 264 * interval = an interval within the timezone 265 * 266 * Returns: the time zone abbreviation, which belongs to @tz 267 * 268 * Since: 2.26 269 */ 270 public string getAbbreviation(int interval) 271 { 272 return Str.toString(g_time_zone_get_abbreviation(gTimeZone, interval)); 273 } 274 275 /** 276 * Get the identifier of this #GTimeZone, as passed to g_time_zone_new(). 277 * If the identifier passed at construction time was not recognised, `UTC` will 278 * be returned. If it was %NULL, the identifier of the local timezone at 279 * construction time will be returned. 280 * 281 * The identifier will be returned in the same format as provided at 282 * construction time: if provided as a time offset, that will be returned by 283 * this function. 284 * 285 * Returns: identifier for this timezone 286 * 287 * Since: 2.58 288 */ 289 public string getIdentifier() 290 { 291 return Str.toString(g_time_zone_get_identifier(gTimeZone)); 292 } 293 294 /** 295 * Determines the offset to UTC in effect during a particular @interval 296 * of time in the time zone @tz. 297 * 298 * The offset is the number of seconds that you add to UTC time to 299 * arrive at local time for @tz (ie: negative numbers for time zones 300 * west of GMT, positive numbers for east). 301 * 302 * Params: 303 * interval = an interval within the timezone 304 * 305 * Returns: the number of seconds that should be added to UTC to get the 306 * local time in @tz 307 * 308 * Since: 2.26 309 */ 310 public int getOffset(int interval) 311 { 312 return g_time_zone_get_offset(gTimeZone, interval); 313 } 314 315 /** 316 * Determines if daylight savings time is in effect during a particular 317 * @interval of time in the time zone @tz. 318 * 319 * Params: 320 * interval = an interval within the timezone 321 * 322 * Returns: %TRUE if daylight savings time is in effect 323 * 324 * Since: 2.26 325 */ 326 public bool isDst(int interval) 327 { 328 return g_time_zone_is_dst(gTimeZone, interval) != 0; 329 } 330 331 alias doref = ref_; 332 /** 333 * Increases the reference count on @tz. 334 * 335 * Returns: a new reference to @tz. 336 * 337 * Since: 2.26 338 */ 339 public TimeZone ref_() 340 { 341 auto p = g_time_zone_ref(gTimeZone); 342 343 if(p is null) 344 { 345 return null; 346 } 347 348 return new TimeZone(cast(GTimeZone*) p, true); 349 } 350 351 /** 352 * Decreases the reference count on @tz. 353 * 354 * Since: 2.26 355 */ 356 public void unref() 357 { 358 g_time_zone_unref(gTimeZone); 359 } 360 }