Skip to content

add idForTimestamp() - #86

Merged
godruoyi merged 9 commits into
godruoyi:masterfrom
cosmastech:patch-1
Apr 23, 2026
Merged

godruoyi merged 9 commits into
godruoyi:masterfrom
cosmastech:patch-1

Conversation

@cosmastech

Copy link
Copy Markdown
Contributor

My team is working on back-filling snowflake IDs for a number of database records. It would be really nice to be able to pull the DB record's created_at timestamp and use that when generating the historic Snowflake IDs.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.79%. Comparing base (dec895d) to head (67dfbe3).
⚠️ Report is 10 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master      #86      +/-   ##
============================================
+ Coverage     98.71%   98.79%   +0.07%     
- Complexity       91       98       +7     
============================================
  Files             7        8       +1     
  Lines           234      248      +14     
============================================
+ Hits            231      245      +14     
  Misses            3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for injecting a custom “current time” resolver into Snowflake so callers can generate IDs based on historical timestamps (e.g., DB created_at) instead of wall-clock time.

Changes:

  • Introduces an optional Closure time resolver with setter/getter on Snowflake.
  • Updates getCurrentMillisecond() to use the injected resolver when present.
  • Adds a PHPUnit test validating resolver injection and timestamp encoding.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/Snowflake.php Adds configurable time resolver and wires it into current-time computation.
tests/SnowflakeTest.php Adds unit test covering the new time resolver behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Snowflake.php Outdated
Comment thread src/Snowflake.php Outdated
Comment thread src/Snowflake.php
Comment thread src/Snowflake.php
Comment thread src/Snowflake.php
Comment thread tests/SnowflakeTest.php Outdated

@godruoyi godruoyi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your PR @cosmastech i love it, just left a two nit comments,

Comment thread src/Snowflake.php Outdated
Comment thread src/Snowflake.php Outdated
Comment thread src/Snowflake.php Outdated
@cosmastech
cosmastech requested a review from godruoyi April 23, 2026 01:42
@cosmastech

Copy link
Copy Markdown
Contributor Author

Let me know if this is what you had in mind @godruoyi 🙇

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/SnowflakeTest.php Outdated
Comment thread src/Snowflake.php Outdated
Comment thread src/Snowflake.php Outdated

@godruoyi godruoyi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your quick update. This change looks great and all LGT. Its waiting for the AI to review again.

godruoyi and others added 2 commits April 23, 2026 09:54
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@godruoyi
godruoyi merged commit 46bf78b into godruoyi:master Apr 23, 2026
6 checks passed
@godruoyi

Copy link
Copy Markdown
Owner

@cosmastech Released in https://github.com/godruoyi/php-snowflake/releases/tag/3.2.3, Please give it a try and let me know if you run into any issues.

@cosmastech cosmastech changed the title allow setting a time resolver add idForTimestamp() Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants