All pastes #926927 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-03-03 22:24 UTC
rendered paste body
Hello,

On Wed, 27 Feb 2008, Kirti Velankar wrote:

> I work on a php extension pecl/intl, to be specific currently on
> DateFormatter . Being relatively new to the PHP world ,  I am having
> difficulty in using the PHP objects DateTime and TimeZone in the
> extension implementation.
> 
> My understanding is that only code exposed  by PHPAPI functions in one
> extension is available for use (by including the header file) in another
> extension. Is this correct?

Yes, mostly. But because ext/date/lib is part of every build, I don't 
think that the PHPAPI part needs to be there and that you can just use 
the functions in the lib after including the header.

> Roughly I need to do the following in the DateFormatter :
> 
> 1)Creating these objects

DateTime objects you mean? You can use date_instantiate() for this. You 
would need to initialize those objects still though, with something like 
date_initialize()

> 2)TimeZone object as a member of the DateFormatter object.

I don't know how DateFormatter works, but the DateTimeZone object is 
also linked to a DateTime object in some cases. As this is similar, you 
can have a look at how this is done. (See 
PHP_FUNCTION(date_timezone_set)

> 3)convert data from int/string to unix timestamp or vice versa for 
> these objects  as some DateFormatter methods accept these objects as
> parameters

those functions are defined in ext/date/lib/timelib.h.

>From int/string to unix TS you would need timelib_strtotime(), 
timelib_fill_holes() and timelib_update_ts().

>From TS to string, php_format_date()

However, it is not really a good idea to convert them to an integer, as 
this loses Timezone information. In that case, it might be better to use 
unixtime2locale() and use the broken up time that that uses.

> And when I looked at ext/date , it does not have PHPAPI functions for
> the above or some of them. So was wondering how I should go about it.

Well, if you are really sure you need PHPAPI in front of the functions, 
let me know -- we can add it then. It would be a bit tricker for the 
functions in ext/date/lib as they also need to build outside of PHP, and 
thus we can't use PHPAPI for this.

> DateFormatter Spec. (First Draft)
> http://www.inter-locale.com/php/datefmt_api.php.txt

I can't resolve that domain name. But what I was wondering... why wasn't 
there any work done integrating some of this functionality into ext/date?

regards,
Derick