Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124172 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 9E3841A009C for ; Tue, 2 Jul 2024 06:23:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719901469; bh=itQgIOEK3x6ZJhB06NDnAN4VZT2Wo+217jmXqXN8apY=; h=In-Reply-To:References:Date:From:To:Subject:From; b=mz/QvEFXovlgpLRN3LMJtP4vVI3gQ5nAY5M5aro2rpUZNTkhguAd4Zbyrxs+A0Y08 gLx0apbOHByxpKEKla74C69iDBRdc+oCe3/e6O+hbBzDLjioAnTeqrf74TxkU54CLd AWL8otam1QkVjNPke1RfOs8Tw9QYL4InbPchaAppSpysiU30Y8hRxS0N/mwxJIYBP0 NvaKx8/mT9RVqz41kaQByznz+g+c8/1ejr5oUboW0M+1MSGfxugq8OdvOugxBGMXbK DjqVUXu50W+mqRh92OgNgwsrL/XLLxC34nEazMUY5Y31URqHNfG/X6sJYWyN80Ma85 TUaJBrC1D8AEA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3FF0E180072 for ; Tue, 2 Jul 2024 06:24:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 2 Jul 2024 06:24:27 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3E80F1140292 for ; Tue, 2 Jul 2024 02:23:06 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute1.internal (MEProxy); Tue, 02 Jul 2024 02:23:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1719901386; x=1719987786; bh=itQgIOEK3x 6ZJhB06NDnAN4VZT2Wo+217jmXqXN8apY=; b=i0wriiPRg+MlZj+hL8+I+tOIH/ /s0fg5OeMwo60u4//IIk4cscgWSFKOmmSOKliVqJ71ctvwoCE2ZofsSLOf9dH/v7 1x6fbiDv3+snnQJKD1tJB0O8t/3qVZR17QMw9ara/esifZLFLrpPHAKzcAgcKGYH pE+m2AqHjgLVtCQ0twjkW4vSGoSKIkSuZ0s633983g3cGlwcUf7SwTKfc0CayuLy 6jTfruL24gV6jMZUuLk8c6gQLo2Uk0fVx6Jl14a0oevYod0gFLVx6Q4mDmxkQAfi OpQAO8D2iP01xhvVUhNhTBT6etuE3AQm1SN+2+nQIs7EhHpbOeb57Gg5Jazw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1719901386; x=1719987786; bh=itQgIOEK3x6ZJhB06NDnAN4VZT2W o+217jmXqXN8apY=; b=NNxxiaiOrSFZNQpAB81W1Y2ywAuOJOGh/ybJswNSvTjL hsEAbRdvfcHxdAOpFsm4hIrYcyLbyH+Vlt0/EUZ081sxaYnNTLne2aqmVo94dyfg ugRJHJ5bDktxTzNRMRgW2ojyxTxNpWKoaEtnFoU/dfeX7EA7N0ymOh9yjry/58ij nuJpcKfp6+JxhD12698sJEjKGI1L2gB0MmTA9VAEj0wtuuXplwh5Akckp9W9OmFv ppK9Joz0yDD6/tQGw8MEKe7ozxLikMZ/DlSpYRa0v+zYffU18mBOQXokCXgdn+Tm 2gz9J6nLRZfdCH+9TYHu1GtAAnpanMxjCOsexW8bIg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeggddutdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvufgtsegrtd erreerreejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothht lhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnhepgedvtedtuedvfffgheffjeetvd evtdehjedvhedvieefffduhfevuefhfefhgeffnecuffhomhgrihhnpehgihhthhhusgdr tghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hrohgssegsohhtthhlvggurdgtohguvghs X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 0B06915A0092; Tue, 2 Jul 2024 02:23:05 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-566-g3812ddbbc-fm-20240627.001-g3812ddbb Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: In-Reply-To: References: Date: Tue, 02 Jul 2024 08:22:19 +0200 To: internals@lists.php.net Subject: Re: [PHP-DEV] [Discussion] Add date_test_set_now() function Content-Type: multipart/alternative; boundary=872cf03f20164e1eb8e4cd042a7e56c9 From: rob@bottled.codes ("Rob Landers") --872cf03f20164e1eb8e4cd042a7e56c9 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, Jul 1, 2024, at 15:07, Go Kudo wrote: > Hi, Internals. >=20 > I've been absent for a long time due to poor health. I'm finally back. >=20 > I maintain a legacy application written in PHP, and occasionally need = to fake the current time for testing purposes. However, PHP doesn't prov= ide a standard way to fake the current time, so I've been changing the O= S's current time to do this, which is quite painful. >=20 > This can be avoided by using third-party libraries (such as Carbon::se= tTestNow()). However, it's almost impossible to modify all parts of a le= gacy application that depend on the current time. >=20 > Another option is to use libfaketime (https://github.com/wolfcw/libfak= etime), but this is also quite painful to use. >=20 > Since this was absolutely necessary for my work, I implemented this fu= nctionality as a PHP Extension. (Please ignore the dirty implementation = related to PDO. I'm not planning to propose it this time.) >=20 > https://github.com/colopl/php-colopl_timeshifter >=20 > However, this Extension has some problems. >=20 > The first is that there's no way to determine whether the format passe= d to the ext-date parser is relative or absolute time, resulting in a di= rty hack using usleep. The second is that it depends on timelib, so it b= reaks when upstream changes related to timelib are made. >=20 > So, how about adding a `date_set_test_now(\DateInterval $shiftInterval= )` function to ext-date? >=20 > This function would treat the current time as shifted by the passed Da= teInterval. Since it's implemented on the ext-date side, there's no need= for dirty hacks using usleep. >=20 > I'd like to hear your opinions. Thank you. >=20 > Best Regards, > Go Kudo Welcome back! I think this is an interesting proposal and very useful. I think many pe= ople may be concerned about it being used in a non-testing context, but = I don=E2=80=99t think we should stop people from being creative. If peop= le find a use for it outside of testing, that would be interesting to se= e. The fact they can already do this today via carbon just makes a point= that this is valuable to those of us who don=E2=80=99t like adding depe= ndencies. Ps. Anytime someone mentions PSR, have your favorite drink. It=E2=80=99l= l help take the edge off. :) In all seriousness, PSR doesn=E2=80=99t app= ly universally and shouldn=E2=80=99t ever be a valid argument on this li= st. That=E2=80=99s my 2=C2=A2 anyway, best of luck to you.=20 =E2=80=94 Rob --872cf03f20164e1eb8e4cd042a7e56c9 Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable

=
On Mon, Jul 1, 2024, at 15:07, Go Kudo wrote:
Hi, I= nternals.

I've been absent for a long = time due to poor health. I'm finally back.

= I maintain a legacy application written in PHP, and occasionally need to= fake the current time for testing purposes. However, PHP doesn't provid= e a standard way to fake the current time, so I've been changing the OS'= s current time to do this, which is quite painful.

This can be avoided by using third-party libraries (such as Carb= on::setTestNow()). However, it's almost impossible to modify all parts o= f a legacy application that depend on the current time.
Another option is to use libfaketime (https://github.com/wolfcw/libfaketime),= but this is also quite painful to use.

Sin= ce this was absolutely necessary for my work, I implemented this functio= nality as a PHP Extension. (Please ignore the dirty implementation relat= ed to PDO. I'm not planning to propose it this time.)

=

<= /div>
However, this Extension has some problems.

<= /div>
The first is that there's no way to determine whether the form= at passed to the ext-date parser is relative or absolute time, resulting= in a dirty hack using usleep. The second is that it depends on timelib,= so it breaks when upstream changes related to timelib are made.

So, how about adding a `date_set_test_now(\DateInt= erval $shiftInterval)` function to ext-date?

This function would treat the current time as shifted by the passed Da= teInterval. Since it's implemented on the ext-date side, there's no need= for dirty hacks using usleep.

I'd like to = hear your opinions. Thank you.

Best R= egards,
Go Kudo
Welcome b= ack!

I think this is an interesting proposa= l and very useful. I think many people may be concerned about it being u= sed in a non-testing context, but I don=E2=80=99t think we should stop p= eople from being creative. If people find a use for it outside of testin= g, that would be interesting to see. The fact they can already do this t= oday via carbon just makes a point that this is valuable to those of us = who don=E2=80=99t like adding dependencies.

Ps. Anytime someone mentions PSR, have your favorite drink. It=E2=80=99= ll help take the edge off. :) In all seriousness, PSR doesn=E2=80=99t ap= ply universally and shouldn=E2=80=99t ever be a valid argument on this l= ist. That=E2=80=99s my 2=C2=A2 anyway, best of luck to you. 

=E2=80=94 Rob
--872cf03f20164e1eb8e4cd042a7e56c9--