[PHP-DEV] [RFC] Time\Instant and Time\Clock

Hi

On 2026-10-05 17:29, Rob Landers wrote:

I'm just now getting around to reading over the RFC, and I've read most messages but not all of them. So, I apologize if I'm reopening any old discussions here.

The only duplication was the JSON serialization that had also been mentioned by Ilia (who I'm Ccing here).

After spending much of the last 4-5 years working on a database that needs to deal with relativity, I'd recommend dropping the physics framing in the introduction. Time doesn't move at the same speed for everyone, even on Earth, and you don't specify a frame of reference for the instant. It would also make it easier to explain `until` as "computes the difference between two represented time values. It does not establish how much physical time elapsed between the events that produced those values."

Thanks for the physics discussion in Discord. To loop in the list: Rob is correct here, I'll check what I can do to satisfy the physics experts without leading other folks down the “I need a timezone” track.

This also raises a question about uncertainty. I appreciate that the RFC distinguishes the nanosecond precision of the representation from the resolution of the underlying clock. However, `Clock::now()` returns only an `Instant`, with no way through that contract to convey the source resolution or any available uncertainty information. I've had servers lose access to their hardware clock due to hardware malfunctions, so this is not just a theoretical concern. Where that information is available, it should be preserved alongside the reading. Where it is unknown, it should remain explicitly unknown. Printing nine fractional digits cannot supply that information.

Uncertainty is likely not of interest to the average user or something they understand: They just trust that their operating system provides them with the correct time. For applications where this matters adding a custom extension with a “ClockWithUncertainty” clock that returns the Instant + a Duration would be the right choice. The current design is in line with what virtually all the other programming languages do for their standard library. Marc also suggested exposing `clock_getres()` on the `SystemClock`, I'll reply there. In any case, I don't think this is something that belongs on the `Clock` interface, since it increases the API complexity for little benefit.

I think there are some things worth addressing in the current RFC:
1. `Instant` should throw when serialized to JSON. I understand the argument is that applications should choose their own representation, but the choice should be enforced rather than silently doing the wrong thing. Or provide an opaque serialization that can restore the `Instant`.

I discussed this with Derick and it's our position that:

1. As you mentioned and as I said in php.internals: Re: [RFC] Time\Instant and Time\Clock that there is no single canonical representation for JSON and that users need to make a choice themselves.
2. That implementing `JsonSerializable` just to always throw an exception would be misleading, because from the API surface it very much looks like JSON serialization would be supported.

That `json_encode()` includes a useless default serialization for arbitrary objects instead of requiring an opt-in is something that should be fixed in ext/json and not worked around for every (value) object we implement. Since there is no “json decode to object”, an opaque serialization that can restore the `Instant` is not really a thing. If users need to manually call methods, they can just go via ISO-8601.

2. `DateTimeInterface` is missing the `toInstant()` method, is that by design?

No. I just forgot that the interface exists. Now added.

3. The backward-compatibility section still says this RFC only introduces three new namespaced symbols. It should also cover the new methods on `DateTime` and `DateTimeImmutable`, including potential conflicts with existing subclass methods named `toInstant()`.

Did some preliminary adjustments there. Might tune the phrasing later.

Best regards
Tim Düsterhus

Hi

On 2026-10-06 11:17, marc@mabe.berlin wrote:

I think the following points still need some discussion. Some of
them may overlap with things others have already raised in this thread. Rather than replying to each of those messages separately, I've collected
everything in this one mail and mention who brought a point up where it
applies.

Thank you for the review. Derick and I already discussed some, but not all of the points. For now I'll just reply to those that are resolved to get them out of the way.

4. Configurable clock resolution

I'd like a way to configure the resolution,
e.g. a SystemClock that only ever returns whole seconds. Many consumers (JWT iat/exp, HTTP dates, database columns) never want fractions.
A clock configured that way guarantees whole seconds to every consumer it is injected into, instead of each consumer having to truncate on its own. It also makes test expectations simpler, because the values never carry
fractions.

We believe this is the job of a “Clock decorator”, e.g. `CoarseClock` that takes in some clock and appropriately rounds or truncates the Instant to the desired precision. Such a decorator would automatically be compatible with any type of clock (e.g. a `FrozenClock` for testing).

As with the testing clocks, we consider a `CoarseClock` out of scope for this RFC. With a possible future `truncateTo()` that I already mentioned elsewhere in the discussion, a userland implementation would become trivial for the use cases where a coarser clock is required.

7. get vs to

The RFC explicitly states that the Unix timestamp is not the internal
representation. getUnixTimestamp() is therefore a conversion, and by the RFC's own convention (toIso8601DateTimeString(), DateTime::toInstant()) it should be toUnixTimestamp(). Duration exposes its components as properties, so with get*() we'd end up with a third style within the same family.

Good catch, we renamed the methods to use the `to` prefix.

9. getNanoseconds()

It isn't obvious whether this returns the nanoseconds since epoch or the
nanoseconds within the current second. getNanoOfSecond() (Java's
NANO_OF_SECOND) would remove that ambiguity.

We believe that with the renaming of the “Unix timestamp” converter to use the `to` prefix and the lack of “Unix” in the name of `getNanoseconds()` the naming is clear enough. It is also easy to see that the result of `getNanoseconds()` can't be the number of nanoseconds elapsed since the Unix epoch, because the value is guaranteed to be less than 1_000_000_000 (i.e. less than 1 second). Using `nanoseconds` as the fractional part is consistent with `Duration::$nanoseconds`.

For completeness I'd like to note that the epoch of the Instant is intentionally left unspecified and that the Unix epoch is just one of several possible epochs.

Best regards
Tim Düsterhus

Hi,

On 7.10.2026 12:45 CEST Tim Düsterhus <tim@bastelstu.be> wrote:

Hi

On 2026-10-06 11:17, marc@mabe.berlin wrote:
> I think the following points still need some discussion. Some of
> them may overlap with things others have already raised in this thread.
> Rather than replying to each of those messages separately, I've
> collected
> everything in this one mail and mention who brought a point up where it
> applies.

Thank you for the review. Derick and I already discussed some, but not
all of the points. For now I'll just reply to those that are resolved to
get them out of the way.

> 4. Configurable clock resolution
>
> I'd like a way to configure the resolution,
> e.g. a SystemClock that only ever returns whole seconds. Many consumers
> (JWT iat/exp, HTTP dates, database columns) never want fractions.
> A clock configured that way guarantees whole seconds to every consumer
> it is injected into, instead of each consumer having to truncate on its
> own. It also makes test expectations simpler, because the values never
> carry
> fractions.

We believe this is the job of a “Clock decorator”, e.g. `CoarseClock`
that takes in some clock and appropriately rounds or truncates the
Instant to the desired precision. Such a decorator would automatically
be compatible with any type of clock (e.g. a `FrozenClock` for testing).

As with the testing clocks, we consider a `CoarseClock` out of scope for
this RFC. With a possible future `truncateTo()` that I already mentioned
elsewhere in the discussion, a userland implementation would become
trivial for the use cases where a coarser clock is required.

Fine by me to keep it out of scope for this RFC. For a future RFC, though, I'd prefer a built-in CoarseSystemClock over a generic decorator. A decorator always has to read the precise clock first and only then truncates, so it can never be cheaper than the clock it wraps. A built-in system clock configured for second (or millisecond) resolution could read a coarse clock source directly instead, such as CLOCK_REALTIME_COARSE on Linux.

On Linux arm64 I measured:

  clock_gettime(CLOCK_REALTIME) 13.3 ns
  clock_gettime(CLOCK_REALTIME_COARSE) 3.3 ns

> 9. getNanoseconds()
>
> It isn't obvious whether this returns the nanoseconds since epoch or
> the
> nanoseconds within the current second. getNanoOfSecond() (Java's
> NANO_OF_SECOND) would remove that ambiguity.

We believe that with the renaming of the “Unix timestamp” converter to
use the `to` prefix and the lack of “Unix” in the name of
`getNanoseconds()` the naming is clear enough. It is also easy to see
that the result of `getNanoseconds()` can't be the number of nanoseconds
elapsed since the Unix epoch, because the value is guaranteed to be less
than 1_000_000_000 (i.e. less than 1 second). Using `nanoseconds` as the
fractional part is consistent with `Duration::$nanoseconds`.

I'm not convinced yet

The value range is only "easy to see" after reading the documentation. The name alone should tell you what you get. Within the same class, the plural unit is used as a unit marker: toUnixTimestampMilliseconds() is "the timestamp in milliseconds". Read the same way, getNanoseconds() is "<something> in nanoseconds", and the only <something> an Instant has is its position on the timeline.

Duration is the wrong reference. A Duration is an amount, so "N nanoseconds" is correct there. An Instant is a point in time, and its sub-second part is a position within the second, not an amount. PEven the current DateTime* API already makes this distinction, using singular names:

     DateTime::getMicrosecond(): int
     DateTime::setMicrosecond(int $microsecond)
     DateTime::setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0)

while the plural is used for amounts:

     Duration::fromMicroseconds(int $microseconds)
     Duration::fromMilliseconds(int $milliseconds)

getNanoOfSecond() removes the ambiguity entirely, at the cost of a few characters. If that's too far from the existing naming, getNanosecond() would at least match DateTime::getMicrosecond().

For completeness I'd like to note that the epoch of the Instant is
intentionally left unspecified and that the Unix epoch is just one of
several possible epochs.

Agreed, and that's exactly the point I made about "follows POSIX time": if
the epoch and the representation are unspecified, the class definition
shouldn't state that Instants follow POSIX time. That belongs to the Unix
timestamp conversion methods.

Best regards,
Marc

Best regards
Tim Düsterhus

Hi

On 2026-10-06 18:56, Mirco Babin wrote:

(Mirco Babin) There is a misconception. The application does not
choose the abstracted clock truth for the Composer installed
libraries. It only chooses the clock for its internal parts. Each
piece of software, internal application and each different external
library, chooses its own source of abstracted clock truth, like:

Of course. If the library provides no way to inject a clock, then you can't inject a clock. What I meant to say is that if the libraries you use allow injecting a clock (e.g. PSR-20 or the new Time\Clock, or something else of course), then you can use the adapters to translate between the different interfaces, while having a single “canonical” clock as a source of truth.

If the library doesn't allow injecting a clock right now, then the introduction of the new interface is no worse than the status quo.

(Mirco Babin) Every effort, however small, however little, that eases
this migration path for applications, should be provided.

Also because Packagist psr/clock - Packagist.org shows
*439 458 545* (439 million) installations of the PSR-20 clock. This is
an *impure number*, because it also includes CI/test installations,
and it also includes nesbot/carbon and laravel/framework
installations.

*I agree to disagree.*

I'm happy to leave it at “agree to disagree”. I nevertheless thank you for raising your concern here.

Can the RFC be updated? Under rejected features can something be added
like:

A hybrid clock, both implementing \Time\Clock from this RFC and the
PSR-20 \Psr\Clock\ClockInterface is rejected. Because ...(reasons)...

I have added a short note to the rejected features section. For the full reasoning readers can read the mailing list discussion (linked at the top of the RFC). This also avoids accidentally misrepresenting the nuance provided in the discussion due to a lack of context.

Best regards
Tim Düsterhus

Hi

Due to the security releases it's been a while since I last looked into this RFC and I probably lost some of my working memory. Please indicate if there is something obvious that I missed somewhere or similar.

On 2026-10-06 11:17, marc@mabe.berlin wrote:

1. Naming of Clock::now()

The method returns an Instant, but the RFC already plans future classes that combine an instant with a timezone (a ZonedDateTime-like class). Callers
will want to get those from a clock directly as well, without going the long way around: $clock->now()->toZonedDateTime($zone). Once a clock can return more than one type, now() no longer says what you get.

A “point in time” is the canonical representation of “now” for the reasons that are also given in the RFC and this is also the type I expect to be returned, even without including it in the name. As you note yourself, a `ZonedDateTime` requires supplementary information (the timezone) to be provided at call time. For that I would also not call it “going the long way around”. As a direct comparison:

     $clock->now()->toZonedDateTime($zone)
     // vs your suggested
     $clock->takeZonedDateTime($zone)

saves a grand total of 5 characters, at the expense of making the “point in time” retrieval much more verbose. The `ZonedDateTime` will very likely be a thin wrapper over `Instant` + `Timezone`, thus the `Instant` object can just be reused as `ZonedDateTime::$instant`.

I would also say that using a `ZonedDateTime` as the default type for handling time is doing it wrong. The timezone is a presentation-layer concern and stuff you “present” to the user is generally expected to be coming from the database, rather than coming from the clock. Allowing comparisons between `ZonedDateTime` and “now” can be enabled by just making `ZonedDateTime::compare()` accept `Instant|ZonedDateTime` as the parameters. The nice part of the `compare()` method is that it's specifically designed for ordering rather than equality, thus a return value of `0` can mean “same point in time” even if the timezones differ.

One constraint thought, PHP interfaces can't have default implementations. Adding methods to Time\Clock later would break every userland clock. So either the interface should get its full shape now, or further result types should come in through factories on the target types
(see 2).

Yes, adding methods to interfaces after the fact is a breaking change and “huge interfaces” are an indicator of wrong design. Java solves this by making the Clock an abstract class, but this also is a heavy-weight solution to something that is not really a problem as per the above, so …

2. Instant::fromClock(Clock $clock)

You rejected Instant::now() because it would tie Instant to the SystemClock. With a required Clock parameter that objection goes away. It is exactly what Java does. Later classes can then follow the same pattern
(ZonedDateTime::fromClock($clock, $zone)) without the Clock interface ever
growing.

… that would be a reasonable middle-ground of providing convenience constructors. With the `from*()` prefix the naming is consistent and it doesn't magically invent information out of thin air. Given that it's pretty much redundant with `$clock->now()` with the current scope of the RFC, I would punt this to when `ZonedDateTime` is introduced so that it can be designed consistently across all classes.

3. Clock resolution

The docblock says "at the resolution offered by the underlying clock", but
nothing in the API exposes that resolution (Rob raised the same point). I
measured what the platforms report via clock_getres() and what they actually deliver:

As I noted in my reply to Rob, I don't believe this is something that belongs on the interface, since this information is unlikely to be actionable by a majority of applications …

                             clock_getres() smallest observed step
  macOS arm64, REALTIME 1 us 1 us
  Linux arm64, REALTIME 1 ns 42 ns (24 MHz counter)
  Linux, REALTIME_COARSE 1 ms -

So clock_getres() is honest on some systems and only nominal on others. I'd still like SystemClock to expose it, documented as the nominal resolution of the source. That is better than no information at all.

… but we can see how exposing the (nominal) resolution of specifically the SystemClock can be useful. I assume that a `SystemClock::getNominalResolution(): Duration` with the `Duration` being the greatest common divisor of possible returned values is what you would expect? I have just added a future scope note to the RFC, since I would need to do additional research into all the operating systems supported by PHP. It's probably also something that can just go in by “simple PR” without going through a full RFC, since this is a minor feature on a `final` class.

4. Configurable clock resolution

Handled previously.

5. Taking a Unix timestamp directly from a clock

Unix timestamps are used everywhere, not only in PHP, so "current time as a Unix timestamp" is a very common operation. Today that's time(), which can't be mocked. With this RFC the mockable replacement is
$clock->now()->getUnixTimestamp(), which always goes through an Instant
object. I'd like a way to take the Unix timestamp directly from the clock.

Our goal with this RFC series is to provide a well-designed and well-typed new API that nudges the user to do the right thing. Making “raw integers” a first class citizen would go against that goal to save 7 characters (and one object creation). The previous arguments against adding a `takeZonedDateTime()` or similar also apply here.

6. "Follows POSIX time" vs. "unspecified representation"

The RFC states that Instants "follow POSIX time". At the same time it says
that "the internal representation of Time\Instant is intentionally left
unspecified and there are deliberately no public properties. In particular
the 'Unix timestamp' is not the primary representation."

I think an unspecified internal representation is the right way forward. But it doesn't match the class being specified as POSIX time. POSIX time is not just one of many ways to look at an instant. It is a specific time
scale: seconds counted since 1970-01-01T00:00:00Z. If Instant follows POSIX time, then the Unix timestamp (plus a fraction of a second) is effectively the model of the class.

It's not quite seconds counted since 1970-01-01T00:00:00Z, the relevant part is that leap seconds are dropped (which makes the POSIX timescale different from UTC).

So I'd suggest not defining Instant itself in terms of POSIX time. POSIX
time is relevant where Unix timestamps come in or go out, so it belongs in
the documentation of the Unix timestamp constructor and getter, not in the
definition of the class.

I'll look into cleaning up the wording when handling the points that Rob mentioned.

7. get vs to

Handled previously.

8. getUnixTimestamp() / getUnixTimestampMilliseconds()

Only the milliseconds variant names its unit, and microseconds (used all
over PHP: microtime(), DateTime) and nanoseconds are missing entirely. A
single pair taking the unit as an argument would cover all of them and stay symmetric:

The `toUnixTimestamp()` + `getNanoseconds()` pair is the canonical representation of a Unix timestamp - with “seconds” also being arguably by far the most common interpretation when hearing “Unix timestamp”. The “milliseconds” variant is provided for interoperability convenience, in particular with JavaScript.

PHP’s existing `DateTime` does not provide functionality to obtain the timestamp as an integral number of microseconds, and `microtime()` either returns a `float` or a weird two-component pair as a string. I am not aware of anything commonly used that returns “integral microseconds since the Unix epoch”, do you know of anything?

  public static function fromUnixTimestamp(int $timestamp, TimeUnit $unit = TimeUnit::Second): self;
  public function toUnixTimestamp(TimeUnit $unit = TimeUnit::Second): int;

TimeUnit would be an enum of Second, Millisecond, Microsecond and
Nanosecond, rounding towards negative infinity as already specified. The

I do not find it obvious at all that “seconds” would be the largest supported unit of a `TimeUnit`.

9. getNanoseconds()

Handled previously.

10. Concepts the ISO-8601 pair brings into Instant

An Instant is described as a timezone-less point in time. The ISO-8601
constructor and getter bring in several concepts that Instant otherwise
deliberately avoids:

  a) parsing and formatting of date-time strings;
  b) UTC as the reference ("Z" means a zero offset from UTC; since RFC 9557 it formally means "UTC known, local offset unknown");
  c) a calendar: ISO 8601 uses the proleptic Gregorian calendar with year
     0000;
  d) an opinionated input and output format

Yes. I don't understand what you are getting at, though. There clearly has to be a way to represent a point in time in some way - and an ISO-8601 datetime string is one of the possible options, probably the most widely used one. The Unix timestamp is another one.

11. The accepted input grammar

The RFC says the parser is strict but "may not support all legal formats",
and that accepted formats can be extended "by a simple pull request". That
means the vote doesn't decide the accepted grammar. Widening it later is
also not BC-neutral for code that uses the parser as a validator. I'd like

Since the RFC guarantees that only legal formats will be accepted, you are able to use it as a validator. If your use case requires narrower validation, then you will need to perform custom validation according to whatever specification you are dealing with. This is not unique to the Instant class.

the RFC to specify the grammar explicitly and to state the outcome for the
cases Ilia listed: comma decimal sign, lowercase t/z, space separator,
-00:00, 24:00:00, 23:59:60, more than 9 fractional digits.

See my reply to Ilia (php.internals: Re: [RFC] Time\Instant and Time\Clock). The RFC changes are still open.

A related point:
the docblock requires "a zone offset" while the prose requires "a timezone". Is an RFC 9557 suffix such as [Europe/Berlin] accepted, rejected or ignored?

Thanks, I adjusted the prose to also require a “zone offset”.

12. The output format

The getter always emits Z, has a fractional part whose width depends on the value (omitted when zero, otherwise 9 digits), and uses signed expanded years outside 0000-9999.

You mentioned that the getter implements the RFC 3339 subset of ISO-8601.
That is not quite true: RFC 3339 only allows 4-digit years 0000-9999, so the output isn't RFC 3339 for expanded years.

That is a bit of a distinction without difference: RFC 3339 is only capable of representing years 0000 to 9999, so years outside of that range are by definition not representable as RFC 3339. The ISO-8601 getter specifically only switches to the expanded format outside that range. Adding a separate RFC 3339 getter that differs only by throwing an Exception for unrepresentable instants does not sound useful, since this Exception is not actionable in any way.

I also tested how well the possible outputs work as input for the existing
DateTime API (PHP 8.5):

  - new DateTimeImmutable($s) accepts all of them, but truncates the 9
    fractional digits to 6 without notice.
  - With createFromFormat() no single format string works. DATE_ATOM only
    matches whole seconds with 4-digit years. DATE_RFC3339_EXTENDED (.v,
    3 digits) never matches. 'Y-m-d\TH:i:s.uP' fails on 9 digits because
    'u' takes at most 6, so you need a hack like 'Y-m-d\TH:i:s.u???P'.
    Expanded years need 'X' instead of 'Y'.

Because the fractional part is only present for some values, any strict
consumer needs at least two format strings and has to choose between them,
which is the trap Ilia described. An output that always includes the
fractional part would at least make 'X-m-d\TH:i:s.u???P' work for every
value.

I do not believe that the existing `DateTime` API is a model of good design in that regard (and there are better ways for interoperability with it, as noted in php.internals: Re: [RFC] Time\Instant and Time\Clock). Only taking a fixed format is already a problem as of now, because “conditionally omitting the fractional part” is common.

The specified format is interoperable with JavaScript's `Temporal.Instant.from()`:

     > Temporal.Instant.from('1969-07-20T20:17:40Z')
     Temporal.Instant 1969-07-20T20:17:40Z

     > Temporal.Instant.from('1969-07-20T20:17:40.123456789Z')
     Temporal.Instant 1969-07-20T20:17:40.123456789Z

     > Temporal.Instant.from('1969-07-20T20:17:40.123000000Z')
     Temporal.Instant 1969-07-20T20:17:40.123Z

With Go’s time.RFC3339Nano:

     t, err := time.Parse(time.RFC3339Nano, "1969-07-20T20:17:40Z")
     fmt.Printf("%+v\n", t) // 1969-07-20 20:17:40 +0000 UTC
     fmt.Printf("%+v\n", err) // <nil>
     t, err = time.Parse(time.RFC3339Nano, "1969-07-20T20:17:40.123456789Z")
     fmt.Printf("%+v\n", t) // 1969-07-20 20:17:40.123456789 +0000 UTC
     fmt.Printf("%+v\n", err) // <nil>
     t, err = time.Parse(time.RFC3339Nano, "1969-07-20T20:17:40.123000000Z")
     fmt.Printf("%+v\n", t) // 1969-07-20 20:17:40.123 +0000 UTC
     fmt.Printf("%+v\n", err) // <nil>

With Java’s `java.time.Instant.parse()`:

     System.out.println(Instant.parse("1969-07-20T20:17:40Z")); // 1969-07-20T20:17:40Z
     System.out.println(Instant.parse("1969-07-20T20:17:40.123456789Z")); // 1969-07-20T20:17:40.123456789Z
     System.out.println(Instant.parse("1969-07-20T20:17:40.123000000Z")); // 1969-07-20T20:17:40.123Z

13. A dedicated parser/formatter instead

I'd prefer parsing and formatting to live in a dedicated parser/formatter
API (future scope) rather than on Instant, where it would sit next to the
other ISO-8601 profiles and custom patterns. If the pair stays on Instant,
the name should say what it really is (a fixed RFC 3339-like profile), and
the grammar should be part of what we vote on.

I agree with Larry’s DX argument here. I'd also like to note that the *output* format is fixed by the RFC. The input format is less constrained, but the RFC guarantees that it stays true to its name by only accepting what ISO-8601 specifies.

14. until() vs Duration::between()

Was Duration::between(Instant $a, Instant $b) considered? Calculating a
duration feels like Duration's responsibility to me.

That suggestion breaks down when measuring elapsed time with a monotonic clock. PHP does not support method overloading, so it would need to become `Duration::between(Instant|MonoInstant, Instant|MonoInstant)` which then also allows non-sense combinations.

15. Smaller things

  - On 32-bit, Duration only covers about 68 years, so until() is more
    limited there than the examples suggest. That's worth a sentence.

Added a note to `until()`’s docblock.

  - Duration uses sign-magnitude for its (seconds, nanoseconds) pair, while fromUnixTimestamp(-1, 500_000_000) uses floor semantics (-0.5s). Both are defensible, but the RFC should say why they differ.

Yes, the Unix timestamp needs “floor semantics” due to external constraints: The second part only ticks once the full second has elapsed. Negative Unix timestamps are also comparatively rare and not always well-defined (e.g. POSIX does not specify a negative `time_t`). This is different for Duration where negative values can regularly appear and where direct interaction with the properties is the expected use case.

Best regards
Tim Düsterhus

Hi

On 2026-10-06 18:16, Larry Garfield wrote:

7. get vs to

I agree with this. $foo->toBar() is a very common "type conversion" pattern, and it makes sense to use here as well.

Already adjusted a while ago.

8. getUnixTimestamp() / getUnixTimestampMilliseconds()

I would agree here as well.

See the reply I just sent to Marc.

13. A dedicated parser/formatter instead

I'd prefer parsing and formatting to live in a dedicated parser/formatter
API (future scope) rather than on Instant, where it would sit next to the
other ISO-8601 profiles and custom patterns. If the pair stays on Instant,
the name should say what it really is (a fixed RFC 3339-like profile), and
the grammar should be part of what we vote on.

I understand the tidiness/purity argument here, and I am generally sympathetic to it. However, that always needs to be balanced against usability. Any incoming date/time information to the PHP process is likely to be either an ISO-8601 string or a unix timestamp int. If we want people to convert those into Instants for doing manipulation and comparison on (which I presume is the case), then that needs to be ergonomically easy to do. Having to go through multiple parser/converter objects (which some purist is likely to insist be injected from a container rather than instantiated directly; I have been known to be that purist) to get there is not ergonomic. So if that logic is split off, we would need to be very careful to ensure the result is ergonomically simple and readily copy-pasteable.

Yes, I've expanded a little more in my own words in the reply I just sent to Marc.

Regarding the “purist note”: Injecting a formatter (into your template engine) actually is reasonable. The correct choice there would likely be one backed by ext/intl.

And of course, as I had noted in php.internals: Re: [RFC] Time\Instant and Time\Clock and the reply to Marc, arbitrary formatting is only well-defined for a `ZonedDateTime` (or `PlainDateTime` - naming tbd - when the timezone is implied). For `Instant` we can just use anything that unambiguously represents a point in time, which basically boils down to ISO-8601 date time with zone offset. Users are able to build their own parsers if they have a requirement for special formats. Or parse into `ZonedDateTime` and extract the instant via `ZonedDateTime::$instant` (or whatever it may be called).

14. until() vs Duration::between()

Was Duration::between(Instant $a, Instant $b) considered? Calculating a
duration feels like Duration's responsibility to me.

This also seems reasonable, as a named constructor of Duration.

See the reply I just sent to Marc.

Best regards
Tim Düsterhus

Hi

On 2026-10-07 12:04, Tim Düsterhus wrote:

We have now made the `SystemClock` a singleton with a `SystemClock::get()` factory / getter. The constructor is private now.

Something I forgot doing then, but I did now: SystemClock is now marked as `@not-serializable`, because well, it is not supposed to be serialized as a singleton.

Best regards
Tim Dsüterhus

Hi

On 2026-10-09 08:20, marc@mabe.berlin wrote:

As with the testing clocks, we consider a `CoarseClock` out of scope for
this RFC. With a possible future `truncateTo()` that I already mentioned
elsewhere in the discussion, a userland implementation would become
trivial for the use cases where a coarser clock is required.

Fine by me to keep it out of scope for this RFC. For a future RFC, though, I'd prefer a built-in CoarseSystemClock over a generic decorator. A decorator always has to read the precise clock first and only then truncates, so it can never be cheaper than the clock it wraps. A built-in system clock configured for second (or millisecond) resolution could read a coarse clock source directly instead, such as CLOCK_REALTIME_COARSE on Linux.

Fair enough regarding the performance argument. I was specifically thinking about use cases where truncating to whole seconds is required. I've added a “CoarseSystemClock” to the possible future scope list. Having it as a separate class makes sense to me to make using the coarse system clock a very explicit and deliberate choice. The correct default for the majority of use cases is the SystemClock, the coarse clock potentially doesn't even have millisecond resolution depending on your configured tick rate, isn't necessarily aligned to second boundaries and …

On Linux arm64 I measured:

  clock_gettime(CLOCK_REALTIME) 13.3 ns
  clock_gettime(CLOCK_REALTIME_COARSE) 3.3 ns

… 10 nanoseconds is likely not all that much compared to the overhead that PHP adds (e.g. object allocation).

We believe that with the renaming of the “Unix timestamp” converter to
use the `to` prefix and the lack of “Unix” in the name of
`getNanoseconds()` the naming is clear enough. It is also easy to see
that the result of `getNanoseconds()` can't be the number of nanoseconds
elapsed since the Unix epoch, because the value is guaranteed to be less
than 1_000_000_000 (i.e. less than 1 second). Using `nanoseconds` as the
fractional part is consistent with `Duration::$nanoseconds`.

I'm not convinced yet

[…]

getNanoOfSecond() removes the ambiguity entirely, at the cost of a few characters. If that's too far from the existing naming, getNanosecond() would at least match DateTime::getMicrosecond().

I'll put this on my list with Derick.

For completeness I'd like to note that the epoch of the Instant is
intentionally left unspecified and that the Unix epoch is just one of
several possible epochs.

Agreed, and that's exactly the point I made about "follows POSIX time": if
the epoch and the representation are unspecified, the class definition
shouldn't state that Instants follow POSIX time. That belongs to the Unix
timestamp conversion methods.

See my reply in php.internals: Re: [RFC] Time\Instant and Time\Clock.

Best regards
Tim Düsterhus

Hi Tim,

On 29.10.2026 14:39 CET Tim Düsterhus <tim@bastelstu.be> wrote:

Hi

Due to the security releases it's been a while since I last looked into
this RFC and I probably lost some of my working memory. Please indicate
if there is something obvious that I missed somewhere or similar.

On 2026-10-06 11:17, marc@mabe.berlin wrote:
> 3. Clock resolution
>
[...]

… but we can see how exposing the (nominal) resolution of specifically
the SystemClock can be useful. I assume that a
`SystemClock::getNominalResolution(): Duration` with the `Duration`
being the greatest common divisor of possible returned values is what
you would expect? [...]

Yes, that’s exactly what I would expect. Thanks for adding it to the future scope.

> 5. Taking a Unix timestamp directly from a clock
>
> Unix timestamps are used everywhere, not only in PHP, so "current time
> as a Unix timestamp" is a very common operation. Today that's time(),
> which can't be mocked. With this RFC the mockable replacement is
> $clock->now()->getUnixTimestamp(), which always goes through an Instant
> object. I'd like a way to take the Unix timestamp directly from the
> clock.

Our goal with this RFC series is to provide a well-designed and
well-typed new API that nudges the user to do the right thing. Making
“raw integers” a first class citizen would go against that goal to save
7 characters (and one object creation). The previous arguments against
adding a `takeZonedDateTime()` or similar also apply here.

This isn’t about saving characters. Software reads the current timestamp all the time and for many reasons, so that call should be as cheap as possible. With the proposed API, getting the Unix timestamp integer means creating an Instant object and making one more method call, only to get back the integer the system already returned in the first place.

>
> 8. getUnixTimestamp() / getUnixTimestampMilliseconds()
>
> Only the milliseconds variant names its unit, and microseconds (used
> all
> over PHP: microtime(), DateTime) and nanoseconds are missing entirely.
> A
> single pair taking the unit as an argument would cover all of them and
> stay symmetric:

The `toUnixTimestamp()` + `getNanoseconds()` pair is the canonical
representation of a Unix timestamp - with “seconds” also being arguably
by far the most common interpretation when hearing “Unix timestamp”. The
“milliseconds” variant is provided for interoperability convenience, in
particular with JavaScript.

I find it odd to give milliseconds a dedicated method just because one other language uses them as its main Unix timestamp resolution. And JavaScript doesn’t even use an integer there - it's a floating point. The result is an API that looks inconsistent: seconds and milliseconds are covered, microseconds and nanoseconds are not.

PHP’s existing `DateTime` does not provide functionality to obtain the
timestamp as an integral number of microseconds, and `microtime()`
either returns a `float` or a weird two-component pair as a string. I am
not aware of anything commonly used that returns “integral microseconds
since the Unix epoch”, do you know of anything?

Microseconds are the finest resolution in a lot of what PHP applications work with every day:

* PHP itself: DateTime/DateTimeImmutable, microtime()
* MySQL/MariaDB: DATETIME/TIMESTAMP with up to 6 fractional digits
* PostgreSQL: timestamp/timestamptz
* Apache Spark: TIMESTAMP
* Python: datetime/timedelta

> public static function fromUnixTimestamp(int $timestamp, TimeUnit
> $unit = TimeUnit::Second): self;
> public function toUnixTimestamp(TimeUnit $unit = TimeUnit::Second):
> int;
>
> TimeUnit would be an enum of Second, Millisecond, Microsecond and
> Nanosecond, rounding towards negative infinity as already specified.
> The

I do not find it obvious at all that “seconds” would be the largest
supported unit of a `TimeUnit`.

Agreed, it isn’t really a time unit. What about something like FractionUnit or SecondUnit, so that the name makes clear it covers seconds and their fractions only?

> 10. Concepts the ISO-8601 pair brings into Instant
>
> An Instant is described as a timezone-less point in time. The ISO-8601
> constructor and getter bring in several concepts that Instant otherwise
> deliberately avoids:
>
> a) parsing and formatting of date-time strings;
> b) UTC as the reference ("Z" means a zero offset from UTC; since RFC
> 9557 it formally means "UTC known, local offset unknown");
> c) a calendar: ISO 8601 uses the proleptic Gregorian calendar with
> year
> 0000;
> d) an opinionated input and output format

Yes. I don't understand what you are getting at, though. There clearly
has to be a way to represent a point in time in some way - and an
ISO-8601 datetime string is one of the possible options, probably the
most widely used one. The Unix timestamp is another one.

The RFC defines Instant as "an absolute point on the timeline of the universe". It also says the timeline of the universe "does not know about days or months". An ISO-8601 string is made of exactly those things: a calendar (years, months, days) and an offset from UTC. Both belong to the Earth, not to the timeline of the universe.

The Unix timestamp is different in nature. It is the distance from one point in time to another. Any point on the timeline of the universe needs at least one reference point to be expressed.

I see why the ISO-8601 representation is convenient, and I have never had to represent a time outside Earth myself. But is it really the right thing to do? At the very least, it conflicts with the definition of Instant.

> 11. The accepted input grammar
>
> The RFC says the parser is strict but "may not support all legal
> formats",
> and that accepted formats can be extended "by a simple pull request".
> That
> means the vote doesn't decide the accepted grammar. Widening it later
> is
> also not BC-neutral for code that uses the parser as a validator. I'd
> like

Since the RFC guarantees that only legal formats will be accepted, you
are able to use it as a validator. If your use case requires narrower
validation, then you will need to perform custom validation according to
whatever specification you are dealing with. This is not unique to the
Instant class.

My concern is the wording in the RFC: “It will only accept well-formed inputs, but may not support all legal formats” is very vague. It doesn’t say which legal formats are not supported, and I think that should be written out explicitly. ...

> the RFC to specify the grammar explicitly and to state the outcome for
> the
> cases Ilia listed: comma decimal sign, lowercase t/z, space separator,
> -00:00, 24:00:00, 23:59:60, more than 9 fractional digits.

See my reply to Ilia (php.internals: Re: [RFC] Time\Instant and Time\Clock).
The RFC changes are still open.

... OK

> A related point:
> the docblock requires "a zone offset" while the prose requires "a
> timezone". Is an RFC 9557 suffix such as [Europe/Berlin] accepted,
> rejected or ignored?

Thanks, I adjusted the prose to also require a “zone offset”.

> 12. The output format
>
> The getter always emits Z, has a fractional part whose width depends on
> the value (omitted when zero, otherwise 9 digits), and uses signed
> expanded years outside 0000-9999.
>
> You mentioned that the getter implements the RFC 3339 subset of
> ISO-8601.
> That is not quite true: RFC 3339 only allows 4-digit years 0000-9999,
> so the output isn't RFC 3339 for expanded years.

That is a bit of a distinction without difference: RFC 3339 is only
capable of representing years 0000 to 9999, so years outside of that
range are by definition not representable as RFC 3339. The ISO-8601
getter specifically only switches to the expanded format outside that
range. Adding a separate RFC 3339 getter that differs only by throwing
an Exception for unrepresentable instants does not sound useful, since
this Exception is not actionable in any way.

I did not ask for a separate RFC 3339 getter. I only wanted to point out that the output of toIso8601DateTimeString() does not conform to RFC 3339 in all cases - not more.

> I also tested how well the possible outputs work as input for the
> existing
> DateTime API (PHP 8.5):
>
> - new DateTimeImmutable($s) accepts all of them, but truncates the 9
> fractional digits to 6 without notice.
> - With createFromFormat() no single format string works. DATE_ATOM
> only
> matches whole seconds with 4-digit years. DATE_RFC3339_EXTENDED
> (.v,
> 3 digits) never matches. 'Y-m-d\TH:i:s.uP' fails on 9 digits
> because
> 'u' takes at most 6, so you need a hack like 'Y-m-d\TH:i:s.u???P'.
> Expanded years need 'X' instead of 'Y'.
>
> Because the fractional part is only present for some values, any strict
> consumer needs at least two format strings and has to choose between
> them,
> which is the trap Ilia described. An output that always includes the
> fractional part would at least make 'X-m-d\TH:i:s.u???P' work for every
> value.

I do not believe that the existing `DateTime` API is a model of good
design in that regard (and there are better ways for interoperability
with it, as noted in php.internals: Re: [RFC] Time\Instant and Time\Clock).
Only taking a fixed format is already a problem as of now, because
“conditionally omitting the fractional part” is common.

A lot of code depends on the existing DateTime API, so there should be a simple way to convert in both directions. The RFC already adds DateTimeInterface::toInstant(). Why not also add the reverse, e.g. DateTimeImmutable::createFromInstant() / DateTime::createFromInstant()?

>
> 13. A dedicated parser/formatter instead
>
> I'd prefer parsing and formatting to live in a dedicated
> parser/formatter
> API (future scope) rather than on Instant, where it would sit next to
> the
> other ISO-8601 profiles and custom patterns. If the pair stays on
> Instant,
> the name should say what it really is (a fixed RFC 3339-like profile),
> and
> the grammar should be part of what we vote on.

I agree with Larry’s DX argument here. I'd also like to note that the
*output* format is fixed by the RFC. The input format is less
constrained, but the RFC guarantees that it stays true to its name by
only accepting what ISO-8601 specifies.

About DX - the simplicity comes from having a dedicated function to parse/format to/from ISO-8601/Instant without having to instantiate or configure anything - which is a good argument but this can be solved differently as well without introducing concepts to Instant it is not designed for e.g. by proving helper functions `Time\parseIso8601DateTimeToInstant´, `Time\instantToIso8601DateTime`.

>
> 14. until() vs Duration::between()
>
> Was Duration::between(Instant $a, Instant $b) considered? Calculating a
> duration feels like Duration's responsibility to me.

That suggestion breaks down when measuring elapsed time with a monotonic
clock. PHP does not support method overloading, so it would need to
become `Duration::between(Instant|MonoInstant, Instant|MonoInstant)`
which then also allows non-sense combinations.

mh true

Thanks,
Marc Bennewitz