Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124143 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 5E33F1A009C for ; Mon, 1 Jul 2024 15:56:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719849485; bh=fGwly84r3x1xlf+lC+Y9aybHe4YpfgieWmD4lefy/V4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QznMVcEf9QvbHVGwUjrrGBBEraxa752zTF/JcON28LoY5r+FxBYrD7JfrxM7vJUde mkNKC5iGKhSRaU23ISdejwB43DhSL5qEz8agR04k8wcVI4AUtEGIlq723+Ms7Nh3gn IyFxaGJsGnlgbMeW7GBcY1WvyuJV3JFVLf99TNASSokd4skkybRax186p/5OYt5iM+ TfM7siSL8X4L1let5/PXsI4uoCKqMqODJZPeS9sKMtDsmAL1+e02eV4pnrmzdX3C5d O6bVUybf1MlbuROkIc+bZxrrt0AH4swZWQMaRz7Kywkxg9uhC00vc1ebs4UkdBMpp1 CTh/zFJcbEqbA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F0E42180056 for ; Mon, 1 Jul 2024 15:58:04 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, 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 mail-vk1-f181.google.com (mail-vk1-f181.google.com [209.85.221.181]) (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 ; Mon, 1 Jul 2024 15:58:04 +0000 (UTC) Received: by mail-vk1-f181.google.com with SMTP id 71dfb90a1353d-4ef6b3207a7so1032998e0c.0 for ; Mon, 01 Jul 2024 08:56:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719849402; x=1720454202; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=fGwly84r3x1xlf+lC+Y9aybHe4YpfgieWmD4lefy/V4=; b=DL1fcj6uLmMlsE+7J2lYSp2wEfmldq9Fr10T7+31gDExO08II8t6kbH5xfYcWYmWnc s/dRa+ESqnNl8HV4K84Yz3ebIc8kA8OSknSOJ2HxPN37IhheZya2jnpZUc3S/U61Uexr tKat3bYwYYdjP8mBajjcLohV9kqM10LecMkSSYqLDYkxkxk9hCwpscoCBpRa6c3k3Zmv i/h1IEVtNsNfchRxNfDzZLBRGBmBc0vhmSHNUV3dg50LK0mEi+d9p1kud7xWQ0LmiIzl ZToQNHUqGo4fS6X+VOGilLEcnpa27c0yJz3XCErI9r61Vr9iIsXlAPzNos3uTEni3OnD De3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719849402; x=1720454202; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fGwly84r3x1xlf+lC+Y9aybHe4YpfgieWmD4lefy/V4=; b=FLC3MKElAMLcvJJyUgOlBUw37AsSEXJElvHTANaxXHwaBKVChfE0XVMCheJ3+xwCYD hYx3L+D4gdIHDflQSzcPSlRvvOmZtEw1OGGOfdnlwZx2nUeFyMyhf4K0x6Ay1BF7db4y kh2iULCRE5qW10wR6JoAfmSn9yA4iKSYTj6TSs7mJlsa55nJOZx+FXkYZXKdyoc2PrFe Fgby5QUpj0P28XAzSaeCpHioa9jYgZxma7gvO5/MMpTCHM/2fgvv3Ft25fREFQM3gANJ FiSwZuS7/qeroR3E25XHy2nw2Q+C41dz3Sgv6Y4cagx2TiCWDmh0qsB3QwqhaGctfZc+ NpVQ== X-Gm-Message-State: AOJu0Yw3IaB1CdrV6nMWw4G0o7XiGYYl870CEjxSlyrZKVS2kwfGBZL8 bIo+HKFSaibOSu4h0Vq9aY7eSZFtRVBekIFvSK+wYt9LD+L25pRX4XSxaop2sGLrJkMwN3aeD4L i9yo5jRqXgy1shpWAc9oT6NgdGZNZzfRy X-Google-Smtp-Source: AGHT+IF19RxYTsKMpiLxMeN3NA+2MmCrykRf5MP+1PmRinxTEFVDgxnw9g6n6IWTM2LAFfGFUOp+2dNKtjjWOgPO3DU= X-Received: by 2002:a05:6122:4a05:b0:4ed:740:c2a9 with SMTP id 71dfb90a1353d-4f2a5719c32mr5971194e0c.16.1719849402389; Mon, 01 Jul 2024 08:56:42 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 2 Jul 2024 00:56:30 +0900 Message-ID: Subject: [PHP-DEV] Re: [Discussion] Add date_test_set_now() function To: PHP internals Cc: andreas@heigl.org, Larry Garfield Content-Type: multipart/alternative; boundary="000000000000b25acf061c31a414" From: zeriyoshi@gmail.com (Go Kudo) --000000000000b25acf061c31a414 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 2024=E5=B9=B47=E6=9C=881=E6=97=A5(=E6=9C=88) 22:07 Go Kudo : > 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 part= s > 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 t= o > the ext-date parser is relative or absolute time, resulting in a dirty ha= ck > 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 nee= d > for dirty hacks using usleep. > > I'd like to hear your opinions. Thank you. > > Best Regards, > Go Kudo > I apologize, the main point of my explanation was off. To put it simply, I'm suggesting that it might be good to implement convenient and commonly used features from Carbon at the ext-date level. I'm proposing the date_test_set_now() function for the following reasons: User-land libraries like Carbon / Chronos have a setTestNow method, indicating a potential demand for this feature. It's impossible to determine whether a value is relative or absolute time from either user-land or Extension. While this is convenient for maintaining legacy systems, that's not the essence of this proposal. As you pointed out, this is an issue that should ideally be solved in user-land. I deeply understand that. However, in reality, PHP's time-related processing is diverse, and to comprehensively handle all of these, it seems necessary to address this at the ext-date level. https://www.php.net/manual/en/ref.datetime.php For example, you might want to use the date() function to display the current time on a whim. However, doing this ruins everything. Even if other parts of your code use Carbon or comply with PSR-20, using the date() function is problematic because the current time it references cannot be modified. `date_test_now(\DateInterval $shiftInterval)` can solve this problem. Of course, there might be various side effects. However, seeing `Carbon::setTestNow()` being used in various places, I think this feature might be necessary. I would appreciate your thoughts on this. Best Regards, Go Kudo --000000000000b25acf061c31a414 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
2024=E5=B9=B47=E6=9C=881=E6=97=A5(=E6=9C= =88) 22:07 Go Kudo <zeriyoshi@gma= il.com>:
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 occasiona= lly need to fake the current time for testing purposes. However, PHP doesn&= #39;t provide a standard way to fake the current time, so I've been cha= nging the OS's current time to do this, which is quite painful.

= This can be avoided by using third-party libraries (such as Carbon::setTest= Now()). However, it's almost impossible to modify all parts of a legacy= application that depend on the current time.

Another option is to u= se 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 tim= e.)

https://github.com/colopl/php-colopl_timeshifter

= However, this Extension has some problems.

The first is that there&#= 39;s no way to determine whether the format passed to the ext-date parser i= s relative or absolute time, resulting in a dirty hack using usleep. The se= cond is that it depends on timelib, so it breaks when upstream changes rela= ted to timelib are made.

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

This function wo= uld treat the current time as shifted by the passed DateInterval. Since it&= #39;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,=C2=A0
Go Kudo

I apologize, the main point of my = explanation was off.

To put it simply, I'm suggesting that it mi= ght be good to implement convenient and commonly used features from Carbon = at the ext-date level.

I'm proposing the date_test_set_now() fun= ction for the following reasons:

User-land libraries like Carbon / C= hronos have a setTestNow method, indicating a potential demand for this fea= ture.
It's impossible to determine whether a value is relative or ab= solute time from either user-land or Extension.
While this is convenient= for maintaining legacy systems, that's not the essence of this proposa= l.

As you pointed out, this is an issue that should ideally be solve= d in user-land. I deeply understand that.

However, in reality, PHP&#= 39;s time-related processing is diverse, and to comprehensively handle all = of these, it seems necessary to address this at the ext-date level.

= https://www.php.= net/manual/en/ref.datetime.php

For example, you might want to us= e the date() function to display the current time on a whim. However, doing= this ruins everything.

Even if other parts of your code use Carbon = or comply with PSR-20, using the date() function is problematic because the= current time it references cannot be modified.

`date_test_now(\Date= Interval $shiftInterval)` can solve this problem.

Of course, there m= ight be various side effects. However, seeing `Carbon::setTestNow()` being = used in various places, I think this feature might be necessary.
=
I would appreciate your thoughts on this.

=
Best Regards,
Go Kudo
--000000000000b25acf061c31a414--