Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124141 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 11AC01A009C for ; Mon, 1 Jul 2024 13:31:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719840755; bh=drOk2CCH8cB9hnTQzhbrs3HSQJcmuuezeZJqB1bVBCo=; h=In-Reply-To:References:Date:From:To:Subject:From; b=MyPJHq1wMDxXwixYKF27YdYTZQ48rx8z61LWauExEGSn5PAYOtKu5zn/1Cujg7OP8 PY59dAEREw2ZBcdZtTjPjJkwrqxckQUMuAAzkAwshiRUKDxbHdG35SeTeM07fEwl+t asp9wIJ8Qy7DndG4DA91gIFYk5quSb7fEcy/zsAAJS2UBTyHZK8cjq2nozz+9DKR+M JsIZNIFKni7ae3inkZzNoNs9fEHf/neaMy8g6Hv0GlxsqWIQjWs9qHEn49Q3nBqDVg uSXzOe4MXEhtD9EFww+l3nmkZNx1F3pDwYyGgG1L7Geyr/AfGwICcLqiTjWOWBh7q4 HemIqJFcxntQA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C2278180DC7 for ; Mon, 1 Jul 2024 13:32:34 +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,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE,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 wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 1 Jul 2024 13:32:34 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id BF8341800089 for ; Mon, 1 Jul 2024 09:31:12 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Mon, 01 Jul 2024 09:31:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; 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=fm2; t=1719840672; x= 1719927072; bh=7vboT76fDNBr6oyRu6KJn/pXG/oOpRFpgV3CNEF3UrI=; b=o aO9jwNcKJLbqaewGEIVdSP257fxqVBu1scpHRVwnmdksXXz0asV3aVqy0tsdXdc9 /n0PBajHyioaf1bpnw6CLCE2hZIaI4Tn7pqbH9yKuUAKPbXvJVl71MGWpw+SltBc xamyjmZqHKna+QbB33enJW8DUSVRvVXhYbD2wT4X8c+60SBSY+Xrq4AfEfn5xjG7 wuSjJ9FrUua5CDPWPZ3cx8VyeoWygmCdu7t2Q/awTdnggoscicyvkm06KVbYL6mu EaA5QtBEMlvdqbDPy1ZwNEBzrOYfJ56VklDqUFV8KvHd7wwgV2gdyOho9p7IWtRb LTNuacoO1B0DgI2kyTMhQ== 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=1719840672; x=1719927072; bh=7vboT76fDNBr6oyRu6KJn/pXG/oO pRFpgV3CNEF3UrI=; b=AUrM7o87E1om1neAF6Bjma9J8tR+iTHHpQV4wVY3RFCn rtD89deQGG6dQpy5LejCozGuAw98a0ZxFlfD3MXt/suiywVKVkkM6I4njfe+TPU6 KIrwNmTqGf0O6Zs6Az/68y9M6H6/1AbPlwKBbRpLufJP2S3dqZC9XcEaiwGK7hcI QlJkSCN08ikXiBDVqNlg3kvmATlCrDweYjPQZQL3NzXEVtwaiua1OyrUNaI0t0XX 53sXuFoR2tit71NmWmumlrY3P0XPjx1XZXdkdHi8gDTQJoKjM0mPG3FqPuNFyc5H Mf7KNDUWx0ZYhix353u7th/I1Xqur1p0fuONLKmvQQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgdeifecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuggftrfgrthhtvghrnhepkeetleehffegfedvudefueejkefhvddtueeuvdevteei veehledugeejudfhhfetnecuffhomhgrihhnpehgihhthhhusgdrtghomhenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghr fhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id C44DF1700096; Mon, 1 Jul 2024 09:31:11 -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: <87c9d05e-740f-4892-b51e-86c4c5624d81@app.fastmail.com> In-Reply-To: References: Date: Mon, 01 Jul 2024 13:30:51 +0000 To: "php internals" Subject: Re: [PHP-DEV] [Discussion] Add date_test_set_now() function Content-Type: text/plain From: larry@garfieldtech.com ("Larry Garfield") On Mon, Jul 1, 2024, at 1:07 PM, Go Kudo wrote: > Hi, Internals. > > 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 > provide 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 > Carbon::setTestNow()). However, it's almost impossible to modify all > parts of 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. > > Since this was absolutely necessary for my work, I implemented this > functionality as a PHP Extension. (Please ignore the dirty > implementation related to PDO. I'm not planning to propose it this > time.) > > https://github.com/colopl/php-colopl_timeshifter > > However, this Extension has some problems. > > The first is that there's no way to determine whether the format 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(\DateInterval > $shiftInterval)` function to ext-date? > > This function would treat the current time as shifted by the passed > DateInterval. 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 Regards, > Go Kudo We don't generally add features just to support very-old legacy code. These days, the correct answer would be to use PSR-20. (Implementations are trivially easy, many available, and it's dead easy to write your own.) That doesn't much help legacy code, but adding global features just to support legacy code that should get refactored anyway doesn't seem like a great idea. --Larry Garfield