Message-ID: <20020401164728.15729.qmail@plover.com> To: perl5-porters@perl.org Subject: [PATCH 5.7.3] Enhancement to core time functions Organization: Plover Systems Date: Mon, 01 Apr 2002 11:47:28 -0500 From: Mark-Jason Dominus --- pod/perlfunc.pod 2002/04/01 15:55:43 1.1 +++ pod/perlfunc.pod 2002/04/01 16:24:33 @@ -2411,12 +2411,12 @@ =item localtime EXPR -Converts a time as returned by the time function to a 9-element list +Converts a time as returned by the time function to a 10-element list with the time analyzed for the local time zone. Typically used as follows: - # 0 1 2 3 4 5 6 7 8 - ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = + # 0 1 2 3 4 5 6 7 8 9 + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst,$seas) = localtime(time); All list elements are numeric, and come straight out of the C `struct @@ -2428,7 +2428,10 @@ 0 indicating Sunday and 3 indicating Wednesday. $yday is the day of the year, in the range C<0..364> (or C<0..365> in leap years.) $isdst is true if the specified time occurs during daylight savings time, -false otherwise. +false otherwise. $seas is the season, with 0 indicating winter, 1 +indicating spring, 2 indicating summer, and 3 indicating autumn. (In +the southern hemisphere, these values are offset by 2, so that 3 +indicates spring, etc.) Note that the $year element is I simply the last two digits of the year. If you assume it is, then you create non-Y2K-compliant --- pod/perldelta.pod 2002/04/01 15:59:25 1.1 +++ pod/perldelta.pod 2002/04/01 15:59:54 @@ -562,6 +562,10 @@ Use of C in substitutions, even with C, elicits C. +=item * + +The C and C functions now return the season. + =back =head1 Modules and Pragmata --- pp_sys.c 2002/04/01 15:36:21 1.1 +++ pp_sys.c 2002/04/01 15:59:09 @@ -4395,7 +4395,7 @@ static char *dayname[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; static char *monname[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - + if (MAXARG < 1) (void)time(&when); else @@ -4427,8 +4427,9 @@ PUSHs(sv_2mortal(tsv)); } else if (tmbuf) { - EXTEND(SP, 9); - EXTEND_MORTAL(9); + U32 season; + EXTEND(SP, 10); + EXTEND_MORTAL(10); PUSHs(sv_2mortal(newSViv(tmbuf->tm_sec))); PUSHs(sv_2mortal(newSViv(tmbuf->tm_min))); PUSHs(sv_2mortal(newSViv(tmbuf->tm_hour))); @@ -4438,6 +4439,29 @@ PUSHs(sv_2mortal(newSViv(tmbuf->tm_wday))); PUSHs(sv_2mortal(newSViv(tmbuf->tm_yday))); PUSHs(sv_2mortal(newSViv(tmbuf->tm_isdst))); + if (PL_op->op_type == OP_LOCALTIME) { + + if (tmbuf->tm_yday < 70) season = 0; + else if (tmbuf->tm_yday < 78) season = 1; + else if (tmbuf->tm_yday < 93) season = 0; + else if (tmbuf->tm_yday < 100) season = 1; + else if (tmbuf->tm_yday < 105) season = 0; + else if (tmbuf->tm_yday < 141) season = 1; + else if (tmbuf->tm_yday < 148) season = 2; + else if (tmbuf->tm_yday < 152) season = 1; + else if (tmbuf->tm_yday < 251) season = 2; + else if (tmbuf->tm_yday < 260) season = 3; + else if (tmbuf->tm_yday < 266) season = 2; + else if (tmbuf->tm_yday < 319) season = 3; + else if (tmbuf->tm_yday < 323) season = 0; + else if (tmbuf->tm_yday < 327) season = 3; + else season = 0; + + PUSHs(sv_2mortal(newSViv(season))); + } else { + + PUSHs(sv_2mortal(newSVpv("raining", 7))); + } } RETURN; } --- ext/POSIX/POSIX.xs 2002/04/01 16:08:37 1.1 +++ ext/POSIX/POSIX.xs 2002/04/01 16:09:36 @@ -1698,7 +1698,7 @@ # sv_setpv(TARG, ...) could be used rather than # ST(0) = sv_2mortal(newSVpv(...)) void -strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1) +strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1, seas = -1) char * fmt int sec int min @@ -1709,6 +1709,7 @@ int wday int yday int isdst + int seas CODE: { char *buf = my_strftime(fmt, sec, min, hour, mday, mon, year, wday, yday, isdst); --- ext/POSIX/POSIX.pod 2002/04/01 16:11:26 1.1 +++ ext/POSIX/POSIX.pod 2002/04/01 16:11:37 @@ -1214,7 +1214,7 @@ Synopsis: - strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1) + strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1, seas = -1) The month (C), weekday (C), and yearday (C) begin at zero. I.e. January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The