-
Notifications
You must be signed in to change notification settings - Fork 37
Follow up of API for large years #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0fea732
Add Display impls for ExtendedDateTime and ParsedDateTime
sylvestre 5373049
Add doc comments on expect_in_range and PartialEq<Zoned>
sylvestre db42f55
Remove Item::Timestamp enum variant
sylvestre 5b19a0a
Deduplicate test helpers using Display and expect_in_range
sylvestre 9e5b189
Add large-year coverage to fuzz target
sylvestre d72070f
docs: add ExtendedDateTime usage example to README
sylvestre d38c5d5
ci: add fuzz_large_year target to CI workflow
sylvestre 041505a
Display: preserve fractional seconds when present
sylvestre c720240
tests: cover Display fractional-second formatting
sylvestre 6b55732
Add assertions for month and day in date parsing test
sylvestre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #![no_main] | ||
|
|
||
| use arbitrary::Arbitrary; | ||
| use jiff::{civil::DateTime, tz::TimeZone}; | ||
| use libfuzzer_sys::fuzz_target; | ||
|
|
||
| #[derive(Arbitrary, Debug)] | ||
| struct Input { | ||
| /// Year for the base date (biased toward boundary years). | ||
| base_year_selector: u8, | ||
| /// Year to embed in a constructed large-year input string. | ||
| input_year: u32, | ||
| month: u8, | ||
| day: u8, | ||
| /// Suffix appended after the constructed date (e.g. relative items). | ||
| suffix: String, | ||
| /// Whether to also call parse_datetime (no base). | ||
| try_no_base: bool, | ||
| } | ||
|
|
||
| fn base_year(selector: u8) -> i16 { | ||
| match selector % 6 { | ||
| 0 => 2024, | ||
| 1 => 9998, | ||
| 2 => 9999, | ||
| 3 => 1, | ||
| 4 => 100, | ||
| _ => (selector as i16) * 40, | ||
| } | ||
| } | ||
|
|
||
| fn clamp_year(y: u32) -> u32 { | ||
| // Focus on the interesting range: 9990..=100_000 and 0..=20_000 | ||
| match y % 4 { | ||
| 0 => 9990 + (y % 20), // near boundary | ||
| 1 => 10000 + (y % 90_000), // large years | ||
| 2 => y % 20_000, // general range | ||
| _ => 2_147_485_540 + (y % 10), // near GNU_MAX_YEAR | ||
| } | ||
| } | ||
|
|
||
| fuzz_target!(|input: Input| { | ||
| let year = clamp_year(input.input_year); | ||
| let month = (input.month % 12) + 1; | ||
| let day = (input.day % 28) + 1; | ||
| let date_str = format!("{year:04}-{month:02}-{day:02} {}", input.suffix); | ||
|
|
||
| // Test parse_datetime (uses current time as base). | ||
| if input.try_no_base { | ||
| let _ = parse_datetime::parse_datetime(&date_str); | ||
| } | ||
|
|
||
| // Test parse_datetime_at_date with a controlled base. | ||
| let by = base_year(input.base_year_selector); | ||
| if let Ok(base) = DateTime::new(by, 1, 1, 0, 0, 0, 0) { | ||
| if let Ok(base) = base.to_zoned(TimeZone::UTC) { | ||
| let _ = parse_datetime::parse_datetime_at_date(base, &date_str); | ||
| } | ||
| } | ||
|
|
||
| // Also try a bare large year as a pure number. | ||
| let bare = format!("{year}"); | ||
| let _ = parse_datetime::parse_datetime(&bare); | ||
| }); |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.