Propsal Idea: ClockInterface

200 views
Skip to first unread message

Chris Seufert

unread,
Mar 4, 2021, 7:34:40 AM3/4/21
to PHP Framework Interoperability Group
Hello,

I would like to propose standardizing a clock interface for reading the current time, date, timestamp, and timezone.

The problems I hope to solve is when testing time sensitive code, there is a unified way to represend the current time. I have run into several issues doing this some of which are:
- Some library use different Clock interfaces / implementations.
- Its impossible to mock some calls to date and time without using a PHP extension to override the current time & date.
- There are about 10 competing library implentations to this problem just from a quck search on packagist

The proposed interface would look like this:

interface ClockInterface
{
    public function timestamp():int;
    
    public function immutable():\DateTimeImmutable;
    
    public function datetime():\DateTime

     public function microtime():float
     
     public function timezone():\DateTimeZone
}

I have created a pull request for this here:

I am looking to find out if anyone is interesting in sponsoring this Standard.

I have enjoyed using the PSR-16 interopable caches, and also migrated a large legacy application to use PSR-7/PSR-15 and also benefits from using standard middlewares and request extensions, and hope this could provide a similar experience in the future.

Regards,
Chris Seufert

Andreas Heigl

unread,
Mar 4, 2021, 8:37:15 AM3/4/21
to php...@googlegroups.com
Hey all

Am 04.03.21 um 13:34 schrieb Chris Seufert:
I won't be able to act as sponsor but would be available for a working
group if that is helpful.

Cheers

Andreas
--
,,,
(o o)
+---------------------------------------------------------ooO-(_)-Ooo-+
| Andreas Heigl |
| mailto:and...@heigl.org N 50°22'59.5" E 08°23'58" |
| https://andreas.heigl.org |
+---------------------------------------------------------------------+
| https://hei.gl/appointmentwithandreas |
+---------------------------------------------------------------------+

OpenPGP_signature

Larry Garfield

unread,
Mar 4, 2021, 11:13:20 AM3/4/21
to PHP-FIG
Have you spoken to the maintainers of those 10 competing libraries? For a spec like this to be successful it would need buy-in from those implementers, otherwise we just end up with an XKCD 927 problem. (https://xkcd.com/927/) They're the people that you'd want in a working group.

In related news, I'm -1 on anything that still uses DateTime. DateTimeImmutable or bust.

--Larry Garfield

Chris Seufert

unread,
Mar 4, 2021, 5:23:33 PM3/4/21
to php...@googlegroups.com
Now that there does seem to be some serious interest in this idea, I will contact the maintainers and see what we can do to get them onboard with adopting a standard like this. And yes, it appears that DateTimeImmutable is the way to go.

Chris Seufert

unread,
Mar 4, 2021, 5:24:02 PM3/4/21
to php...@googlegroups.com
That would be great, thank you.

--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/lA8Lz0E4dWk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/67a54cec-28bc-e547-6e7f-d6d1c77aa44a%40heigl.org.


--
Chris Seufert

M. 0424 066 016  T. 03 9510 7477
The Well - 1 / 21 Wellington St, St Kilda, Victoria 3182, Australia
modd.com.au - udo.net.au - artsphere.com.au  

Alessandro Lai

unread,
Mar 5, 2021, 2:42:51 AM3/5/21
to PHP Framework Interoperability Group
If that could be of any help, I will remember you that we have a public Discord server, where you could invite potential WG members to discuss and organize.

The server is reachable at https://discord.gg/php-fig/

Ping me or other secretaries if you need a dedicated channel.

Chris Seufert

unread,
Mar 8, 2021, 6:15:10 PM3/8/21
to php...@googlegroups.com
Hi,

To update anyone on the progress made via the currently pull requests on github. The consensus is that the interface spec should be far simpler than the initial proposed one, and now looks as follows:
<?php

namespace Psr\Clock;

interface ClockInterface
{
    /**
     * Returns the current time as a DateTimeImmutable Object
     */
    public function now(): \DateTimeImmutable;

}


After reaching out to several clock library authors. I have had positive feedback from the most prominent library authors, and everyone else who has commented on the PR is in general agreement on the spec. As this is my first time working with getting something published as a standard I am not sure what to do next, do I need to find a sponsor? How would I go about that?


Larry Garfield

unread,
Mar 8, 2021, 7:08:04 PM3/8/21
to PHP-FIG
On Mon, Mar 8, 2021, at 5:14 PM, Chris Seufert wrote:
> Hi,
>
> To update anyone on the progress made via the currently pull requests
> on github. The consensus is that the interface spec should be far
> simpler than the initial proposed one, and now looks as follows:
> <?php
>
> namespace Psr\Clock;
>
> interface ClockInterface
> {
> /**
> * Returns the current time as a DateTimeImmutable Object
> */
> public function now(): \DateTimeImmutable;
>
> }
>
>
> After reaching out to several clock library authors. I have had
> positive feedback from the most prominent library authors, and everyone
> else who has commented on the PR is in general agreement on the spec.
> As this is my first time working with getting something published as a
> standard I am not sure what to do next, do I need to find a sponsor?
> How would I go about that?
>
> Link to spec:
> https://github.com/php-fig/fig-standards/pull/1224/files

The full process is described here: https://www.php-fig.org/bylaws/psr-workflow/

Short version: At this stage, you need yourself as Editor (I presume), one Core Committee member as a Sponsor, and 3 or more other people who can be anyone involved. (Presumably the other existing library authors.) Then the Sponsor calls an Entrance Vote on the proposal to date. The Sponsor can help shepherd the spec through the remaining stages.

So the next step is, who from the CC wants to Sponsor this?

--Larry Garfield

Chuck Burgess

unread,
Mar 8, 2021, 7:13:25 PM3/8/21
to php...@googlegroups.com
I'll sponsor this... there seems to be a good amount of interest.
CRB

--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/4b223db1-e784-4d7e-b8fe-660920c6dc09%40www.fastmail.com.

Alessandro Lai

unread,
Mar 9, 2021, 9:27:51 AM3/9/21
to PHP Framework Interoperability Group
In the meantime, I've created a #tmp-psr-clock channel on our Discord, to help the formation of the WG.

Chris Seufert

unread,
Mar 10, 2021, 5:19:19 PM3/10/21
to PHP Framework Interoperability Group
Thanks Allesandro for the discord channel,

We now have a working groups and sponsor:
Sponsor
  • Chuck Burgess
Working group members
  • Pol Dellaiera
  • Ben Edmunds
  • Jérôme Gamez
  • Andreas Heigl
  • Andreas Möller
I am not sure if we should wait a little longer for anyone who hasn't been able to accept an invitation to the working group, or if we should be organising an entrance vote for the spec. 


Larry Garfield

unread,
Mar 10, 2021, 5:28:05 PM3/10/21
to PHP-FIG
On Wed, Mar 10, 2021, at 4:19 PM, Chris Seufert wrote:
> Thanks Allesandro for the discord channel,
>
> We now have a working groups and sponsor:
> Sponsor * Chuck Burgess
>
> <https://github.com/moddengine/fig-standards/blob/psr-clock/proposed/clock-meta.md#53-working-group-members>Working group members * Pol Dellaiera
> * Ben Edmunds
> * Jérôme Gamez
> * Andreas Heigl
> * Andreas Möller
> I am not sure if we should wait a little longer for anyone who hasn't
> been able to accept an invitation to the working group, or if we should
> be organising an entrance vote for the spec.

To clarify, how many of the WG members are maintainers of the affected libraries? We want to make sure there's buy-in from them, as they're the most important constituency.

--Larry Garfield

Chris Seufert

unread,
Mar 10, 2021, 11:01:00 PM3/10/21
to php...@googlegroups.com
Hi,

Working Group Members who maintain libraries

- Jérôme Gamez maintains kreait/clock
- Andreas Möller maintains ergebnis/clock
- Luís Cobucci maintains lcobucci/clock

I have reached out to some other library authors, but have not heard back.


--
You received this message because you are subscribed to a topic in the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-fig/lA8Lz0E4dWk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-fig+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/c2c12f7f-60c1-4a89-b246-2b913c9c0fa9%40www.fastmail.com.

Kenta Usami

unread,
Mar 14, 2021, 10:02:56 AM3/14/21
to PHP Framework Interoperability Group
Hi,

I'm interested in these issues as I'm working on time and test issues for a framework-less (pure HTTP PSRs implementation) web application in my company.

I wrote another "clock" library and interface proposal.
https://github.com/bag2php/clock

I already have an interface and class similar to this in production.
This interface only has the now method and can interoperate with the DateTime extension classes (Carbon and Chronos).

I am willing to participate in the discussion when a working group is formed.

2021年3月11日木曜日 13:01:00 UTC+9 Chris Seufert:
Reply all
Reply to author
Forward
0 new messages