Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -1221,8 +1221,12 @@ PHPAPI char *php_format_date(char *format, int format_len, time_t ts, int localt
timelib_time *t;
timelib_tzinfo *tzi;
char *string;
struct timeval tv;

gettimeofday(&tv, NULL);

t = timelib_time_ctor();
t->f = tv.tv_usec/1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is right. With this patch, f will always be initialized with current time's milliseconds, even if formatting string provides other time.


if (localtime) {
tzi = get_timezone_info(TSRMLS_C);
Expand Down Expand Up @@ -2541,6 +2545,7 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str,
int type = TIMELIB_ZONETYPE_ID, new_dst = 0;
char *new_abbr = NULL;
timelib_sll new_offset;
struct timeval tv;

if (dateobj->time) {
timelib_time_dtor(dateobj->time);
Expand Down Expand Up @@ -2603,8 +2608,11 @@ PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str,
now->tz_abbr = new_abbr;
break;
}
gettimeofday(&tv, NULL);
timelib_unixtime2local(now, (timelib_sll) time(NULL));

now->f = tv.tv_usec/1000;

timelib_fill_holes(dateobj->time, now, TIMELIB_NO_CLONE);
timelib_update_ts(dateobj->time, tzi);

Expand Down