Bug 16182

Summary: Y#K of tm_year returned by localtime()
Product: Base System Reporter: Jin Guojun <jin>
Component: miscAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description Jin Guojun 2000-01-18 18:40:01 UTC
% ll Makefile
-rw-r--r--  1 jin  2294 Jan 18 09:59 Makefile

	stat(file_name, &f_stat);
	ftm = localtime(&f_stat.st_mtime);

(xxgdb) print *ftm
$3 = {
  tm_sec = 22, 
  tm_min = 44, 
  tm_hour = 9, 
  tm_mday = 18, 
  tm_mon = 0, 
  tm_year = 100, 
  tm_wday = 2, 
  tm_yday = 17, 
  tm_isdst = 0, 
  tm_gmtoff = -28800, 
  tm_zone = 0x20158f30 "PST"
}

Fix: 

Question:
	Shall we set the tm_year value to four digits by adding 1900?
	or Is the user resposible to add 1900 to the tm_year in program?
Comment 1 Ruslan Ermilov 2000-01-18 18:55:42 UTC
On Tue, Jan 18, 2000 at 10:33:22AM -0800, Jin Guojun wrote:
> 
> >Number:         16182
> >Category:       misc
> >Synopsis:       Y#K of tm_year returned by localtime()
> >Severity:       serious
> >Release:        FreeBSD 3.4-20000104-STABLE i386
> 
[...]
> >Description:
> 
> % ll Makefile
> -rw-r--r--  1 jin  2294 Jan 18 09:59 Makefile
> 
> 	stat(file_name, &f_stat);
> 	ftm = localtime(&f_stat.st_mtime);
> 
> (xxgdb) print *ftm
> $3 = {
>   tm_sec = 22, 
>   tm_min = 44, 
>   tm_hour = 9, 
>   tm_mday = 18, 
>   tm_mon = 0, 
>   tm_year = 100, 
>   tm_wday = 2, 
>   tm_yday = 17, 
>   tm_isdst = 0, 
>   tm_gmtoff = -28800, 
>   tm_zone = 0x20158f30 "PST"
> }
> 
Read the ctime(3) manpage:
[...]
	   int tm_mday;    /* day of month (1 - 31) */
	   int tm_mon;	   /* month of year (0 - 11) */
	   int tm_year;    /* year - 1900 */
	   int tm_wday;    /* day of week (Sunday = 0) */
	   int tm_yday;    /* day of year (0 - 365) */
[...]

> >Fix:
> 	
> 	Question:
> 	Shall we set the tm_year value to four digits by adding 1900?
> 	or Is the user resposible to add 1900 to the tm_year in program?
> 
The PR system is probably not a good place to ask questions.

-- 
Ruslan Ermilov		Sysadmin and DBA of the
ru@ucb.crimea.ua	United Commercial Bank,
ru@FreeBSD.org		FreeBSD committer,
+380.652.247.647	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age
Comment 2 mph freebsd_committer freebsd_triage 2000-01-18 19:31:14 UTC
State Changed
From-To: open->closed

Correctly written software adds 1900 to tm_year to obtain a four-digit 
year.  Changing localtime(3) in the way you describe will break all 
existing correctly-written software with no benefit.