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 :)
Thanks!
Ilia
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 06:58:51 -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
@@ -1076,6 +1084,14 @@
timelib_sll isoweek, isoyear;
int rfc_colon;
+#ifdef HAVE_GETTIMEOFDAY
+ struct timeval tp = {0};
+ struct timezone tz = {0};
+
+ gettimeofday(&tp, &tz);
+ t->f = (double) tp.tv_usec / MICROSECONDS_PER_SECOND;
+#endif
+
if (!format_len) {
return estrdup("");
}
@@ -1150,7 +1166,7 @@
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;
+ case 'u': length = slprintf(buffer, 32, "%06d", (int)
floor(t->f * MICROSECONDS_PER_SECOND)); break;
/* timezone */
case 'I': length = slprintf(buffer, 32, "%d", localtime
? offset->is_dst : 0); break;
Index: php_date.h
===================================================================
RCS file: /repository/php-src/ext/date/php_date.h,v
retrieving revision 1.17.2.11.2.3.2.9
diff -u -b -r1.17.2.11.2.3.2.9 php_date.h
--- php_date.h 18 Jul 2008 14:33:53 -0000 1.17.2.11.2.3.2.9
+++ php_date.h 27 Sep 2008 06:58:51 -0000
@@ -128,4 +128,6 @@
PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb);
PHPAPI timelib_tzinfo *get_timezone_info(TSRMLS_D);
+#define MICROSECONDS_PER_SECOND 1000000
+
#endif /* PHP_DATE_H */
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php