-
Notifications
You must be signed in to change notification settings - Fork 208
PHPC-536: UTCDateTime construction from DateTime or current time #336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Sorry for my programming ignorance, but I noticed that you were using |
/* Initialize UTCDateTime from current time */ | ||
struct timeval cur_time; | ||
|
||
gettimeofday(&cur_time, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Windows doesn't have gettimeofday
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered the options in http://stackoverflow.com/q/10905892/162228, but then I found gettimeofday
and the necessary structs defined in win32/time.h
(going back to at least PHP 5.4). I also found evidence of that implementation being used in several core extensions.
The PHP implementation seems to be equivalent to the other solutions (i.e. it uses GetSystemTimeAsFileTime()
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
DateTimeInterface only exists in PHP 5.5, but we should be able to use that if it's available and fall back to DateTime for PHP 5.4. @derick: I noticed that
Can we get away with defining
Great idea. I'll work on getting these in and try to come up with some tests that exercise the range limits of PHP and BSON dates. |
@derickr: Regarding the Travis failure, that appears to be |
Sorry. That's just me forgetting that the driver is compatible back to 5.4. Being able to pass in |
No. This works on Linux, but won't work on Windows.
That sounds kinda crappy... I'd rather export the interface in PHP (from PHP 7.1). |
Of course it makes sense to start doing that in PHP 7.1, but |
found_ce = zend_fetch_class("DateTimeInterface", sizeof("DateTimeInterface")-1, ZEND_FETCH_CLASS_AUTO|ZEND_FETCH_CLASS_NO_AUTOLOAD|ZEND_FETCH_CLASS_SILENT TSRMLS_CC); | ||
#endif | ||
|
||
return found_ce ? found_ce : php_date_get_date_ce(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@derickr: Would it make sense to memoize this function by saving found_ce
in a static global? I also thought about initializing the constructors date_ce
in UTCDateTime's MINIT, but that assumes we are always initialized after PHP's date extension. I'd like to respect the edge case where that may not be true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add a dependency on it, and that should make PHP initialise datetime first. Instead of MINIT, I would put it in RINIT.
zend_restore_error_handling(&error_handling TSRMLS_CC); | ||
return; | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran into problems calling zend_fetch_class()
to get the class entry for DateTimeInterface during MINIT. This ultimately seemed an easier solution, which uses nothing more than the date extension's public API.
Meanwhile, I've opened PHPC-718 to ensure that we start listing our extension dependencies.
--SKIPIF-- | ||
<?php if (defined("HHVM_VERSION_ID")) exit("skip HHVM handles parameter parsing differently"); ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might have to put this one back in I suppose, if we find that it's still different with HHVM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it will be a problem. Your constructor accepts a mixed type and all validation is left to you, so it should be trivial to customize the exception message here.
LGTM |
Supported since ext-mongodb 1.2 mongodb/mongo-php-driver#336
Supported since ext-mongodb 1.2 mongodb/mongo-php-driver#336
https://jira.mongodb.org/browse/PHPC-536