Add LocalDate and sub-second precision support.#10
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds two major capabilities to the tiny-blocks Time library: a new LocalDate value object for date-only modeling, and configurable ISO-8601 emission precision for Instant (seconds/milliseconds/microseconds), including decoding of fractional seconds.
Changes:
- Introduces
LocalDate(+InvalidLocalDate) and documentation/tests for date-only operations and projecting anInstantinto a civil date. - Adds
Precisionand extendsInstant::toIso8601()to optionally emit milliseconds/microseconds; updates offset datetime decoding to accept fractional seconds. - Refactors multiple unit tests toward more explicit Given/When/Then steps and expands Instant coverage for precision formatting.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/TimezonesTest.php | Refactors assertions/BDD step annotations for Timezones. |
| tests/Unit/TimeOfDayTest.php | Refactors assertions/BDD step annotations for TimeOfDay. |
| tests/Unit/PeriodTest.php | Minor refactor of overlap/contains assertions to store intermediate results. |
| tests/Unit/LocalDateTest.php | New comprehensive unit test suite for LocalDate. |
| tests/Unit/InstantTest.php | Adds Precision coverage and more fractional-second parsing/formatting tests. |
| tests/Unit/DurationTest.php | Refactors assertions/BDD steps for Duration comparisons and accessors. |
| tests/Unit/DayOfWeekTest.php | Refactors tests using cases()/array helpers and explicit intermediate variables. |
| src/Timezones.php | PHPDoc wording tweaks for factories and toStrings(). |
| src/Timezone.php | PHPDoc wording tweaks for toString() / toDateTimeZone(). |
| src/TimeOfDay.php | PHPDoc wording tweaks + renames local $diff to $difference in durationUntil(). |
| src/Precision.php | New public enum to represent ISO-8601 emission granularity. |
| src/LocalDate.php | New public value object for date-only operations (parse/format/compare/day arithmetic). |
| src/Internal/Decoders/OffsetDateTimeDecoder.php | Adds fractional-second decoding for offset ISO-8601 instants. |
| src/Instant.php | Adds Precision support in toIso8601() and introduces toLocalDate(). |
| src/Exceptions/InvalidLocalDate.php | New exception type for invalid local-date parsing/component validation. |
| README.md | Documents Precision usage and introduces LocalDate section + updates license link. |
| phpstan.neon.dist | Adds a suppression targeting Instant::fromUnixSeconds() return type handling. |
| .claude/rules/php-library-testing.md | Clarifies allowed non-test methods (lifecycle hooks + data providers). |
| .claude/rules/php-library-code-style.md | Updates member-ordering rule semantics and Internal/ PHPDoc guidance. |
Comments suppressed due to low confidence (2)
src/Timezones.php:114
toStrings()returns a list of IANA identifiers; the summary "Returns the Timezones as strings" is vague compared to the previous wording. Consider restoring the more specific description (identifiers as plain strings) so the PHPDoc matches the return type semantics.
/**
* Returns the Timezones as strings.
*
* @return list<string> The list of IANA timezone identifier strings.
*/
public function toStrings(): array
tests/Unit/InstantTest.php:1025
- This data set calls
toIso8601(precision: Precision::Seconds), butSecondsis the method default. Per the code-style rules, default-valued arguments should be omitted; the default behavior is already covered bytestToIso8601DefaultPrecisionIsSeconds(). Consider removing this case or switching it to the no-argument call.
'Seconds precision, no fractions emitted' => [
'value' => '2026-02-17 08:27:21.106011',
'precision' => Precision::Seconds,
'expectedIso8601' => '2026-02-17T08:27:21+00:00'
],
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
What this pull request does.
Related issue
Closes #...
Checklist
composer reviewpasses.composer testspasses.