Skip to content

Commit

Permalink
Removed Timestamp::builder() in favor of with_year() and with_ymd()
Browse files Browse the repository at this point in the history
  • Loading branch information
popematt committed Jul 7, 2023
1 parent 77f1316 commit 1b7f921
Show file tree
Hide file tree
Showing 16 changed files with 193 additions and 303 deletions.
20 changes: 8 additions & 12 deletions src/binary/non_blocking/raw_binary_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ impl<A: AsRef<[u8]> + Expandable> IonReader for RawBinaryReader<A> {

// Year precision

let builder = Timestamp::builder().with_year(year);
let builder = Timestamp::with_year(year);
if buffer.is_empty() {
let timestamp = builder.build()?;
return Ok(timestamp);
Expand Down Expand Up @@ -1648,32 +1648,30 @@ mod tests {
expect_value(reader.next(), IonType::Timestamp);
assert_eq!(
reader.read_timestamp()?,
Timestamp::builder().with_year(2022).build()?
Timestamp::with_year(2022).build()?
);
expect_value(reader.next(), IonType::Timestamp);
assert_eq!(
reader.read_timestamp()?,
Timestamp::builder().with_year(2022).with_month(6).build()?
Timestamp::with_year(2022).with_month(6).build()?
);
expect_value(reader.next(), IonType::Timestamp);
assert_eq!(
reader.read_timestamp()?,
Timestamp::builder().with_ymd(2022, 6, 18).build()?
Timestamp::with_ymd(2022, 6, 18).build()?
);
expect_value(reader.next(), IonType::Timestamp);
assert_eq!(
reader.read_timestamp()?,
Timestamp::builder()
.with_ymd(2022, 6, 18)
Timestamp::with_ymd(2022, 6, 18)
.with_hour_and_minute(11, 30)
.with_offset(0)
.build()?
);
expect_value(reader.next(), IonType::Timestamp);
assert_eq!(
reader.read_timestamp()?,
Timestamp::builder()
.with_ymd(2022, 6, 18)
Timestamp::with_ymd(2022, 6, 18)
.with_hms(11, 30, 51)
.with_milliseconds(115)
.with_offset(-5 * 60)
Expand All @@ -1683,8 +1681,7 @@ mod tests {
expect_value(reader.next(), IonType::Timestamp);
assert_eq!(
reader.read_timestamp()?,
Timestamp::builder()
.with_ymd(2022, 6, 9)
Timestamp::with_ymd(2022, 6, 9)
.with_hms(23, 0, 59)
.with_milliseconds(45)
.with_offset(0)
Expand All @@ -1694,8 +1691,7 @@ mod tests {
expect_value(reader.next(), IonType::Timestamp);
assert_eq!(
reader.read_timestamp()?,
Timestamp::builder()
.with_ymd(2022, 6, 9)
Timestamp::with_ymd(2022, 6, 9)
.with_hms(22, 59, 59)
.with_milliseconds(0)
.with_offset(0)
Expand Down
22 changes: 11 additions & 11 deletions src/binary/raw_binary_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,17 +1038,17 @@ mod writer_tests {
}

#[rstest]
#[case::year(Timestamp::builder().with_year(2021).build().unwrap())]
#[case::year_month(Timestamp::builder().with_year(2021).with_month(1).build().unwrap())]
#[case::year_month_day(Timestamp::builder().with_ymd(2021, 1, 8).build().unwrap())]
#[case::ymd_hm_unknown(Timestamp::builder().with_ymd(2021, 1, 8).with_hour_and_minute(14, 12).build().unwrap())]
#[case::ymd_hm_est(Timestamp::builder().with_ymd(2021, 1, 8).with_hour_and_minute(14, 12).with_offset(-5 * 60).build().unwrap())]
#[case::ymd_hms_unknown(Timestamp::builder().with_ymd(2021, 1, 8).with_hms(14, 12, 36).build().unwrap())]
#[case::ymd_hms_est(Timestamp::builder().with_ymd(2021, 1, 8).with_hms(14, 12, 36).with_offset(-5 * 60).build().unwrap())]
#[case::ymd_hms_millis_unknown(Timestamp::builder().with_ymd(2021, 1, 8).with_hms(14, 12, 36).with_milliseconds(888).build().unwrap())]
#[case::ymd_hms_millis_est(Timestamp::builder().with_ymd(2021, 1, 8).with_hms(14, 12, 36).with_milliseconds(888).with_offset(-5 * 60).build().unwrap())]
#[case::ymd_hms_nanos_unknown(Timestamp::builder().with_ymd(2021, 1, 8).with_hms(14, 12, 36).with_nanoseconds(888888888).build().unwrap())]
#[case::ymd_hms_nanos_est(Timestamp::builder().with_ymd(2021, 1, 8).with_hms(14, 12, 36).with_nanoseconds(888888888).with_offset(-5 * 60).build().unwrap())]
#[case::year(Timestamp::with_year(2021).build().unwrap())]
#[case::year_month(Timestamp::with_year(2021).with_month(1).build().unwrap())]
#[case::year_month_day(Timestamp::with_ymd(2021, 1, 8).build().unwrap())]
#[case::ymd_hm_unknown(Timestamp::with_ymd(2021, 1, 8).with_hour_and_minute(14, 12).build().unwrap())]
#[case::ymd_hm_est(Timestamp::with_ymd(2021, 1, 8).with_hour_and_minute(14, 12).with_offset(-5 * 60).build().unwrap())]
#[case::ymd_hms_unknown(Timestamp::with_ymd(2021, 1, 8).with_hms(14, 12, 36).build().unwrap())]
#[case::ymd_hms_est(Timestamp::with_ymd(2021, 1, 8).with_hms(14, 12, 36).with_offset(-5 * 60).build().unwrap())]
#[case::ymd_hms_millis_unknown(Timestamp::with_ymd(2021, 1, 8).with_hms(14, 12, 36).with_milliseconds(888).build().unwrap())]
#[case::ymd_hms_millis_est(Timestamp::with_ymd(2021, 1, 8).with_hms(14, 12, 36).with_milliseconds(888).with_offset(-5 * 60).build().unwrap())]
#[case::ymd_hms_nanos_unknown(Timestamp::with_ymd(2021, 1, 8).with_hms(14, 12, 36).with_nanoseconds(888888888).build().unwrap())]
#[case::ymd_hms_nanos_est(Timestamp::with_ymd(2021, 1, 8).with_hms(14, 12, 36).with_nanoseconds(888888888).with_offset(-5 * 60).build().unwrap())]
fn binary_writer_timestamps(#[case] timestamp: Timestamp) -> IonResult<()> {
binary_writer_scalar_test(
&[timestamp],
Expand Down
4 changes: 2 additions & 2 deletions src/element/element_stream_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ mod reader_tests {
next_type(reader, IonType::Timestamp, false);
assert_eq!(
reader.read_timestamp()?,
Timestamp::builder().with_ymd(2007, 7, 12).build().unwrap()
Timestamp::with_ymd(2007, 7, 12).build().unwrap()
);
next_type(reader, IonType::Symbol, false);
assert_eq!(reader.read_symbol()?, Symbol::owned("foo"));
Expand All @@ -505,7 +505,7 @@ mod reader_tests {
#[case(" 738 ", 738)]
#[case(" 2.5e0 ", 2.5)]
#[case(" 2.5 ", Decimal::new(25, -1))]
#[case(" 2007-07-12T ", Timestamp::builder().with_ymd(2007, 7, 12).build().unwrap())]
#[case(" 2007-07-12T ", Timestamp::with_ymd(2007, 7, 12).build().unwrap())]
#[case(" foo ", Symbol::owned("foo"))]
#[case(" \"hi!\" ", "hi!".to_owned())]
#[case(" {{ZW5jb2RlZA==}} ", Blob::from("encoded"))]
Expand Down
36 changes: 12 additions & 24 deletions src/element/element_stream_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,15 +434,13 @@ mod tests {

#[test]
fn write_timestamp_with_year() {
let timestamp = Timestamp::builder()
.with_year(2000)
let timestamp = Timestamp::with_year(2000)
.build()
.expect("building timestamp failed");
writer_scalar_test(
|w| w.write_timestamp(&timestamp),
Value::Timestamp(
Timestamp::builder()
.with_year(2000)
Timestamp::with_year(2000)
.build()
.expect("timestamp expected value"),
),
Expand All @@ -451,16 +449,14 @@ mod tests {

#[test]
fn write_timestamp_with_month() {
let timestamp = Timestamp::builder()
.with_year(2000)
let timestamp = Timestamp::with_year(2000)
.with_month(8)
.build()
.expect("building timestamp failed");
writer_scalar_test(
|w| w.write_timestamp(&timestamp),
Value::Timestamp(
Timestamp::builder()
.with_year(2000)
Timestamp::with_year(2000)
.with_month(8)
.build()
.expect("timestamp expected value"),
Expand All @@ -470,15 +466,13 @@ mod tests {

#[test]
fn write_timestamp_with_ymd() {
let timestamp = Timestamp::builder()
.with_ymd(2000, 8, 22)
let timestamp = Timestamp::with_ymd(2000, 8, 22)
.build()
.expect("building timestamp failed");
writer_scalar_test(
|w| w.write_timestamp(&timestamp),
Value::Timestamp(
Timestamp::builder()
.with_year(2000)
Timestamp::with_year(2000)
.with_month(8)
.with_day(22)
.build()
Expand All @@ -489,17 +483,15 @@ mod tests {

#[test]
fn write_timestamp_with_ymd_hms() {
let timestamp = Timestamp::builder()
.with_ymd(2000, 8, 22)
let timestamp = Timestamp::with_ymd(2000, 8, 22)
.with_hms(15, 45, 11)
.with_offset(2 * 60)
.build()
.expect("building timestamp failed");
writer_scalar_test(
|w| w.write_timestamp(&timestamp),
Value::Timestamp(
Timestamp::builder()
.with_year(2000)
Timestamp::with_year(2000)
.with_month(8)
.with_day(22)
.with_hms(15, 45, 11)
Expand All @@ -512,8 +504,7 @@ mod tests {

#[test]
fn write_timestamp_with_ymd_hms_millis() {
let timestamp = Timestamp::builder()
.with_ymd(2000, 8, 22)
let timestamp = Timestamp::with_ymd(2000, 8, 22)
.with_hms(15, 45, 11)
.with_milliseconds(931)
.with_offset(-5 * 60)
Expand All @@ -522,8 +513,7 @@ mod tests {
writer_scalar_test(
|w| w.write_timestamp(&timestamp),
Value::Timestamp(
Timestamp::builder()
.with_year(2000)
Timestamp::with_year(2000)
.with_month(8)
.with_day(22)
.with_hms(15, 45, 11)
Expand All @@ -537,17 +527,15 @@ mod tests {

#[test]
fn write_timestamp_with_ymd_hms_millis_unknown_offset() {
let timestamp = Timestamp::builder()
.with_ymd(2000, 8, 22)
let timestamp = Timestamp::with_ymd(2000, 8, 22)
.with_hms(15, 45, 11)
.with_milliseconds(931)
.build()
.expect("building timestamp failed");
writer_scalar_test(
|w| w.write_timestamp(&timestamp),
Value::Timestamp(
Timestamp::builder()
.with_year(2000)
Timestamp::with_year(2000)
.with_month(8)
.with_day(22)
.with_hms(15, 45, 11)
Expand Down
8 changes: 4 additions & 4 deletions src/element/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ mod reader_tests {
2020-02-27T14:16:33.123Z
"#,
vec![
Timestamp::builder().with_year(2020).build(),
Timestamp::builder().with_ymd(2020, 2, 27).build(),
Timestamp::builder().with_ymd(2020, 2, 27)
Timestamp::with_year(2020).build(),
Timestamp::with_ymd(2020, 2, 27).build(),
Timestamp::with_ymd(2020, 2, 27)
.with_hms(14, 16, 33)
.build(),
Timestamp::builder().with_ymd(2020, 2, 27)
Timestamp::with_ymd(2020, 2, 27)
.with_hms(14, 16, 33)
.with_milliseconds(123)
.with_offset(0).build(),
Expand Down
2 changes: 1 addition & 1 deletion src/lazy/binary/raw/lazy_raw_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl<'data> LazyRawValue<'data> {

// Year precision

let builder = Timestamp::builder().with_year(year);
let builder = Timestamp::with_year(year);
if input.is_empty() {
let timestamp = builder.build()?;
return Ok(RawValueRef::Timestamp(timestamp));
Expand Down
2 changes: 1 addition & 1 deletion src/lazy/binary/system/lazy_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ mod tests {
#[case::float("2.5e0", 2.5f64)]
#[case::special_float("-inf", f64::neg_infinity())]
#[case::decimal("3.14159", Decimal::new(314159, -5))]
#[case::timestamp("2023-04-29T", Timestamp::builder().with_ymd(2023, 4, 29).build()?)]
#[case::timestamp("2023-04-29T", Timestamp::with_ymd(2023, 4, 29).build()?)]
#[case::symbol("foo", Symbol::owned("foo"))]
#[case::string("\"hello\"", "hello")]
#[case::blob("{{Blob}}", Element::blob([0x06, 0x5A, 0x1B]))]
Expand Down
3 changes: 1 addition & 2 deletions src/lazy/raw_value_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ mod tests {
);
assert_eq!(
reader.next()?.expect_value()?.read()?.expect_timestamp()?,
Timestamp::builder()
.with_ymd(2023, 4, 29)
Timestamp::with_ymd(2023, 4, 29)
.with_hms(13, 45, 38)
.with_milliseconds(281)
.with_offset(0)
Expand Down
4 changes: 2 additions & 2 deletions src/lazy/value_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ mod tests {
);
assert_eq!(
reader.expect_next()?.read()?.expect_timestamp()?,
Timestamp::builder().with_ymd(2023, 4, 29).build()?
Timestamp::with_ymd(2023, 4, 29).build()?
);
assert_eq!(
reader.expect_next()?.read()?.expect_symbol()?,
Expand Down Expand Up @@ -298,7 +298,7 @@ mod tests {
);
assert_eq!(
reader.expect_next()?.read()?,
ValueRef::Timestamp(Timestamp::builder().with_ymd(2023, 4, 29).build()?)
ValueRef::Timestamp(Timestamp::with_ymd(2023, 4, 29).build()?)
);
assert_eq!(
reader.expect_next()?.read()?,
Expand Down
8 changes: 4 additions & 4 deletions src/text/non_blocking/raw_text_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ mod reader_tests {
#[case(" 738 ", TextValue::Int(738.into()))]
#[case(" 2.5e0 ", TextValue::Float(2.5))]
#[case(" 2.5 ", TextValue::Decimal(Decimal::new(25, -1)))]
#[case(" 2007-07-12T ", TextValue::Timestamp(Timestamp::builder().with_ymd(2007, 7, 12).build().unwrap()))]
#[case(" 2007-07-12T ", TextValue::Timestamp(Timestamp::with_ymd(2007, 7, 12).build().unwrap()))]
#[case(" foo ", TextValue::Symbol(text_token("foo")))]
#[case(" \"hi!\" ", TextValue::String("hi!".to_owned()))]
#[case(" {{ZW5jb2RlZA==}} ", TextValue::Blob(Vec::from("encoded".as_bytes())))]
Expand Down Expand Up @@ -1185,7 +1185,7 @@ mod reader_tests {
next_type(reader, IonType::Timestamp, false);
assert_eq!(
reader.read_timestamp()?,
Timestamp::builder().with_ymd(2021, 9, 25).build().unwrap()
Timestamp::with_ymd(2021, 9, 25).build().unwrap()
);

next_type(reader, IonType::Symbol, false);
Expand Down Expand Up @@ -1260,7 +1260,7 @@ mod reader_tests {
next_type(reader, IonType::Timestamp, false);
assert_eq!(
reader.read_timestamp()?,
Timestamp::builder().with_ymd(2014, 6, 26).build()?
Timestamp::with_ymd(2014, 6, 26).build()?
);
// TODO: Check for 'km' annotation after change to OwnedSymbolToken
next_type(reader, IonType::Int, false);
Expand Down Expand Up @@ -1308,7 +1308,7 @@ mod reader_tests {
next_type(reader, IonType::Timestamp, false);
assert_eq!(
reader.read_timestamp()?,
Timestamp::builder().with_ymd(2021, 9, 25).build().unwrap()
Timestamp::with_ymd(2021, 9, 25).build().unwrap()
);
annotations_eq(reader, [100, 200, 300]);

Expand Down
Loading

0 comments on commit 1b7f921

Please sign in to comment.