OLD | NEW |
---|---|
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 } | 335 } |
336 | 336 |
337 void SystemSnapshotMac::TimeZone(DaylightSavingTimeStatus* dst_status, | 337 void SystemSnapshotMac::TimeZone(DaylightSavingTimeStatus* dst_status, |
338 int* standard_offset_seconds, | 338 int* standard_offset_seconds, |
339 int* daylight_offset_seconds, | 339 int* daylight_offset_seconds, |
340 std::string* standard_name, | 340 std::string* standard_name, |
341 std::string* daylight_name) const { | 341 std::string* daylight_name) const { |
342 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 342 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
343 | 343 |
344 tm local; | 344 tm local; |
345 localtime_r(&snapshot_time_->tv_sec, &local); | 345 PCHECK(localtime_r(&snapshot_time_->tv_sec, &local)) << "localtime_r"; |
346 | 346 |
347 *standard_name = tzname[0]; | 347 *standard_name = tzname[0]; |
348 if (daylight) { | 348 if (daylight) { |
349 // This assumes that the offset between standard and daylight saving time is | 349 // Scan forward and backward, one month at a time, looking for an instance |
350 // globally a constant, where a time zone’s daylight saving time is one hour | 350 // when the observance of daylight saving time is different than it is in |
351 // ahead of its standard time. | 351 // |local|. |
352 const int kSecondsPerHour = 60 * 60; | 352 long probe_gmtoff = local.tm_gmtoff; |
353 | |
354 const int kMonthDeltas[] = | |
355 { 0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, | |
356 7, -7, 8, -8, 9, -9, 10, -10, 11, -11, 12, -12 }; | |
357 for (size_t index = 0; index < arraysize(kMonthDeltas); ++index) { | |
358 // Look at the 15th day of each month at local noon. Set tm_isdst to -1 to | |
359 // avoid giving mktime() any hints about whether to consider daylight | |
360 // saving time in effect. mktime() accepts values of tm_mon that are | |
Robert Sesek
2014/10/03 22:36:42
Pinkerton will be happy that I didn't have to comm
| |
361 // outside of its normal range and behaves as expected: if tm_mon is -1, | |
362 // it references December of the preceding year, and if it is 12, it | |
363 // references January of the following year. | |
364 tm probe_tm = {}; | |
365 probe_tm.tm_hour = 12; | |
366 probe_tm.tm_mday = 15; | |
367 probe_tm.tm_mon = local.tm_mon + kMonthDeltas[index]; | |
368 probe_tm.tm_year = local.tm_year; | |
369 probe_tm.tm_isdst = -1; | |
370 if (mktime(&probe_tm) != -1 && probe_tm.tm_isdst != local.tm_isdst) { | |
371 probe_gmtoff = probe_tm.tm_gmtoff; | |
372 break; | |
373 } | |
374 } | |
353 | 375 |
354 *daylight_name = tzname[1]; | 376 *daylight_name = tzname[1]; |
355 if (!local.tm_isdst) { | 377 if (!local.tm_isdst) { |
356 *dst_status = kObservingStandardTime; | 378 *dst_status = kObservingStandardTime; |
357 *standard_offset_seconds = local.tm_gmtoff; | 379 *standard_offset_seconds = local.tm_gmtoff; |
358 *daylight_offset_seconds = local.tm_gmtoff + kSecondsPerHour; | 380 *daylight_offset_seconds = probe_gmtoff; |
359 } else { | 381 } else { |
360 *dst_status = kObservingDaylightSavingTime; | 382 *dst_status = kObservingDaylightSavingTime; |
361 *standard_offset_seconds = local.tm_gmtoff - kSecondsPerHour; | 383 *standard_offset_seconds = probe_gmtoff; |
362 *daylight_offset_seconds = local.tm_gmtoff; | 384 *daylight_offset_seconds = local.tm_gmtoff; |
363 } | 385 } |
364 } else { | 386 } else { |
365 *daylight_name = tzname[0]; | 387 *daylight_name = tzname[0]; |
366 *dst_status = kDoesNotObserveDaylightSavingTime; | 388 *dst_status = kDoesNotObserveDaylightSavingTime; |
367 *standard_offset_seconds = local.tm_gmtoff; | 389 *standard_offset_seconds = local.tm_gmtoff; |
368 *daylight_offset_seconds = local.tm_gmtoff; | 390 *daylight_offset_seconds = local.tm_gmtoff; |
369 } | 391 } |
370 } | 392 } |
371 | 393 |
372 } // namespace internal | 394 } // namespace internal |
373 } // namespace crashpad | 395 } // namespace crashpad |
OLD | NEW |