Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:6702 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37513 invoked by uid 1010); 23 Dec 2003 13:42:35 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 37423 invoked from network); 23 Dec 2003 13:42:35 -0000 Received: from unknown (HELO mailbomber.kirowski.com) (195.228.44.26) by pb1.pair.com with SMTP; 23 Dec 2003 13:42:35 -0000 Received: from localhost (localhost [127.0.0.1]) by localhost (Postfix) with ESMTP id 571B286F97 for ; Tue, 23 Dec 2003 14:42:33 +0100 (CET) Received: from mailbomber.kirowski.com ([127.0.0.1]) by localhost (mailbomber [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 21413-11 for ; Tue, 23 Dec 2003 14:42:27 +0100 (CET) Received: from Bazso.kiro.z (dmz-gw.kirowski.com [195.228.44.25]) by mailbomber.kirowski.com (Postfix) with ESMTP id 6E9D486F51 for ; Tue, 23 Dec 2003 14:42:27 +0100 (CET) To: internals@lists.php.net Content-Type: multipart/mixed; boundary="=-7CeWSZte3b8pxayCa1Mu" Message-ID: <1072186947.3443.13.camel@bazso> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 (1.4.5-2) Date: Tue, 23 Dec 2003 14:42:27 +0100 X-Virus-Scanned: by amavisd-new-20030616-p5 Subject: new format character in date function From: zsolt.banyai@kirowski.com (=?ISO-8859-1?Q?B=E1nyai?= Zsolt) --=-7CeWSZte3b8pxayCa1Mu Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi, I usually have to work with dates and i miss a date format character wich returns year of the week. I'm not a C developer, i could just play with it in datetime.c, but i send the patch file, please check this and if you are interest in it, use in the future. About the working: in case 01/01/2003 returns 2003 in case 31/12/2003 returns 2004 the format character is X. thanks zsolt banyai [bazso] kirowski rt. hungary --=-7CeWSZte3b8pxayCa1Mu Content-Disposition: attachment; filename=datetime.c.diff Content-Type: text/x-patch; name=datetime.c.diff; charset=iso-8859-2 Content-Transfer-Encoding: 7bit --- datetime.c.old 2003-12-16 23:52:47.000000000 +0100 +++ datetime.c 2003-12-23 14:25:36.000000000 +0100 @@ -361,6 +361,9 @@ case 'Y': /* year, numeric, 4 digits */ size += 4; break; + case 'X': + size += 4; /* Year of The Weeek, numeric, 4 digits */ + break; case 'M': /* month, textual, 3 letters */ case 'D': /* day, textual, 3 letters */ case 'z': /* day of the year, 1 to 366 */ @@ -428,6 +431,31 @@ sprintf(tmp_buff, "%d", ta->tm_year + YEAR_BASE); /* SAFE */ strcat(Z_STRVAL_P(return_value), tmp_buff); break; + case 'X': + wd = ta->tm_wday == 0 ? 6 : ta->tm_wday - 1; /* weekday */ + yd = ta->tm_yday + 1; /* days since January 1st */ + + fd = (7 + wd - yd % 7+ 1) % 7; /* weekday (1st January) */ + + /* week is a last year week (52 or 53) */ + if ((yd <= 7 - fd) && fd > 3){ + wk = (fd == 4 || (fd == 5 && isleap((ta->tm_year + YEAR_BASE - 1)))) ? 53 : 52; + sprintf(tmp_buff, "%d", ta->tm_year + YEAR_BASE - 1 ); /* SAFE */ + } + /* week is a next year week (1) */ + else if (isleap((ta->tm_year+YEAR_BASE)) + 365 - yd < 3 - wd){ + wk = 1; + sprintf(tmp_buff, "%d", ta->tm_year + YEAR_BASE + 1); /* SAFE */ + } + /* normal week */ + else { + wk = (yd + 6 - wd + fd) / 7 - (fd > 3); + sprintf(tmp_buff, "%d", ta->tm_year + YEAR_BASE); /* SAFE */ + } + + strcat(Z_STRVAL_P(return_value), tmp_buff); + break; + case 'M': /* month, textual, 3 letters */ strcat(Z_STRVAL_P(return_value), mon_short_names[ta->tm_mon]); break; --=-7CeWSZte3b8pxayCa1Mu--