Changeset 1785 for trunk/gsdl/lib


Ignore:
Timestamp:
2000-12-12T13:55:22+13:00 (23 years ago)
Author:
sjboddie
Message:

Fixed some trouble with the get_date() function that showed up on windows

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/lib/gsdltimes.cpp

    r1779 r1785  
    117117}
    118118
    119 // returns current date and time formatted like "Thu Dec 7 23:43:38 GMT 2000"
     119// returns current date and time formatted like "Thu Dec 07 23:43:38 GMT 2000"
    120120// if ltime is true return value will be expressed in local time, otherwise
    121 // it'll be Coordinated Universal Time (UTC)
     121// it'll be Coordinated Universal Time (UTC) - no promises are made that the
     122// resulting string will be formatted exactly as expected, especially on windows
    122123// returns "" if an error occurs
    123124text_t get_date (bool ltime) {
    124125
    125   char *timestr = new char[128];
    126126  tm *tm_ptr = NULL;
    127127  time_t t = time(NULL);
     
    129129  else tm_ptr = gmtime (&t);
    130130  if (tm_ptr == NULL) return "";
     131  char *timestr = new char[128];
     132  text_t ret;
    131133
    132   strftime (timestr, 128, "%a %b %e %T %Z %Y", tm_ptr);
    133   text_t ret = timestr;
     134  // we do this in such an ugly way because windows is kind of flakey when
     135  // it comes to timezones
     136  if (ltime) {
     137    strftime (timestr, 128, "%a %b %d %H:%M:%S %z %Y", tm_ptr);
     138    ret.setcstr (timestr);
     139  } else {
     140    strftime (timestr, 128, "%a %b %d %H:%M:%S", tm_ptr);
     141    ret.setcstr (timestr);
     142    ret += " GMT ";
     143    strftime (timestr, 128, "%Y", tm_ptr);
     144    ret += timestr;
     145  }
     146
    134147  delete timestr;
    135148  return ret;
Note: See TracChangeset for help on using the changeset viewer.