Question
Can Carbon::setTestNow() preserve microseconds when given a float timestamp?
Ari River
0 reputation · 12 Jul 2021, 02:34 UTC
100.8K views0
Goal
Determine whether Carbon's static test clock can freeze time with microsecond precision when the value is supplied as a float.
Constraints
- Carbon 2.x truncates fractional seconds; Carbon 3.x claims to retain them but the rounding rule is undocumented.
- setTestNow() is global and process‑wide, affecting all Carbon calls, including CarbonImmutable instances created via constructor.
- Tests that compare timestamps formatted with the
uspecifier may be flaky if microseconds are lost.
Unresolved Questions
- What exact rounding or truncation does Carbon 2.x apply to microseconds when setTestNow receives a float?
- Does Carbon 3.x preserve the full microsecond value from a float input, or does it apply a different rounding strategy?
- Is there a recommended pattern to assert microsecond fidelity in automated tests across Carbon 2.x and 3.x?