feat: enhanced Unix timestamp detection with validation and edge case handling#1302
Open
suatkocar wants to merge 2 commits intopilotmoon:masterfrom
Open
feat: enhanced Unix timestamp detection with validation and edge case handling#1302suatkocar wants to merge 2 commits intopilotmoon:masterfrom
suatkocar wants to merge 2 commits intopilotmoon:masterfrom
Conversation
- Auto-detect if timestamp is in seconds or milliseconds (>= 1e12 = milliseconds) - Add support for parsing date strings (including extended year format with +) - Fix copy functionality - now copies result to clipboard - Add error handling for invalid inputs
- Add comprehensive validation for ambiguous 11-12 digit timestamps (seconds vs milliseconds) - Add validation for ambiguous 14-15 digit timestamps (milliseconds vs microseconds) - Extend date range validation to 1970-2300 to handle edge cases - Implement magnitude heuristic for 11-12 digit timestamps (threshold: 1e10) - Handle negative timestamps correctly (always treat as seconds) - Support microseconds (16 digits) and nanoseconds (19+ digits) - Based on industry standards (epochconverter.com, unixtimestamp.com) - Addresses known pitfalls from naive approaches (Pydantic issue #7940) Tested with 61 edge cases covering: - Epoch boundaries, negative timestamps, year boundaries - Ambiguous digit counts, real-world examples - All tests passing
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.
Problem
1762265258239) were incorrectly parsed as seconds, causing wrong date conversions (e.g., showing year 57813 instead of 2025)762265258239) were incorrectly interpreted, leading to dates like year 26125Solution
Enhanced timestamp detection algorithm based on industry standards (epochconverter.com, unixtimestamp.com):
Auto-detect timestamp format using digit count and validation:
Smart validation for ambiguous cases:
Copy result to clipboard in addition to showing it
Error handling for invalid inputs
Addresses known pitfalls from naive approaches (see Pydantic issue #7940)
Testing
✅ Seconds timestamp:
1535438729→2018-08-28 06:45:29 UTC✅ Milliseconds timestamp:
1762265258239→2025-11-04 14:07:32 UTC✅ Ambiguous 12-digit:
762265258239→1994-02-26 12:20:58 UTC(correctly detected as milliseconds)✅ Negative timestamp:
-1→1969-12-31 23:59:59 UTC✅ Microseconds:
946684800000000→2000-01-01 00:00:00 UTC✅ Nanoseconds:
946684800000000000→2000-01-01 00:00:00 UTCComprehensive testing: 61 edge cases covering epoch boundaries, negative timestamps, year boundaries, ambiguous digit counts, and real-world examples - all passing ✅