Changeset 4ebbfbc for util.c


Ignore:
Timestamp:
Jul 23, 2011, 8:26:03 PM (12 years ago)
Author:
Jason Gross <jgross@mit.edu>
Branches:
master, release-1.10, 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").
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.