1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* time.c: new method gmtoff', gmt_offset' and `utc_offset'.

(time_utc_offset): new function.
(Init_Time): bind above methods to `time_utc_offset'.

* time.c: 64bit time_t support.
(time_s_at): use NUM2LONG instead of NUM2INT for tv_sec.
(time_arg): initialize tm_isdst correctly.
use long to initialize tm_year.
(search_time_t): renamed from `make_time_t'.
(make_time_t): call `timegm' and `mktime' instead of `search_time_t'
if availabe.
(time_to_i): use LONG2NUM instead of INT2NUM.
(time_localtime): check localtime failure.
(time_gmtime): check gmtime failure.
(time_year): use LONG2NUM instead of INT2FIX.
(time_to_a): use long for tm_year.
(time_dump): check tm_year which is not representable with 17bit.
(time_load): initialize tm_isdst.

* configure.in: check existence of `mktime' and `timegm'.
check existence of tm_gmtoff field of struct tm.
fix negative time_t for 64bit time_t.

* missing/strftime.c: fix overflow by tm_year + 1900.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2001-12-17 06:45:37 +00:00
parent 39c0252e04
commit b48e38c526
4 changed files with 180 additions and 27 deletions

View file

@ -175,7 +175,8 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
char *start = s;
auto char tbuf[100];
long off;
int i, w, y;
int i, w;
long y;
static short first = 1;
#ifdef POSIX_SEMANTICS
static char *savetz = NULL;
@ -378,7 +379,7 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
break;
case 'Y': /* year with century */
sprintf(tbuf, "%d", 1900 + timeptr->tm_year);
sprintf(tbuf, "%ld", 1900L + timeptr->tm_year);
break;
#ifdef MAILHEADER_EXT
@ -503,10 +504,10 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
#ifdef VMS_EXT
case 'v': /* date as dd-bbb-YYYY */
sprintf(tbuf, "%2d-%3.3s-%4d",
sprintf(tbuf, "%2d-%3.3s-%4ld",
range(1, timeptr->tm_mday, 31),
months_a[range(0, timeptr->tm_mon, 11)],
timeptr->tm_year + 1900);
timeptr->tm_year + 1900L);
for (i = 3; i < 6; i++)
if (islower(tbuf[i]))
tbuf[i] = toupper(tbuf[i]);
@ -516,7 +517,7 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
#ifdef POSIX2_DATE
case 'C':
sprintf(tbuf, "%02d", (timeptr->tm_year + 1900) / 100);
sprintf(tbuf, "%02ld", (timeptr->tm_year + 1900L) / 100);
break;
@ -550,16 +551,16 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
*/
w = iso8601wknum(timeptr);
if (timeptr->tm_mon == 11 && w == 1)
y = 1900 + timeptr->tm_year + 1;
y = 1900L + timeptr->tm_year + 1;
else if (timeptr->tm_mon == 0 && w >= 52)
y = 1900 + timeptr->tm_year - 1;
y = 1900L + timeptr->tm_year - 1;
else
y = 1900 + timeptr->tm_year;
y = 1900L + timeptr->tm_year;
if (*format == 'G')
sprintf(tbuf, "%d", y);
sprintf(tbuf, "%ld", y);
else
sprintf(tbuf, "%02d", y % 100);
sprintf(tbuf, "%02ld", y % 100);
break;
#endif /* ISO_DATE_EXT */
default:
@ -590,10 +591,10 @@ out:
#ifndef __STDC__
static int
isleap(year)
int year;
long year;
#else
static int
isleap(int year)
isleap(long year)
#endif
{
return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
@ -684,7 +685,7 @@ iso8601wknum(const struct tm *timeptr)
dec31ly.tm_mon = 11;
dec31ly.tm_mday = 31;
dec31ly.tm_wday = (jan1day == 0) ? 6 : jan1day - 1;
dec31ly.tm_yday = 364 + isleap(dec31ly.tm_year + 1900);
dec31ly.tm_yday = 364 + isleap(dec31ly.tm_year + 1900L);
weeknum = iso8601wknum(& dec31ly);
#endif
}