Mercurial > pidgin
comparison libpurple/util.c @ 18259:c5c265dff90c
support replying to XEP-0202 queries
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sun, 24 Jun 2007 04:53:36 +0000 |
parents | 5653692dcf79 |
children | e122b631a657 |
comparison
equal
deleted
inserted
replaced
18258:70747b33f1bd | 18259:c5c265dff90c |
---|---|
529 | 529 |
530 return off; | 530 return off; |
531 } | 531 } |
532 #endif | 532 #endif |
533 | 533 |
534 #ifndef HAVE_STRFTIME_Z_FORMAT | 534 const char *purple_get_tzoff_str(const struct tm *tm, gboolean iso) |
535 static const char *get_tmoff(const struct tm *tm) | 535 { |
536 { | 536 static char buf[7]; |
537 static char buf[6]; | |
538 long off; | 537 long off; |
539 gint8 min; | 538 gint8 min; |
540 gint8 hrs; | 539 gint8 hrs; |
541 struct tm new_tm = *tm; | 540 struct tm new_tm = *tm; |
542 | 541 |
552 # ifdef HAVE_TM_GMTOFF | 551 # ifdef HAVE_TM_GMTOFF |
553 off = new_tm.tm_gmtoff; | 552 off = new_tm.tm_gmtoff; |
554 # else | 553 # else |
555 # ifdef HAVE_TIMEZONE | 554 # ifdef HAVE_TIMEZONE |
556 tzset(); | 555 tzset(); |
557 off = -timezone; | 556 off = -1 * timezone; |
558 # endif /* HAVE_TIMEZONE */ | 557 # endif /* HAVE_TIMEZONE */ |
559 # endif /* !HAVE_TM_GMTOFF */ | 558 # endif /* !HAVE_TM_GMTOFF */ |
560 #endif /* _WIN32 */ | 559 #endif /* _WIN32 */ |
561 | 560 |
562 min = (off / 60) % 60; | 561 min = (off / 60) % 60; |
563 hrs = ((off / 60) - min) / 60; | 562 hrs = ((off / 60) - min) / 60; |
564 | 563 |
565 if (g_snprintf(buf, sizeof(buf), "%+03d%02d", hrs, ABS(min)) > 5) | 564 if(iso) { |
566 g_return_val_if_reached(""); | 565 if (0 == off) { |
566 strcpy(buf, "Z"); | |
567 } else { | |
568 /* please leave the colons...they're optional for iso, but jabber | |
569 * wants them */ | |
570 if(g_snprintf(buf, sizeof(buf), "%+03d:%02d", hrs, ABS(min)) > 6) | |
571 g_return_val_if_reached(""); | |
572 } | |
573 } else { | |
574 if (g_snprintf(buf, sizeof(buf), "%+03d%02d", hrs, ABS(min)) > 5) | |
575 g_return_val_if_reached(""); | |
576 } | |
567 | 577 |
568 return buf; | 578 return buf; |
569 } | 579 } |
570 #endif | |
571 | 580 |
572 /* Windows doesn't HAVE_STRFTIME_Z_FORMAT, but this seems clearer. -- rlaager */ | 581 /* Windows doesn't HAVE_STRFTIME_Z_FORMAT, but this seems clearer. -- rlaager */ |
573 #if !defined(HAVE_STRFTIME_Z_FORMAT) || defined(_WIN32) | 582 #if !defined(HAVE_STRFTIME_Z_FORMAT) || defined(_WIN32) |
574 static size_t purple_internal_strftime(char *s, size_t max, const char *format, const struct tm *tm) | 583 static size_t purple_internal_strftime(char *s, size_t max, const char *format, const struct tm *tm) |
575 { | 584 { |
598 { | 607 { |
599 char *tmp = g_strdup_printf("%s%.*s%s", | 608 char *tmp = g_strdup_printf("%s%.*s%s", |
600 fmt ? fmt : "", | 609 fmt ? fmt : "", |
601 c - start - 1, | 610 c - start - 1, |
602 start, | 611 start, |
603 get_tmoff(tm)); | 612 purple_get_tzoff_str(tm, FALSE)); |
604 g_free(fmt); | 613 g_free(fmt); |
605 fmt = tmp; | 614 fmt = tmp; |
606 start = c + 1; | 615 start = c + 1; |
607 } | 616 } |
608 #endif | 617 #endif |