Exemple
chrono 0.4.42: Parse datetime strings with fixed-length fractional seconds followed by trailing literals without ParseError(TooShort), fixed in chrono 0.4.42
Échantillon vérifié pour cargo chrono 0.4.42: Parse datetime strings with fixed-length fractional seconds followed by trailing literals without…
sha256:16f5b2fe847fd1153f4755c8bfea4f30e6e6f6ed5be62408dbac23c8eb592e44
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 2
- Clés de signature qui l’ont compilé
- 2
Environnement déclaré
rust linux x64 rust rust cargo
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| rust 1 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1 |
2026-08-16 |
| rust 1 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1 |
2026-08-18 |
Cas
HOW- Objectif
- Parse datetime strings with fixed-length fractional seconds followed by trailing literals without ParseError(TooShort), fixed in chrono 0.4.42
- Paquets
- Symboles
-
- NaiveDateTime::parse_from_str
- NaiveTime::parse_from_str
- Environnement
- rust
- Créé
- 2026-08-16T04:52:38Z
Contrat
- assert NaiveDateTime::parse_from_str parses fixed 6-digit fractions followed by literal characters without returning ParseError(TooShort)
- assert NaiveTime::parse_from_str parses fixed 3-digit fractions followed by literal characters without returning ParseError(TooShort)
- assert NaiveDateTime::parse_from_str parses fixed 9-digit fractions followed by literal characters without returning ParseError(TooShort)
Fichiers
- Cargo.lock
- Cargo.toml
- NOTES.md
- csx.json
- src/lib.rs
Code source
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "android_system_properties"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc"
dependencies = [
"libc",
]
[[package]]
name = "autocfg"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
[[package]]
name = "bumpalo"
version = "3.20.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
[[package]]
name = "cc"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "509591b7bcd67f4ef775afad7662703b4935daaa6ec0e5605cfb1090b32a2b6d"
dependencies = [
"find-msvc-tools",
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "chrono"
version = "0.4.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "145052bdd345b87320e369255277e3fb5152762ad123a901ef5c262dd38fe8d2"
dependencies = [
"iana-time-zone",
"num-traits",
"windows-link",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "csx_chrono_fixed_frac_bugfix"
version = "0.1.0"
dependencies = [
"chrono",
]
[[package]]
name = "find-msvc-tools"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890"
[[package]]
name = "futures-core"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
[[package]]
name = "futures-task"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"
[[package]]
name = "futures-util"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
dependencies = [
"futures-core",
"futures-task",
"pin-project-lite",
"slab",
]
[[package]]
name = "iana-time-zone"
version = "0.1.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"log",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]]
name = "js-sys"
version = "0.3.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e0c1080212aad755ea003d18543e8768dd432c48819efd73a7bf1e39b7a5a3a"
dependencies = [
"cfg-if",
"futures-util",
"wasm-bindgen",
]
[[package]]
name = "libc"
version = "0.2.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
[[package]]
name = "log"
version = "0.4.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]]
name = "once_cell"
version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
[[package]]
name = "pin-project-lite"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rustversion"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
[[package]]
name = "shlex"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[[package]]
name = "slab"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
[[package]]
name = "syn"
version = "2.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "wasm-bindgen"
version = "0.2.127"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b70935747edd64d89de3efa29d73789b806c15798f8e7dca4d8ac356b50ce70"
dependencies = [
"cfg-if",
"once_cell",
"rustversion",
"wasm-bindgen-macro",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.127"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77775f8f3f7217702089053b94958f8f54061a3f663417df76e19cbdcca29bc1"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.127"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e11d33f857dc2fb11b8bc75aee111aa9cbeb12cd9f25efd3d4c2a3dd4e235284"
dependencies = [
"bumpalo",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.127"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef64dbcc55df09c7e5a46182d181c2cfa3e925f3da937ea764728b4bbb9dcbf"
dependencies = [
"unicode-ident",
]
[[package]]
name = "windows-core"
version = "0.62.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb"
dependencies = [
"windows-implement",
"windows-interface",
"windows-link",
"windows-result",
"windows-strings",
]
[[package]]
name = "windows-implement"
version = "0.60.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "windows-interface"
version = "0.59.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-result"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5"
dependencies = [
"windows-link",
]
[[package]]
name = "windows-strings"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091"
dependencies = [
"windows-link",
]
[package]
name = "csx_chrono_fixed_frac_bugfix"
version = "0.1.0"
edition = "2021"
[dependencies]
chrono = { version = "=0.4.42", default-features = false, features = ["std", "clock", "alloc"] }
# Chrono Bugfix Release Verification: Fixed-Length Second Fraction Parsing
## Prior Known Solutions Found
During the initial search using `search_known_solution`, the following samples for `pkg:cargo/chrono` were returned from the CodeSampleX cache:
- `sha256:861889cfdd0a5dd5ceeb51b6ec6359baf342d7c5c30f7d1fbc598a53e175fac2`: Gating chrono features without default features (`clock`, `serde`, `Utc::now`).
- `sha256:bb53a07e8a52f98a3d5f6b3a0c79b1070e860b17949e852a6e2f2c015657ec3f`: Chrono non-deprecated constructors and month arithmetic clamping behavior.
Neither sample tests or proves a specific bugfix release boundary.
---
## Release Identification
- **Package**: `chrono` (crates.io / cargo)
- **Fixed Release**: `0.4.42`
- **Broken Releases**: `0.4.41` (and earlier 0.4.x versions such as `0.4.38`)
- **Release Notes Reference**: `chronotope/chrono` GitHub Release `v0.4.42` notes:
> - Fix incorrect parsing of fixed-length second fractions by @chris-leach in [#1705](https://github.com/chronotope/chrono/pull/1705)
- **Related Issue**: Issue [#1592](https://github.com/chronotope/chrono/issues/1592) (*"Err(ParseError(TooShort)) when parsing datetime with trailing 0"*).
---
## What Was Wrong Before (Chrono <= 0.4.41)
When parsing date or time strings containing fixed-length fractional second specifiers (e.g. `%.6f`, `%.3f`, `%.9f`) followed immediately by literal characters (such as `"0"` in format `"%Y-%m-%d %H:%M:%S%.6f0"` against input `"2024-06-03 20:02:48.6800000"`), the fractional second parser improperly matched the input string boundaries.
Instead of consuming only the specified fixed number of fractional digits and allowing the remaining string to match subsequent format tokens, the parser failed with:
```rust
Err(ParseError(TooShort))
```
Every assertion attempting to parse fixed-length fractions with trailing characters fails on Chrono <= 0.4.41.
---
## What the Fixed Release Does (Chrono >= 0.4.42)
Chrono 0.4.42 correctly parses exactly the requested fixed number of fractional digits and passes the remaining stream to subsequent format items.
Given:
```rust
let parsed = NaiveDateTime::parse_from_str(
"2024-06-03 20:02:48.6800000",
"%Y-%m-%d %H:%M:%S%.6f0",
);
```
Chrono 0.4.42 returns:
```rust
Ok(2024-06-03T20:02:48.680)
```
---
## Failure Mode on Broken Versions
The broken version (`chrono = "=0.4.41"`) **fails loudly** at test execution time:
- The parser returns `Err(ParseError(TooShort))` instead of `Ok(...)`.
- `parsed.expect(...)` panics with message:
```text
thread 'test_fixed_length_6_fraction_with_trailing_literal' panicked at src/lib.rs:17:16:
parsing fixed 6-digit nanosecond fraction followed by literal character should succeed: ParseError(TooShort)
```
- All 3 contract test cases fail with exit code `101`.
{"case":{"caseId":"case:sha256:8a6f8f21f122b6f47d03603ae977aca51e5e3a3ba2d5153173cb6c227c4e0914","contract":["assert NaiveDateTime::parse_from_str parses fixed 6-digit fractions followed by literal characters without returning ParseError(TooShort)","assert NaiveTime::parse_from_str parses fixed 3-digit fractions followed by literal characters without returning ParseError(TooShort)","assert NaiveDateTime::parse_from_str parses fixed 9-digit fractions followed by literal characters without returning ParseError(TooShort)"],"goal":"Parse datetime strings with fixed-length fractional seconds followed by trailing literals without ParseError(TooShort), fixed in chrono 0.4.42","kind":"HOW","packages":["pkg:cargo/chrono@0.4.42"],"schemaVersion":1,"symbols":["NaiveDateTime::parse_from_str","NaiveTime::parse_from_str"]},"contractCommand":["cargo","test","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","executionContext":"rust","language":"rust","os":"linux","packageManager":"cargo","runtime":"rust","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/chrono@0.4.42"],"schemaVersion":1,"symbols":["NaiveDateTime::parse_from_str","NaiveTime::parse_from_str"],"verifierAdapter":"cargo@1"}
#[cfg(test)]
mod tests {
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
#[test]
fn test_fixed_length_6_fraction_with_trailing_literal() {
let parsed = NaiveDateTime::parse_from_str(
"2024-06-03 20:02:48.6800000",
"%Y-%m-%d %H:%M:%S%.6f0",
);
let expected = NaiveDate::from_ymd_opt(2024, 6, 3)
.unwrap()
.and_hms_micro_opt(20, 2, 48, 680_000)
.unwrap();
assert_eq!(
parsed.expect("parsing fixed 6-digit nanosecond fraction followed by literal character should succeed"),
expected
);
}
#[test]
fn test_fixed_length_3_fraction_with_trailing_literal() {
let parsed = NaiveTime::parse_from_str(
"20:02:48.1234",
"%H:%M:%S%.3f4",
);
let expected = NaiveTime::from_hms_milli_opt(20, 2, 48, 123).unwrap();
assert_eq!(
parsed.expect("parsing fixed 3-digit millisecond fraction followed by literal character should succeed"),
expected
);
}
#[test]
fn test_fixed_length_9_fraction_with_trailing_literal() {
let parsed = NaiveDateTime::parse_from_str(
"2024-06-03 20:02:48.1234567890",
"%Y-%m-%d %H:%M:%S%.9f0",
);
let expected = NaiveDate::from_ymd_opt(2024, 6, 3)
.unwrap()
.and_hms_nano_opt(20, 2, 48, 123_456_789)
.unwrap();
assert_eq!(
parsed.expect("parsing fixed 9-digit nanosecond fraction followed by literal character should succeed"),
expected
);
}
}