Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124139 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 C01DF1A009C for ; Mon, 1 Jul 2024 13:12:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719839645; bh=Umy6GfhSVr7NSkGoMR59Y85zip3HRSvQ55VzEH/OsWE=; h=From:Date:Subject:To:From; b=f2ovN0BRnkSD5xZ5fK1ZdPcuH0mFFhvGO6onxIxgZWIk5At2RuseXG7MGGo6yeMhY GZmva3ofyKFWBLf4s+lfv/02eOdqe7nwbQJlP7/cfn1VWzvoziiSDZ8Jp/BQvChGYB x9qGNKKjslyatoC6ytL7hRQgtywWnufRo7BycagFJDecs6S/xCi1ZndKJnZN6s1Bdr zQf+1ka3evDRRITOxkUgmCAIuG2nzk2vj0cOK+wQMcgc+TRlENXBNDYbg5f6NjiiqB RbTOz7qxYMTWpkAiG7qjLXu+X1W2CNBnPz/wgJUyBzDQpXIqkEsV5fSxDv0jhJKP2M mNjXMpuJOB4Tg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4AE8F1808C1 for ; Mon, 1 Jul 2024 13:14: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-f175.google.com (mail-vk1-f175.google.com [209.85.221.175]) (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 13:14:03 +0000 (UTC) Received: by mail-vk1-f175.google.com with SMTP id 71dfb90a1353d-4e4efbc3218so1201243e0c.0 for ; Mon, 01 Jul 2024 06:12:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719839562; x=1720444362; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=Umy6GfhSVr7NSkGoMR59Y85zip3HRSvQ55VzEH/OsWE=; b=TEaVp0Hz4qc5d9mMRu6afRlwyJ+WunytNO4WY6eWrjKR2Cp05fxbHzoiuYSW3Qcazm 7BUYWzQ3MuNXhUiENINcN55/Of6dQeEN8yDPWV4klthVb0mNwXDHCPaylDQZ0Dfs0zUR R4W323SB//OKbQCm2gOzmLYqlNymWao1rutx/RNWCPBjLrSweazu/8fJ4cFv3roZyX3j 1Bx17GpMdN9DxCdAw9myu8FiDLceXa9m800yYwTXd4wIniOy19N/cFBkozMMh1mF8BG2 DwsPDyCxg4eoXMZgaLEwhX+bxLOlg9kLRa7AouxK2ghWJ02AhNSt4H6ErTYwlMcTb4ic 44jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719839562; x=1720444362; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Umy6GfhSVr7NSkGoMR59Y85zip3HRSvQ55VzEH/OsWE=; b=QNxjVIK2gPwmGBqEbpm958xXzmgzR/ONA6lTAvqXQqFAb2dPNEhWrrSoO+WjCcfE+Q uF/4Meb+u3ENbJSIMLIUy/ILTKljWlq53Nvuly4M95Eho2eR1ZWxbAHYJgtAKRDPtpIa jMiSUjJqYARylFCaTzFuGpvuiJYnTZpBFSXRHx/Fz0PRYfucdPkA3AECtEkvT2itLHAT 5GbQLxgnHvk1lLXBWKj/dgsJbs3XExAjKUOWXsJc0LeeJFnvm8snlVKnxSkTf+0/bTlu VfTDV73n27hIw2pcpoctmsZ8rKFJdiUUC7hiRQEEcnxwDGoORXzUn1EAD5xUdIZy9DaC eOgw== X-Gm-Message-State: AOJu0YyfJTaZf5hztrMw08vC4buUSCsNzbw93O4xvKAv8tBOTrtt73RR /x3D1taf2r5oZpsfOfAHx9YnkPpqrTyP1Pc/DRPD6BhjjKn4KDRxy3tk8dPGotvrx/bv4gITlNp FgkBWClwZ3j7+vz3sUT/M6KnkhTeHNIuK X-Google-Smtp-Source: AGHT+IGLsv/Eyyu2S6b4AgnXrkuYMCj+kSH55DP00UCjWXD4Dep8Lu2e8KWq8n0qrXcLNUo7+L7/3ihnzMm1XFTZqLo= X-Received: by 2002:a05:620a:469e:b0:795:4fee:81aa with SMTP id af79cd13be357-79d7ba12b61mr968953185a.33.1719839246929; Mon, 01 Jul 2024 06:07:26 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Date: Mon, 1 Jul 2024 22:07:15 +0900 Message-ID: Subject: [PHP-DEV] [Discussion] Add date_test_set_now() function To: PHP internals Content-Type: multipart/alternative; boundary="00000000000062643a061c2f47da" From: zeriyoshi@gmail.com (Go Kudo) --00000000000062643a061c2f47da Content-Type: text/plain; charset="UTF-8" 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 --00000000000062643a061c2f47da Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 curren= t time for testing purposes. However, PHP doesn't provide a standard wa= y 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 usin= g third-party libraries (such as Carbon::setTestNow()). However, it's a= lmost 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/libfaketim= e), but this is also quite painful to use.

Since this was absolu= tely necessary for my work, I implemented this functionality as a PHP Exten= sion. (Please ignore the dirty implementation related to PDO. I'm not p= lanning 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-d= ate parser is relative or absolute time, resulting in a dirty hack using us= leep. 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_se= t_test_now(\DateInterval $shiftInterval)` function to ext-date?

This= function would treat the current time as shifted by the passed DateInterva= l. 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
--00000000000062643a061c2f47da--