 |
Changeset 2128
- Timestamp:
- 05/02/07 16:50:42
(2 years ago)
- Author:
- kris
- Message:
testing DST-related changes ...
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2048 |
r2128 |
|
| 22 | 22 | |
|---|
| 23 | 23 | // set current local time |
|---|
| 24 | | date.set (Utc.local); |
|---|
| | 24 | date.set (Utc.time, true); |
|---|
| 25 | 25 | |
|---|
| 26 | 26 | // get GMT difference in minutes |
|---|
| … | … | |
| 43 | 43 | date.year |
|---|
| 44 | 44 | ); |
|---|
| | 45 | |
|---|
| | 46 | date.set (Utc.time); |
|---|
| | 47 | // format date |
|---|
| | 48 | Stdout.formatln ("{}, {} {:d2} {:d2}:{:d2}:{:d2} GMT{}{:d2}:{:d2} {}", |
|---|
| | 49 | date.asDay, |
|---|
| | 50 | date.asMonth, |
|---|
| | 51 | date.day, |
|---|
| | 52 | date.hour, |
|---|
| | 53 | date.min, |
|---|
| | 54 | date.sec, |
|---|
| | 55 | sign, |
|---|
| | 56 | tz / 60, |
|---|
| | 57 | tz % 60, |
|---|
| | 58 | date.year |
|---|
| | 59 | ); |
|---|
| 45 | 60 | } |
|---|
| r2049 |
r2128 |
|
| 164 | 164 | ***************************************************************/ |
|---|
| 165 | 165 | |
|---|
| 166 | | Time get () |
|---|
| | 166 | Time get (bool local=false) |
|---|
| 167 | 167 | { |
|---|
| 168 | 168 | SYSTEMTIME sTime = void; |
|---|
| … | … | |
| 179 | 179 | |
|---|
| 180 | 180 | SystemTimeToFileTime (&sTime, &fTime); |
|---|
| 181 | | return Utc.convert (fTime); |
|---|
| | 181 | auto time = Utc.convert (fTime); |
|---|
| | 182 | return (local) ? cast(Time) (time+localBias) : time; |
|---|
| 182 | 183 | } |
|---|
| 183 | 184 | |
|---|
| … | … | |
| 190 | 191 | ***************************************************************/ |
|---|
| 191 | 192 | |
|---|
| 192 | | void set (Time time) |
|---|
| | 193 | void set (Time time, bool local=false) |
|---|
| 193 | 194 | { |
|---|
| 194 | 195 | SYSTEMTIME sTime = void; |
|---|
| | 196 | |
|---|
| | 197 | if (local) |
|---|
| | 198 | time -= localBias; |
|---|
| 195 | 199 | |
|---|
| 196 | 200 | auto fTime = Utc.convert (time); |
|---|
| … | … | |
| 206 | 210 | dow = sTime.wDayOfWeek; |
|---|
| 207 | 211 | } |
|---|
| | 212 | |
|---|
| | 213 | /*************************************************************** |
|---|
| | 214 | |
|---|
| | 215 | adjust for local time |
|---|
| | 216 | |
|---|
| | 217 | ***************************************************************/ |
|---|
| | 218 | |
|---|
| | 219 | private ulong localBias () |
|---|
| | 220 | { |
|---|
| | 221 | ulong bias; |
|---|
| | 222 | TIME_ZONE_INFORMATION tz = void; |
|---|
| | 223 | |
|---|
| | 224 | switch (GetTimeZoneInformation (&tz)) |
|---|
| | 225 | { |
|---|
| | 226 | default: |
|---|
| | 227 | bias = tz.Bias; |
|---|
| | 228 | break; |
|---|
| | 229 | case 1: |
|---|
| | 230 | bias = tz.Bias + tz.StandardBias; |
|---|
| | 231 | break; |
|---|
| | 232 | case 2: |
|---|
| | 233 | bias = tz.Bias + tz.DaylightBias; |
|---|
| | 234 | break; |
|---|
| | 235 | } |
|---|
| | 236 | |
|---|
| | 237 | return bias * Time.TicksPerMinute; |
|---|
| | 238 | } |
|---|
| 208 | 239 | } |
|---|
| 209 | 240 | |
|---|
| … | … | |
| 223 | 254 | ***************************************************************/ |
|---|
| 224 | 255 | |
|---|
| 225 | | Time get () |
|---|
| | 256 | Time get (bool local=false) |
|---|
| 226 | 257 | { |
|---|
| 227 | 258 | tm t; |
|---|
| … | … | |
| 234 | 265 | t.tm_sec = sec; |
|---|
| 235 | 266 | |
|---|
| | 267 | time_t seconds = local ? timelocal (&t) |
|---|
| | 268 | : timegm (&t); |
|---|
| 236 | 269 | return cast(Time) (Time.TicksTo1970 + |
|---|
| 237 | | Time.TicksPerSecond * timegm(&t) + |
|---|
| | 270 | Time.TicksPerSecond * seconds + |
|---|
| 238 | 271 | Time.TicksPerMillisecond * ms); |
|---|
| 239 | 272 | } |
|---|
| … | … | |
| 247 | 280 | **************************************************************/ |
|---|
| 248 | 281 | |
|---|
| 249 | | void set (Time time) |
|---|
| | 282 | void set (Time time, bool local=false) |
|---|
| 250 | 283 | { |
|---|
| 251 | 284 | auto timeval = Utc.convert (time); |
|---|
| … | … | |
| 253 | 286 | |
|---|
| 254 | 287 | tm result; |
|---|
| 255 | | tm* t = gmtime_r (&timeval.tv_sec, &result); |
|---|
| 256 | | assert (t, "gmtime failed"); |
|---|
| | 288 | tm* t = local ? localtime_r (&timeval.tv_sec, &result) |
|---|
| | 289 | : gmtime_r (&timeval.tv_sec, &result); |
|---|
| | 290 | assert (t); |
|---|
| 257 | 291 | |
|---|
| 258 | | year = t.tm_year + 1900; |
|---|
| 259 | | month = t.tm_mon + 1; |
|---|
| 260 | | day = t.tm_mday; |
|---|
| 261 | | hour = t.tm_hour; |
|---|
| 262 | | min = t.tm_min; |
|---|
| 263 | | sec = t.tm_sec; |
|---|
| 264 | | dow = t.tm_wday; |
|---|
| | 292 | year = result.tm_year + 1900; |
|---|
| | 293 | month = result.tm_mon + 1; |
|---|
| | 294 | day = result.tm_mday; |
|---|
| | 295 | hour = result.tm_hour; |
|---|
| | 296 | min = result.tm_min; |
|---|
| | 297 | sec = result.tm_sec; |
|---|
| | 298 | dow = result.tm_wday; |
|---|
| 265 | 299 | } |
|---|
| 266 | 300 | } |
|---|
Download in other formats:
|
 |
 |
|
 |
Copyright © 2006-2008 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic