~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-updates

« back to all changes in this revision

Viewing changes to date.c

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-04-22 13:31:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20070422133105-xg8fnm18r2cxcbg1
Tags: upstream-1.5.1.2
ImportĀ upstreamĀ versionĀ 1.5.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Copyright (C) Linus Torvalds, 2005
5
5
 */
6
6
 
7
 
#include <time.h>
8
 
#include <sys/time.h>
9
 
 
10
7
#include "cache.h"
11
8
 
12
9
static time_t my_mktime(struct tm *tm)
58
55
        return gmtime(&t);
59
56
}
60
57
 
61
 
const char *show_date(unsigned long time, int tz, int relative)
 
58
const char *show_date(unsigned long time, int tz, enum date_mode mode)
62
59
{
63
60
        struct tm *tm;
64
61
        static char timebuf[200];
65
62
 
66
 
        if (relative) {
 
63
        if (mode == DATE_RELATIVE) {
67
64
                unsigned long diff;
68
 
                time_t t = gm_time_t(time, tz);
69
65
                struct timeval now;
70
66
                gettimeofday(&now, NULL);
71
 
                if (now.tv_sec < t)
 
67
                if (now.tv_sec < time)
72
68
                        return "in the future";
73
 
                diff = now.tv_sec - t;
 
69
                diff = now.tv_sec - time;
74
70
                if (diff < 90) {
75
71
                        snprintf(timebuf, sizeof(timebuf), "%lu seconds ago", diff);
76
72
                        return timebuf;
109
105
        tm = time_to_tm(time, tz);
110
106
        if (!tm)
111
107
                return NULL;
112
 
        sprintf(timebuf, "%.3s %.3s %d %02d:%02d:%02d %d %+05d",
113
 
                weekday_names[tm->tm_wday],
114
 
                month_names[tm->tm_mon],
115
 
                tm->tm_mday,
116
 
                tm->tm_hour, tm->tm_min, tm->tm_sec,
117
 
                tm->tm_year + 1900, tz);
 
108
        if (mode == DATE_SHORT)
 
109
                sprintf(timebuf, "%04d-%02d-%02d", tm->tm_year + 1900,
 
110
                                tm->tm_mon + 1, tm->tm_mday);
 
111
        else
 
112
                sprintf(timebuf, "%.3s %.3s %d %02d:%02d:%02d %d %+05d",
 
113
                                weekday_names[tm->tm_wday],
 
114
                                month_names[tm->tm_mon],
 
115
                                tm->tm_mday,
 
116
                                tm->tm_hour, tm->tm_min, tm->tm_sec,
 
117
                                tm->tm_year + 1900, tz);
118
118
        return timebuf;
119
119
}
120
120