Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:68029 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46898 invoked from network); 2 Jul 2013 07:22:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Jul 2013 07:22:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=simonsimcity@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=simonsimcity@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.46 as permitted sender) X-PHP-List-Original-Sender: simonsimcity@gmail.com X-Host-Fingerprint: 74.125.82.46 mail-wg0-f46.google.com Received: from [74.125.82.46] ([74.125.82.46:39965] helo=mail-wg0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 48/64-09174-B9F72D15 for ; Tue, 02 Jul 2013 03:22:03 -0400 Received: by mail-wg0-f46.google.com with SMTP id c11so4382991wgh.13 for ; Tue, 02 Jul 2013 00:22:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Bb+lx3Nrtvs5LXPOTvEeLUu5j4GTU80gJyOmqzIc/D8=; b=Aip3h8oYJQy1D6FaUOapy1B/QHGs5qM+wPOZHOFDQheHJb7EVrQmJ+vOsfKFU8t0sw KMt4YuGgpe10sRqO3FtCIessTL2eJyFsgb7kvarpajhUTPXKIg0IP30bpUh1B2gdXuJF h0XZlaVUPUBFAlOviuDji2UZLfj+4njf01ruF5B/pk2mEs6WoIc7RvUzrIFxcvTeThu3 kWYkj51FrE73oqoNDrpf/31XxTD7a5PBmcxHrZAF654JKJvWBbLkFoZpKE7sTde5456Z LwdYYqyM0q/zg3a/MIs6zcLrbSwAwowFzz7hxzyvpsQIRZl6H7eTC2QkjtYtyM92CKRI TSmQ== MIME-Version: 1.0 X-Received: by 10.180.207.43 with SMTP id lt11mr14292239wic.57.1372749719998; Tue, 02 Jul 2013 00:21:59 -0700 (PDT) Received: by 10.194.63.200 with HTTP; Tue, 2 Jul 2013 00:21:59 -0700 (PDT) In-Reply-To: References: Date: Tue, 2 Jul 2013 09:21:59 +0200 Message-ID: To: Derick Rethans Cc: PHP Internals List Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Adding a time interval to an interval From: simonsimcity@gmail.com (Simon Schick) On Fri, Jun 28, 2013 at 11:20 PM, Derick Rethans wrote: > > Hey Simon, > > PS, please don't top-reply as per mailinglist guidelines: > http://us2.php.net/reST/README.MAILINGLIST_RULES > > On Fri, 28 Jun 2013, Simon Schick wrote: > > On Fri, Jun 28, 2013 at 7:10 PM, Derick Rethans wrote: > > > > > On Fri, 28 Jun 2013, Simon Schick wrote: > > > > > > > I'd like to extend the API of php by a method. > > > > > > Great, let me know if you need any help with the implementation, or > > > when you have any questions on how it currently works. > > > > Sorry - I that was easy to missunderstand ;) I thought of providing > > the idea. But I would happily also try to implement it by my own - > > just to also have contributed to the php-core. If you could give me a > > hint where to start - I feel quite lost in the code right now ... even > > so I read the great tutorials about php-internals provided by Anthony > > Ferrara. > > > > And this may take some time! I've just started with C/C++. > > > > Do you think this is an easy task to start? Depending on knowledge of > > php-internals ;) > > It's not that difficult, but not the easiest thing either. Basically, > you have to do the following steps: > > 1. in ext/date/lib/interval.c add a function that has two arguments of > the timelib_rel_time* type. It should return a *new* > timelib_rel_time* structure that has the two intervals added up > together. It shouldn't change either of the original > timelib_rel_time* arguments. Add the function definition to > ext/date/lib/timelib.h too. > 2. You can only add two timelib_rel_time* arguments if neither of > first_last_day_of, special, have_weekday_relative, and > have_special_relative are set. You can'd add a "first day of next > month" to a "+5 days" interval - it only works for simple y:m:d h:i:s > intervals. > 3. In ext/date/php_date.c add: > > a. a new ARG_INFO struct after the one for > arginfo_date_interval_construct, > b. Add a new method, "add" after > PHP_ME_MAPPING(createFromDateString, date_interval_create_from_date_string,... > c. Add a new PHP_FUNCTION(date_interval_add) after the function > PHP_FUNCTION(date_interval_format) that takes two DateInterval > objects, extract the timelib_rel_time information, call the new > function that you've added in step 1, and replace the > timelib_rel_time* that is part of the DateInterval object with the > returned value. > d. Add a forwards declaration to php_date.h after > PHP_FUNCTION(date_interval_create_from_date_string); > > 4. Make sure that the function can be called both as a procedural way > (date_interval_add) and an object oriented way (DateInterval->add()). > > 5. Write test cases and put them in ext/date/tests. > > That's what I can think off right now. > > cheers, > Derick > > > > -- > http://derickrethans.nl | http://xdebug.org > Like Xdebug? Consider a donation: http://xdebug.org/donate.php > twitter: @derickr and @xdebug > Posted with an email client that doesn't mangle email: alpine Hi, Derick I thought a bit about the changes here and came up with the following feedback: If I can't add intervals where either one is relative, I'd also add a method isRelative() to the class, where the user can check if it's a relative interval. But anyways - what happens if the interval is relative and you try to access one of the public properties? They're all designed for static intervals (let's say +5days), right? What, if the user tries to add a relative to a fixed interval? Should I trigger a E_WARNING, because it's no breaking error, but the value can't be calculated? Bye, Simon