It definitely would be, and that's actually the way I would have preferred
to do it. I didn't want to impact too much code, if that makes sense in
this case, but I'm glad that someone agrees :)
I have attached a patch to do exactly this.
Ilia
On Sat, Sep 27, 2008 at 1:40 AM, Alexey Zakhlestin <[EMAIL PROTECTED]>wrote:
> On Sat, Sep 27, 2008 at 11:04 AM, Ilia Cheishvili
> <[EMAIL PROTECTED]> wrote:
> > Hi all,
> > This patch addresses the issue with the date() function. When passing in
> a
> > 'u', the date() function simply outputs six zeros. To fix this, I added
> a
> > gettimeofday() call that figures out what to display for microseconds. I
> am
> > including the headers and using the function with pre-processor
> safeguards
> > as well.
> > Take a look :)
>
> Wouldn't it be better, to make gettimeofday() call only in case of 'u'?
>
>
> --
> Alexey Zakhlestin
> http://blog.milkfarmsoft.com/
>
Index: php_date.c
===================================================================
RCS file: /repository/php-src/ext/date/php_date.c,v
retrieving revision 1.43.2.45.2.51.2.54
diff -u -b -r1.43.2.45.2.51.2.54 php_date.c
--- php_date.c 8 Aug 2008 22:07:07 -0000 1.43.2.45.2.51.2.54
+++ php_date.c 27 Sep 2008 08:02:06 -0000
@@ -30,6 +30,14 @@
#include "zend_interfaces.h"
#include "lib/timelib.h"
#include <time.h>
+#ifdef PHP_WIN32
+#include "win32/time.h"
+#elif defined(NETWARE)
+#include <sys/timeval.h>
+#include <sys/time.h>
+#else
+#include <sys/time.h>
+#endif
/* {{{ arginfo */
static
@@ -1075,6 +1083,8 @@
timelib_time_offset *offset = NULL;
timelib_sll isoweek, isoyear;
int rfc_colon;
+ struct timeval tp = {0};
+ struct timezone tz = {0};
if (!format_len) {
return estrdup("");
@@ -1150,7 +1160,9 @@
case 'H': length = slprintf(buffer, 32, "%02d", (int)
t->h); break;
case 'i': length = slprintf(buffer, 32, "%02d", (int)
t->i); break;
case 's': length = slprintf(buffer, 32, "%02d", (int)
t->s); break;
- case 'u': length = slprintf(buffer, 32, "%06d", (int)
floor(t->f * 1000000)); break;
+#ifdef HAVE_GETTIMEOFDAY
+ case 'u': gettimeofday(&tp, &tz); length =
slprintf(buffer, 32, "%06d", (int) tp.tv_usec); break;
+#endif
/* timezone */
case 'I': length = slprintf(buffer, 32, "%d", localtime
? offset->is_dst : 0); break;
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php