Skip to content

Commit 7b09c45

Browse files
committed
Merge branch 'jk/date-local'
"git log --date=local" used to only show the normal (default) format in the local timezone. The command learned to take 'local' as an instruction to use the local timezone with other formats, e.g. "git show --date=rfc-local". * jk/date-local: t6300: add tests for "-local" date formats t6300: make UTC and local dates different date: make "local" orthogonal to date format date: check for "local" before anything else t6300: add test for "raw" date format t6300: introduce test_date() helper fast-import: switch crash-report date to iso8601 Documentation/rev-list: don't list date formats Documentation/git-for-each-ref: don't list date formats Documentation/config: don't list date formats Documentation/blame-options: don't list date formats
2 parents 297ae71 + 99264e9 commit 7b09c45

File tree

10 files changed

+166
-114
lines changed

10 files changed

+166
-114
lines changed

Documentation/blame-options.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ include::line-range-format.txt[]
6363
`-` to make the command read from the standard input).
6464

6565
--date <format>::
66-
The value is one of the following alternatives:
67-
{relative,local,default,iso,rfc,short}. If --date is not
66+
Specifies the format used to output dates. If --date is not
6867
provided, the value of the blame.date config variable is
6968
used. If the blame.date config variable is also not set, the
70-
iso format is used. For more information, See the discussion
69+
iso format is used. For supported values, see the discussion
7170
of the --date option at linkgit:git-log[1].
7271

7372
-M|<num>|::

Documentation/config.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,9 +1829,7 @@ log.abbrevCommit::
18291829
log.date::
18301830
Set the default date-time mode for the 'log' command.
18311831
Setting a value for log.date is similar to using 'git log''s
1832-
`--date` option. Possible values are `relative`, `local`,
1833-
`default`, `iso`, `rfc`, and `short`; see linkgit:git-log[1]
1834-
for details.
1832+
`--date` option. See linkgit:git-log[1] for details.
18351833

18361834
log.decorate::
18371835
Print out the ref names of any commits that are shown by the log

Documentation/git-for-each-ref.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ the object referred by the ref does not cause an error. It
150150
returns an empty string instead.
151151

152152
As a special case for the date-type fields, you may specify a format for
153-
the date by adding one of `:default`, `:relative`, `:short`, `:local`,
154-
`:iso8601`, `:rfc2822` or `:raw` to the end of the fieldname; e.g.
155-
`%(taggerdate:relative)`.
153+
the date by adding `:` followed by date format name (see the
154+
values the `--date` option to linkgit::git-rev-list[1] takes).
156155

157156

158157
EXAMPLES

Documentation/git-rev-list.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ SYNOPSIS
4545
[ --regexp-ignore-case | -i ]
4646
[ --extended-regexp | -E ]
4747
[ --fixed-strings | -F ]
48-
[ --date=(local|relative|default|iso|iso-strict|rfc|short) ]
48+
[ --date=<format>]
4949
[ [ --objects | --objects-edge | --objects-edge-aggressive ]
5050
[ --unpacked ] ]
5151
[ --pretty | --header ]

Documentation/rev-list-options.txt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -701,15 +701,19 @@ include::pretty-options.txt[]
701701
--relative-date::
702702
Synonym for `--date=relative`.
703703

704-
--date=(relative|local|default|iso|iso-strict|rfc|short|raw)::
704+
--date=<format>::
705705
Only takes effect for dates shown in human-readable format, such
706706
as when using `--pretty`. `log.date` config variable sets a default
707-
value for the log command's `--date` option.
707+
value for the log command's `--date` option. By default, dates
708+
are shown in the original time zone (either committer's or
709+
author's). If `-local` is appended to the format (e.g.,
710+
`iso-local`), the user's local time zone is used instead.
708711
+
709712
`--date=relative` shows dates relative to the current time,
710-
e.g. ``2 hours ago''.
713+
e.g. ``2 hours ago''. The `-local` option cannot be used with
714+
`--raw` or `--relative`.
711715
+
712-
`--date=local` shows timestamps in user's local time zone.
716+
`--date=local` is an alias for `--date=default-local`.
713717
+
714718
`--date=iso` (or `--date=iso8601`) shows timestamps in a ISO 8601-like format.
715719
The differences to the strict ISO 8601 format are:
@@ -732,10 +736,15 @@ format, often found in email messages.
732736
`--date=format:...` feeds the format `...` to your system `strftime`.
733737
Use `--date=format:%c` to show the date in your system locale's
734738
preferred format. See the `strftime` manual for a complete list of
735-
format placeholders.
739+
format placeholders. When using `-local`, the correct syntax is
740+
`--date=format-local:...`.
736741
+
737-
`--date=default` shows timestamps in the original time zone
738-
(either committer's or author's).
742+
`--date=default` is the default format, and is similar to
743+
`--date=rfc2822`, with a few exceptions:
744+
745+
- there is no comma after the day-of-week
746+
747+
- the time zone is omitted when the local time zone is used
739748

740749
ifdef::git-rev-list[]
741750
--header::

builtin/blame.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
26002600
fewer display columns. */
26012601
blame_date_width = utf8_strwidth(_("4 years, 11 months ago")) + 1; /* add the null */
26022602
break;
2603-
case DATE_LOCAL:
26042603
case DATE_NORMAL:
26052604
blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
26062605
break;

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,14 +1091,14 @@ struct date_mode {
10911091
DATE_NORMAL = 0,
10921092
DATE_RELATIVE,
10931093
DATE_SHORT,
1094-
DATE_LOCAL,
10951094
DATE_ISO8601,
10961095
DATE_ISO8601_STRICT,
10971096
DATE_RFC2822,
10981097
DATE_STRFTIME,
10991098
DATE_RAW
11001099
} type;
11011100
const char *strftime_fmt;
1101+
int local;
11021102
};
11031103

11041104
/*

date.c

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ struct date_mode *date_mode_from_type(enum date_mode_type type)
166166
if (type == DATE_STRFTIME)
167167
die("BUG: cannot create anonymous strftime date_mode struct");
168168
mode.type = type;
169+
mode.local = 0;
169170
return &mode;
170171
}
171172

@@ -174,6 +175,9 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
174175
struct tm *tm;
175176
static struct strbuf timebuf = STRBUF_INIT;
176177

178+
if (mode->local)
179+
tz = local_tzoffset(time);
180+
177181
if (mode->type == DATE_RAW) {
178182
strbuf_reset(&timebuf);
179183
strbuf_addf(&timebuf, "%lu %+05d", time, tz);
@@ -189,9 +193,6 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
189193
return timebuf.buf;
190194
}
191195

192-
if (mode->type == DATE_LOCAL)
193-
tz = local_tzoffset(time);
194-
195196
tm = time_to_tm(time, tz);
196197
if (!tm) {
197198
tm = time_to_tm(0, 0);
@@ -232,7 +233,7 @@ const char *show_date(unsigned long time, int tz, const struct date_mode *mode)
232233
tm->tm_mday,
233234
tm->tm_hour, tm->tm_min, tm->tm_sec,
234235
tm->tm_year + 1900,
235-
(mode->type == DATE_LOCAL) ? 0 : ' ',
236+
mode->local ? 0 : ' ',
236237
tz);
237238
return timebuf.buf;
238239
}
@@ -770,31 +771,50 @@ int parse_date(const char *date, struct strbuf *result)
770771
return 0;
771772
}
772773

774+
static enum date_mode_type parse_date_type(const char *format, const char **end)
775+
{
776+
if (skip_prefix(format, "relative", end))
777+
return DATE_RELATIVE;
778+
if (skip_prefix(format, "iso8601-strict", end) ||
779+
skip_prefix(format, "iso-strict", end))
780+
return DATE_ISO8601_STRICT;
781+
if (skip_prefix(format, "iso8601", end) ||
782+
skip_prefix(format, "iso", end))
783+
return DATE_ISO8601;
784+
if (skip_prefix(format, "rfc2822", end) ||
785+
skip_prefix(format, "rfc", end))
786+
return DATE_RFC2822;
787+
if (skip_prefix(format, "short", end))
788+
return DATE_SHORT;
789+
if (skip_prefix(format, "default", end))
790+
return DATE_NORMAL;
791+
if (skip_prefix(format, "raw", end))
792+
return DATE_RAW;
793+
if (skip_prefix(format, "format", end))
794+
return DATE_STRFTIME;
795+
796+
die("unknown date format %s", format);
797+
}
798+
773799
void parse_date_format(const char *format, struct date_mode *mode)
774800
{
775-
if (!strcmp(format, "relative"))
776-
mode->type = DATE_RELATIVE;
777-
else if (!strcmp(format, "iso8601") ||
778-
!strcmp(format, "iso"))
779-
mode->type = DATE_ISO8601;
780-
else if (!strcmp(format, "iso8601-strict") ||
781-
!strcmp(format, "iso-strict"))
782-
mode->type = DATE_ISO8601_STRICT;
783-
else if (!strcmp(format, "rfc2822") ||
784-
!strcmp(format, "rfc"))
785-
mode->type = DATE_RFC2822;
786-
else if (!strcmp(format, "short"))
787-
mode->type = DATE_SHORT;
788-
else if (!strcmp(format, "local"))
789-
mode->type = DATE_LOCAL;
790-
else if (!strcmp(format, "default"))
791-
mode->type = DATE_NORMAL;
792-
else if (!strcmp(format, "raw"))
793-
mode->type = DATE_RAW;
794-
else if (skip_prefix(format, "format:", &format)) {
795-
mode->type = DATE_STRFTIME;
796-
mode->strftime_fmt = xstrdup(format);
797-
} else
801+
const char *p;
802+
803+
/* historical alias */
804+
if (!strcmp(format, "local"))
805+
format = "default-local";
806+
807+
mode->type = parse_date_type(format, &p);
808+
mode->local = 0;
809+
810+
if (skip_prefix(p, "-local", &p))
811+
mode->local = 1;
812+
813+
if (mode->type == DATE_STRFTIME) {
814+
if (!skip_prefix(p, ":", &p))
815+
die("date format missing colon separator: %s", format);
816+
mode->strftime_fmt = xstrdup(p);
817+
} else if (*p)
798818
die("unknown date format %s", format);
799819
}
800820

fast-import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ static void write_crash_report(const char *err)
424424
fprintf(rpt, "fast-import crash report:\n");
425425
fprintf(rpt, " fast-import process: %"PRIuMAX"\n", (uintmax_t) getpid());
426426
fprintf(rpt, " parent process : %"PRIuMAX"\n", (uintmax_t) getppid());
427-
fprintf(rpt, " at %s\n", show_date(time(NULL), 0, DATE_MODE(LOCAL)));
427+
fprintf(rpt, " at %s\n", show_date(time(NULL), 0, DATE_MODE(ISO8601)));
428428
fputc('\n', rpt);
429429

430430
fputs("fatal: ", rpt);

0 commit comments

Comments
 (0)