Changeset 4ebbfbc


Ignore:
Timestamp:
Jul 23, 2011, 8:26:03 PM (10 years ago)
Author:
Jason Gross <jgross@mit.edu>
Branches:
master, release-1.9
Children:
e5baf0a, c36f4d0
Parents:
a7fac14
git-author:
Jason Gross <jgross@mit.edu> (07/22/11 10:43:43)
git-committer:
Jason Gross <jgross@mit.edu> (07/23/11 20:26:03)
Message:
Show the time zone in :info; replace ctime with strftime

This fixes trac-#146.

The new function owl_util_time_to_timestr takes a const struct tm *
instead of a const time_t because, although we pass around time_t for
just about everything else, this lets the caller decide whether to use
localtime or gmtime (UTC).

Note: I'm not sure that "%c" (which is locale-dependent) will always
include the time zone.  If not, or if we want a bit more consistency, we
can switch to something like "%a %b %d %H:%M:%S %Y %Z" (like "Fri Jul 22
15:39:45 2011 EDT") or "%a %b %d, %Y %h:%M:%S %p %Z" (like "Fri Jul 22,
2011 03:39:45 PM 2011 EDT") or something.  On linerva, "%c" seems to be
equivalent to "%a %d %b %Y %h:%M:%S %p %Z" (like "Fri 22 Jul 2011
03:39:45 PM EDT").
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r6500907 r4ebbfbc  
    12231223void G_GNUC_PRINTF(1, 2) owl_function_debugmsg(const char *fmt, ...)
    12241224{
     1225  char *tmpbuff;
    12251226  FILE *file;
    12261227  time_t now;
     
    12371238  now = time(NULL);
    12381239
    1239   fprintf(file, "[%d -  %.24s - %lds]: ",
    1240           (int) getpid(), ctime(&now), now - owl_global_get_starttime(&g));
     1240  tmpbuff = owl_util_time_to_timestr(localtime(&now));
     1241  fprintf(file, "[%d -  %s - %lds]: ",
     1242          (int) getpid(), tmpbuff, now - owl_global_get_starttime(&g));
     1243  g_free(tmpbuff);
    12411244  vfprintf(file, fmt, ap);
    12421245  putc('\n', file);
     
    17611764void owl_function_status(void)
    17621765{
     1766  char *tmpbuff;
    17631767  char buff[MAXPATHLEN+1];
    17641768  time_t start;
     
    17881792  owl_fmtext_append_normal(&fm, "\n");
    17891793
    1790   owl_fmtext_appendf_normal(&fm, "  Startup Time: %s", ctime(&start));
     1794  tmpbuff = owl_util_time_to_timestr(localtime(&start));
     1795  owl_fmtext_appendf_normal(&fm, "  Startup Time: %s\n", tmpbuff);
     1796  g_free(tmpbuff);
    17911797
    17921798  up=owl_global_get_runtime(&g);
     
    34093415  char *buff;
    34103416
    3411   now=time(NULL);
    3412   date=g_strdup(ctime(&now));
    3413   date[strlen(date)-1]='\0';
     3417  now = time(NULL);
     3418  date = owl_util_time_to_timestr(localtime(&now));
    34143419
    34153420  buff = g_strdup_printf("%s %s", date, string);
  • message.c

    r6500907 r4ebbfbc  
    4646 
    4747  /* save the time */
    48   m->time=time(NULL);
    49   m->timestr=g_strdup(ctime(&(m->time)));
    50   m->timestr[strlen(m->timestr)-1]='\0';
     48  m->time = time(NULL);
     49  m->timestr = owl_util_time_to_timestr(localtime(&m->time));
    5150
    5251  m->fmtext = NULL;
     
    796795  /* save the time, we need to nuke the string saved by message_init */
    797796  if (m->timestr) g_free(m->timestr);
    798   m->time=n->z_time.tv_sec;
    799   m->timestr=g_strdup(ctime(&(m->time)));
    800   m->timestr[strlen(m->timestr)-1]='\0';
     797  m->time = n->z_time.tv_sec;
     798  m->timestr = owl_util_time_to_timestr(localtime(&m->time));
    801799
    802800  /* set other info */
  • perl/modules/Twitter/lib/BarnOwl/Module/Twitter/Handle.pm

    r7aa1fa5 r4ebbfbc  
    2929use BarnOwl;
    3030use BarnOwl::Message::Twitter;
    31 use POSIX qw(asctime);
     31use POSIX qw(strftime);
    3232
    3333use LWP::UserAgent;
     
    247247                       ($self->{cfg}->{account_nickname} ?
    248248                        "[$self->{cfg}->{account_nickname}]" : "") .
    249                         ": ratelimited until " . asctime(localtime($timeout)));
     249                        ": ratelimited until " . strftime('%c', localtime($timeout)));
    250250    } elsif(exists($ratelimit->{error})) {
    251251        $self->sleep(60*20);
  • util.c

    r8219374 r4ebbfbc  
    296296}
    297297
     298CALLER_OWN char *owl_util_time_to_timestr(const struct tm *time)
     299{
     300  /* 32 chosen for first attempt because timestr will end up being
     301   * something like "Www Mmm dd hh:mm:ss AM yyyy UTC\0" */
     302  size_t timestr_size = 16;
     303  char *timestr = NULL;
     304  do {
     305    timestr_size *= 2;
     306    timestr = g_renew(char, timestr, timestr_size);
     307  } while (strftime(timestr, timestr_size, "%c", time) == 0);
     308  return timestr;
     309}
     310
    298311/* These are in order of their value in owl.h */
    299312static const struct {
Note: See TracChangeset for help on using the changeset viewer.