Skip to content

Commit

Permalink
date.c: add "show_date()" function.
Browse files Browse the repository at this point in the history
Kind of like ctime(), but not as broken.
  • Loading branch information
Linus Torvalds committed May 6, 2005
1 parent 5aad72f commit f80cd78
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions cache.h
Expand Up @@ -166,6 +166,7 @@ extern void *read_object_with_reference(const unsigned char *sha1,
unsigned long *size,
unsigned char *sha1_ret);

const char *show_date(unsigned long time, int timezone);
void parse_date(char *date, char *buf, int bufsize);
void datestamp(char *buf, int bufsize);

Expand Down
28 changes: 28 additions & 0 deletions date.c
Expand Up @@ -38,6 +38,34 @@ static const char *weekday_names[] = {
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
};

/*
* The "tz" thing is passed in as this strange "decimal parse of tz"
* thing, which means that tz -0100 is passed in as the integer -100,
* even though it means "sixty minutes off"
*/
const char *show_date(unsigned long time, int tz)
{
struct tm *tm;
time_t t;
static char timebuf[200];
int minutes;

minutes = tz < 0 ? -tz : tz;
minutes = (tz / 100)*60 + (tz % 100);
minutes = tz < 0 ? -minutes : minutes;
t = time - minutes * 60;
tm = gmtime(&t);
if (!tm)
return NULL;
sprintf(timebuf, "%.3s %.3s %d %02d:%02d:%02d %d %+05d",
weekday_names[tm->tm_wday],
month_names[tm->tm_mon],
tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec,
tm->tm_year + 1900, tz);
return timebuf;
}

/*
* Check these. And note how it doesn't do the summer-time conversion.
*
Expand Down

0 comments on commit f80cd78

Please sign in to comment.