|
36 | 36 | #include "config.h" |
37 | 37 | #include "date_time_scanner.cfg.hh" |
38 | 38 | #include "injector.hh" |
| 39 | +#include "math_util.hh" |
39 | 40 | #include "ptimec.hh" |
40 | 41 | #include "scn/scn.h" |
41 | 42 |
|
@@ -336,6 +337,19 @@ date_time_scanner::scan(const char* time_dest, |
336 | 337 | return retval; |
337 | 338 | } |
338 | 339 |
|
| 340 | +void |
| 341 | +date_time_scanner::clear() |
| 342 | +{ |
| 343 | + this->dts_base_time = 0; |
| 344 | + this->dts_base_tm = exttm{}; |
| 345 | + this->dts_fmt_lock = -1; |
| 346 | + this->dts_fmt_len = -1; |
| 347 | + this->dts_last_tv = timeval{}; |
| 348 | + this->dts_last_tm = exttm{}; |
| 349 | + this->dts_localtime_cached_gmt = 0; |
| 350 | + this->dts_localtime_cached_tm = tm{}; |
| 351 | +} |
| 352 | + |
339 | 353 | void |
340 | 354 | date_time_scanner::set_base_time(time_t base_time, const tm& local_tm) |
341 | 355 | { |
@@ -371,7 +385,29 @@ date_time_scanner::to_localtime(time_t t, exttm& tm_out) |
371 | 385 | -= this->dts_local_offset_expiry % EXPIRE_TIME; |
372 | 386 | } else { |
373 | 387 | time_t adjust_gmt = t + this->dts_local_offset_cache; |
374 | | - secs2tm(adjust_gmt, &tm_out.et_tm); |
| 388 | + auto adjust_gmt_min = adjust_gmt / 60; |
| 389 | + if (this->dts_localtime_cached_gmt == adjust_gmt_min) |
| 390 | + { |
| 391 | + tm_out.et_tm = this->dts_localtime_cached_tm; |
| 392 | + tm_out.et_tm.tm_sec = adjust_gmt % 60; |
| 393 | + } else { |
| 394 | + secs2tm(adjust_gmt, &tm_out.et_tm); |
| 395 | + this->dts_localtime_cached_gmt = adjust_gmt_min; |
| 396 | + this->dts_localtime_cached_tm = tm_out.et_tm; |
| 397 | + this->dts_localtime_cached_tm.tm_sec = 0; |
| 398 | + } |
| 399 | +#if 0 |
| 400 | + { |
| 401 | + tm verify_tm; |
| 402 | + secs2tm(adjust_gmt, &verify_tm); |
| 403 | + require(tm_out.et_tm.tm_year == verify_tm.tm_year); |
| 404 | + require(tm_out.et_tm.tm_mon == verify_tm.tm_mon); |
| 405 | + require(tm_out.et_tm.tm_mday == verify_tm.tm_mday); |
| 406 | + require(tm_out.et_tm.tm_hour == verify_tm.tm_hour); |
| 407 | + require(tm_out.et_tm.tm_min == verify_tm.tm_min); |
| 408 | + require(tm_out.et_tm.tm_sec == verify_tm.tm_sec); |
| 409 | + } |
| 410 | +#endif |
375 | 411 | } |
376 | 412 | tm_out.et_gmtoff = 0; |
377 | 413 | #ifdef HAVE_STRUCT_TM_TM_ZONE |
|
0 commit comments