Mercurial > pidgin
comparison src/util.c @ 8577:599d6ac9bbfe
[gaim-migrate @ 9326]
a jabber tweak i forgot to commit
a fix for logging times wrt daylight savings time
re-fix html logging timestamp sizes, after the syslog merge
a cosmetic change to the log window
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Sun, 04 Apr 2004 18:27:45 +0000 |
| parents | 2d4ccd94e298 |
| children | 56360561af5e |
comparison
equal
deleted
inserted
replaced
| 8576:ddbcef747dc7 | 8577:599d6ac9bbfe |
|---|---|
| 424 tm.tm_min = min; | 424 tm.tm_min = min; |
| 425 tm.tm_sec = sec >= 0 ? sec : time(NULL) % 60; | 425 tm.tm_sec = sec >= 0 ? sec : time(NULL) % 60; |
| 426 | 426 |
| 427 return mktime(&tm); | 427 return mktime(&tm); |
| 428 } | 428 } |
| 429 | |
| 430 time_t | |
| 431 gaim_str_to_time(const char *timestamp, gboolean utc) | |
| 432 { | |
| 433 struct tm t; | |
| 434 time_t retval = 0; | |
| 435 char buf[32]; | |
| 436 char *c; | |
| 437 int tzoff = 0; | |
| 438 | |
| 439 time(&retval); | |
| 440 localtime_r(&retval, &t); | |
| 441 | |
| 442 snprintf(buf, sizeof(buf), "%s", timestamp); | |
| 443 c = buf; | |
| 444 | |
| 445 /* 4 digit year */ | |
| 446 if(!sscanf(c, "%04d", &t.tm_year)) return 0; | |
| 447 c+=4; | |
| 448 if(*c == '-') | |
| 449 c++; | |
| 450 | |
| 451 t.tm_year -= 1900; | |
| 452 | |
| 453 /* 2 digit month */ | |
| 454 if(!sscanf(c, "%02d", &t.tm_mon)) return 0; | |
| 455 c+=2; | |
| 456 if(*c == '-') | |
| 457 c++; | |
| 458 | |
| 459 t.tm_mon -= 1; | |
| 460 | |
| 461 | |
| 462 /* 2 digit day */ | |
| 463 if(!sscanf(c, "%02d", &t.tm_mday)) return 0; | |
| 464 c+=2; | |
| 465 if(*c == 'T' || *c == '.') { /* we have more than a date, keep going */ | |
| 466 c++; /* skip the "T" */ | |
| 467 | |
| 468 /* 2 digit hour */ | |
| 469 if(sscanf(c, "%02d:%02d:%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3 || | |
| 470 sscanf(c, "%02d%02d%02d", &t.tm_hour, &t.tm_min, &t.tm_sec) == 3) { | |
| 471 int tzhrs, tzmins; | |
| 472 c+=8; | |
| 473 if(*c == '.') /* dealing with precision we don't care about */ | |
| 474 c += 4; | |
| 475 | |
| 476 if((*c == '+' || *c == '-') && | |
| 477 sscanf(c+1, "%02d:%02d", &tzhrs, &tzmins)) { | |
| 478 tzoff = tzhrs*60*60 + tzmins*60; | |
| 479 if(*c == '+') | |
| 480 tzoff *= -1; | |
| 481 } | |
| 482 | |
| 483 if(tzoff || utc) { | |
| 484 | |
| 485 #ifdef HAVE_TM_GMTOFF | |
| 486 tzoff += t.tm_gmtoff; | |
| 487 #else | |
| 488 # ifdef HAVE_TIMEZONE | |
| 489 tzset(); /* making sure */ | |
| 490 tzoff -= timezone; | |
| 491 # endif | |
| 492 #endif | |
| 493 } | |
| 494 } | |
| 495 } | |
| 496 | |
| 497 t.tm_isdst = -1; | |
| 498 | |
| 499 retval = mktime(&t); | |
| 500 | |
| 501 retval += tzoff; | |
| 502 | |
| 503 return retval; | |
| 504 } | |
| 505 | |
| 429 | 506 |
| 430 | 507 |
| 431 /************************************************************************** | 508 /************************************************************************** |
| 432 * Markup Functions | 509 * Markup Functions |
| 433 **************************************************************************/ | 510 **************************************************************************/ |
