Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124170 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 524031A009C for ; Tue, 2 Jul 2024 04:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719895250; bh=KmNZzDO3V76sw7zmMzC3/VYXzXqlSrvSS++9oTRwZYk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=EY0DWBGNapbmuI5VktJI1XYggT87+qspoH6dY6rDcEhoKLOhpOKqJ1/9/GcLXOyJI kqLgLZ554ueQ88O90N/dboly4vuVqhJHHyNILG1VXeql/6rDZsvZdy4w7YMc2il5lc EqqSZWhvt03LfXkhYDLiObgOEzsjX/0mmjCqQaVjVDcP6bBD4AHI4WcwcI+ZCnYsuZ b9cM8ULxmB+Fl5hrjR+yzugdK8eT3Tcrc7Nl5zQrBSxQkl5ubfXJLvCG2CeZ3+oy/h gYUE8i6ULkc5AznW1HbUdjj6L2/VJtMfv/njZGqw43wYhBoAsgMstN0upFiAWdizfM swe8BOPPOJyOQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4B3DB180056 for ; Tue, 2 Jul 2024 04:40:49 +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-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) (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 04:40:48 +0000 (UTC) Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-e03618fc78bso3341322276.2 for ; Mon, 01 Jul 2024 21:39:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719895167; x=1720499967; 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=KmNZzDO3V76sw7zmMzC3/VYXzXqlSrvSS++9oTRwZYk=; b=iLHGWteyrDtOIJhsGmJLTd214iyvTRN0VnMgU9ggFbtPjucxJv2319dvrMySZxe2ji mVOz2XxJTE/7IgXQ7VXHOIbOqqNB2zL9qwsKZsKGFW9ogM9JTpqANF4LkvW9RUf/eoFA u3a0SM4ejQjzfkMkr4s7QgGW7J9D+OYDfF8XAK6xAv8caI37TCMxNGxD5yRDAXjEtMxR dD1UnmhU6U9PNYTWWB1Segkd5/RDxIK9cw/4/hP4vLsDTvJqZPDgq5V9WON4JP1lGAiw lzVdsduUHJUOPYQ2J8Dph6DxR/7gCHz1lsTYoI3bbovDnTz0mGkXS03l2WMXIShoxgNL V6Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719895167; x=1720499967; 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=KmNZzDO3V76sw7zmMzC3/VYXzXqlSrvSS++9oTRwZYk=; b=YlrAmPPlCZJAuRdP4Bx4q2CpNQO6SmMbKd2N26hxzU22kmDB+3x3tJstclz4hNpnBW m4eVTcFVTcdkKOht+06rpRljElJQEJMmG5iOTFRM9qAycQ+01fmgJDfl0dPMnee74AQ4 SxQROFr2btF86jhQVQMI0Bedg9ChcGgLjznxjmnmlZGRL3wKaIgNZhyu815OJTljbpXR JOvsViD/sXNZvagfTaA2/vPr2S2Gvgt89+VJVNfOKLS+UzsXwxf5EmYxrQKGLEhJRIfv Ce3hp579Z0ea2W0qKs+AlMzPHGI2C/eprk3pm24ubTNbyLiBBZfZ5UT0ZXkgod50nuMF fovQ== X-Gm-Message-State: AOJu0YzQr8Zq8cUMf3kviL6UO69D4cus68/OC10Ss0u6+PP50QGhJdbx J8eDbQW1Xg88LODz2xzDymCmBJwNdDaPEQyzPz4EVznHJ34lMIxFvfCzMzR+wMGbmzP4RYVlFlg gGAbZ85C4UVQXODX0gAuEu01Ycccowrl2AOg= X-Google-Smtp-Source: AGHT+IHoeKJd3ygA1U2b80+knqqlt0FnS6WGsyZmxVChOvvqWTJikHekqAQyAUBmz5iPe98SPA8n5cOGli17N+i7uE4= X-Received: by 2002:a5b:1c7:0:b0:e02:b463:39ec with SMTP id 3f1490d57ef6-e036eb67dc3mr7833951276.29.1719895167028; Mon, 01 Jul 2024 21:39:27 -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 07:39:14 +0300 Message-ID: Subject: Re: [PHP-DEV] [Discussion] Add date_test_set_now() function To: Go Kudo Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000007b5757061c3c4c45" From: drealecs@gmail.com (=?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?=) --0000000000007b5757061c3c4c45 Content-Type: text/plain; charset="UTF-8" > > > 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 can see how this would be useful on legacy applications, not forcing many changes everywhere. However, I think that we should not encourage this and keep it out of php core offering. Having it as a separate php extension sounds good to me, and as long as that php extension is loaded and used only while running tests, it helps with not possibly impacting production in any way. Indeed, it mighty have some limitations but I think we can work around them. An alternative solution would be to have namespaced functions and classes and use rector to automate the replacement of native ones just before running tests and package everything as a testing php library. Alex --0000000000007b5757061c3c4c45 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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

However, this Extensi= on has some problems.

The first is that there's no way to determ= ine whether the format passed to the ext-date parser is relative or absolut= e time, resulting in a dirty hack using usleep. The second is that it depen= ds on timelib, so it breaks when upstream changes related to timelib are ma= de.

So, how about adding a `date_set_test_now(\DateInterval $shiftIn= terval)` 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 can see how this would be useful on legacy appli= cations, not forcing many changes everywhere.

However, I think that we should not encourage this an= d keep it out of php core offering.

Having it as a separate php extension sounds good to me, and as= long as that php extension is loaded and used only while running tests, it= helps with not possibly impacting production in any way.
Indeed, it mighty have some limitations but I think we can work aroun= d them.

An alternative s= olution would be to have namespaced functions and classes and use rector to= automate the replacement of native ones just before running tests and pack= age everything as a testing php library.
=C2=A0
Alex

--0000000000007b5757061c3c4c45--