summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-04-05 23:33:09 +0000
committerJim Meyering <jim@meyering.net>1996-04-05 23:33:09 +0000
commitc1505fc01f46bdb0e4f6e719a05b7cccf40c53e2 (patch)
treeb601aed430c6eb5febc47294e4fde9b682c36b65
parentcca1377d965dc0206e501233fe69b837b4d5cdbc (diff)
downloadcoreutils-c1505fc01f46bdb0e4f6e719a05b7cccf40c53e2.tar.xz
(sun_week): Make %U work properly.
Before, `date -d '1 Jan 1995' +%U' output `00'. Now it prints `01'.
-rw-r--r--lib/strftime.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/strftime.c b/lib/strftime.c
index e6b0c5a47..5cf5f0d17 100644
--- a/lib/strftime.c
+++ b/lib/strftime.c
@@ -242,13 +242,12 @@ sun_week (tm)
{
int dl;
- /* Set `dl' to the day in the year of the last day of the week previous
- to the one containing the day specified in TM. If the day specified
- in TM is in the first week of the year, `dl' will be negative or 0.
- Otherwise, calculate the number of complete weeks before our week
- (dl / 7) and add any partial week at the start of the year (dl % 7). */
+ /* %U Week of the year (Sunday as the first day of the week) as a decimal
+ number [00-53]. All days in a new year preceding the first Sunday are
+ considered to be in week 0. */
+
dl = tm->tm_yday - tm->tm_wday;
- return dl <= 0 ? 0 : dl / 7 + (dl % 7 != 0);
+ return dl < 0 ? 0 : dl / 7 + 1;
}
/* Return the week in the year of the time in TM, with the weeks