Skip to content

Commit 05ff694

Browse files
authored
Limit timestamp offsets from -18:00 to +18:00 (#7)
1 parent 0c63480 commit 05ff694

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "jtd-fuzz"
33
description = "Generates example data from JSON Typedef schemas"
4-
version = "0.1.13"
4+
version = "0.1.14"
55
license = "MIT"
66
authors = ["JSON Typedef Contributors"]
77
edition = "2018"

src/lib.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const MAX_SEQ_LENGTH: u8 = 8;
5858
///
5959
/// assert_eq!(jtd_fuzz::fuzz(&schema, &mut rng), json!({
6060
/// "name": "e",
61-
/// "createdAt": "1931-10-18T14:26:10-05:14",
61+
/// "createdAt": "1931-10-18T15:44:45-03:55",
6262
/// "favoriteNumbers": [166, 142]
6363
/// }));
6464
/// ```
@@ -161,9 +161,6 @@ fn fuzz_with_root<R: rand::Rng>(root: &jtd::Schema, rng: &mut R, schema: &jtd::S
161161
jtd::form::TypeValue::Timestamp => {
162162
use chrono::TimeZone;
163163

164-
// For timestamp generation, we're going to be real
165-
// psychotic.
166-
//
167164
// We'll generate timestamps with some random seconds offset
168165
// from UTC. Most of these random offsets will never have
169166
// been used historically, but they can nonetheless be used
@@ -172,7 +169,17 @@ fn fuzz_with_root<R: rand::Rng>(root: &jtd::Schema, rng: &mut R, schema: &jtd::S
172169
// Although timestamp_millis accepts an i64, not all values
173170
// in that range are permissible. The i32 range is entirely
174171
// safe.
175-
chrono::FixedOffset::east(rng.gen_range(-86_400 + 1, 86_400 - 1))
172+
//
173+
// Java's java.time.ZoneOffset restricts offsets to no more
174+
// than 18 hours from UTC:
175+
//
176+
// https://docs.oracle.com/javase/8/docs/api/java/time/ZoneOffset.html
177+
//
178+
// To make jtd-fuzz work out of the box with the Java
179+
// ecosystem, we will limit ourselves to the same range of
180+
// offsets.
181+
let max_offset = 18 * 60 * 60;
182+
chrono::FixedOffset::east(rng.gen_range(-max_offset, max_offset))
176183
.timestamp(rng.gen::<i32>() as i64, 0)
177184
.to_rfc3339()
178185
.into()

0 commit comments

Comments
 (0)