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