Subject: lib/2257: strftime gives wrong week number with %V format
To: None <gnats-bugs@NetBSD.ORG>
From: Tor Egge <tegge@idt.unit.no>
List: netbsd-bugs
Date: 03/25/1996 00:28:08
>Number:         2257
>Category:       lib
>Synopsis:       strftime gives wrong week number with %V format
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people (Library Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Mar 24 18:50:01 1996
>Last-Modified:
>Originator:     Tor Egge <tegge@idt.unit.no>
>Organization:
	Norwegian Institute of Science and Technology   (NTNU)
>Release:        current as of Mar 19 1996
>Environment:
	
System: NetBSD ikke.idt.unit.no 1.1B NetBSD 1.1B (TEGGE) #1: Tue Mar 19 20:00:47 MET 1996 root@ikke.idt.unit.no:/usr/src/sys/arch/i386/compile/TEGGE i386


>Description:
	Some years the week number is off by 1 with the %V format in
	strftime.

	The code unfortunately checks for how many days	the year has before the
	first Saturday (5 in 1996), instead of how many days the year has
	before the first Monday (0 in 1996).

>How-To-Repeat:
	/bin/date +%V
	/bin/date +%W

	Since January 1st 1996 is on a Monday, they should give the
	same result.
>Fix:
	Apply this patch.
*** /usr/src/lib/libc/string/strftime.c.orig	Sun Mar 24 23:20:59 1996
--- usr/src/lib/libc/string/strftime.c	Sun Mar 24 23:22:03 1996
***************
*** 216,222 ****
  				 
  				int week = MON_WEEK(t);
  
! 				if (((t->tm_yday + 7 - (t->tm_wday + 1)) % 7) >= 4) {
  					week++;
  				} else if (week == 0) {
  					week = 53;
--- 216,222 ----
  				 
  				int week = MON_WEEK(t);
  
! 				if (((t->tm_yday + 7 - (t->tm_wday - 1)) % 7) >= 4) {
  					week++;
  				} else if (week == 0) {
  					week = 53;

>Audit-Trail:
>Unformatted: