Skip to content

Commit 5b4f46d

Browse files
authored
Updates to PlainYearMonth and PlainMonthDay based on review (#567)
Changes made: - month_day.rs and year_month.rs to plain_month_day.rs and plain_year_month.rs - Remove padded_iso_year_string from PlainYearMonth
1 parent 6b7fd1d commit 5b4f46d

File tree

8 files changed

+8
-59
lines changed

8 files changed

+8
-59
lines changed

src/builtins/core/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ pub mod duration;
1111
pub mod timezone;
1212

1313
mod instant;
14-
mod month_day;
1514
mod plain_date;
1615
mod plain_date_time;
16+
mod plain_month_day;
1717
mod plain_time;
18-
mod year_month;
18+
mod plain_year_month;
1919
pub(crate) mod zoned_date_time;
2020

2121
mod now;
@@ -28,14 +28,14 @@ pub use duration::{DateDuration, Duration, PartialDuration};
2828
#[doc(inline)]
2929
pub use instant::Instant;
3030
#[doc(inline)]
31-
pub use month_day::PlainMonthDay;
32-
#[doc(inline)]
3331
pub use plain_date::{PartialDate, PlainDate};
3432
#[doc(inline)]
3533
pub use plain_date_time::{DateTimeFields, PartialDateTime, PlainDateTime};
3634
#[doc(inline)]
35+
pub use plain_month_day::PlainMonthDay;
36+
#[doc(inline)]
3737
pub use plain_time::{PartialTime, PlainTime};
3838
#[doc(inline)]
39-
pub use year_month::{PartialYearMonth, PlainYearMonth};
39+
pub use plain_year_month::{PartialYearMonth, PlainYearMonth};
4040
#[doc(inline)]
4141
pub use zoned_date_time::{PartialZonedDateTime, ZonedDateTime, ZonedDateTimeFields};

src/builtins/core/month_day.rs renamed to src/builtins/core/plain_month_day.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ impl PlainMonthDay {
370370
.into()
371371
}
372372

373+
/// Creates a RFC9557 IXDTF [`Writeable`].
373374
pub fn to_ixdtf_writeable(&self, display_calendar: DisplayCalendar) -> impl Writeable + '_ {
374375
let ixdtf = FormattableMonthDay {
375376
date: FormattableDate(self.iso_year(), self.iso_month(), self.iso.day),

src/builtins/core/year_month.rs renamed to src/builtins/core/plain_year_month.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use crate::{
1717
provider::{NeverProvider, TimeZoneProvider},
1818
temporal_assert,
1919
unix_time::EpochNanoseconds,
20-
utils::pad_iso_year,
2120
Calendar, MonthCode, TemporalError, TemporalResult, TemporalUnwrap, TimeZone,
2221
};
2322

@@ -391,14 +390,14 @@ impl PlainYearMonth {
391390
/// Creates a new `PlainYearMonth` with an ISO 8601 calendar, rejecting any date that may be invalid.
392391
#[inline]
393392
pub fn try_new_iso(year: i32, month: u8, reference_day: Option<u8>) -> TemporalResult<Self> {
394-
Self::try_new(year, month, reference_day, Calendar::default())
393+
Self::try_new(year, month, reference_day, Calendar::ISO)
395394
}
396395

397396
/// Creates a new `PlainYearMonth` with an ISO 8601 calendar, constraining any arguments
398397
/// that are invalid into a valid range.
399398
#[inline]
400399
pub fn new_iso(year: i32, month: u8, reference_day: Option<u8>) -> TemporalResult<Self> {
401-
Self::new(year, month, reference_day, Calendar::default())
400+
Self::new(year, month, reference_day, Calendar::ISO)
402401
}
403402

404403
/// Creates a new valid `YearMonth` with provided [`Overflow`] option.
@@ -462,13 +461,6 @@ impl PlainYearMonth {
462461
.year_month_from_fields(fields, Overflow::Constrain)
463462
}
464463

465-
/// Returns the padded ISO year string
466-
#[inline]
467-
#[must_use]
468-
pub fn padded_iso_year_string(&self) -> String {
469-
pad_iso_year(self.iso.year)
470-
}
471-
472464
/// Returns the calendar era of the current `PlainYearMonth`
473465
pub fn era(&self) -> Option<TinyAsciiStr<16>> {
474466
self.calendar().era(&self.iso)

src/utils.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
//! Utility date and time equations for Temporal
22
3-
use alloc::format;
4-
use alloc::string::String;
5-
63
pub(crate) use timezone_provider::utils::epoch_days_from_gregorian_date;
74

85
// NOTE: Potentially add more of tests.
@@ -16,16 +13,4 @@ pub(crate) use timezone_provider::utils::{
1613
epoch_days_to_epoch_ms, iso_days_in_month, ymd_from_epoch_milliseconds,
1714
};
1815

19-
/// 3.5.11 PadISOYear ( y )
20-
///
21-
/// returns a String representation of y suitable for inclusion in an ISO 8601 string
22-
pub(crate) fn pad_iso_year(year: i32) -> String {
23-
if (0..9999).contains(&year) {
24-
return format!("{year:04}");
25-
}
26-
let year_sign = if year > 0 { "+" } else { "-" };
27-
let year_string = format!("{:06}", year.abs());
28-
format!("{year_sign}{year_string}",)
29-
}
30-
3116
// ==== End Calendar Equations ====

temporal_capi/bindings/c/PlainYearMonth.h

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

temporal_capi/bindings/cpp/temporal_rs/PlainYearMonth.d.hpp

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

temporal_capi/bindings/cpp/temporal_rs/PlainYearMonth.hpp

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

temporal_capi/src/plain_year_month.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,6 @@ pub mod ffi {
8383
.map_err(Into::into)
8484
}
8585

86-
pub fn padded_iso_year_string(&self, write: &mut DiplomatWrite) {
87-
// TODO this double-allocates, an API returning a Writeable or impl Write would be better
88-
let string = self.0.padded_iso_year_string();
89-
// throw away the error, the write itself should always succeed
90-
let _ = write.write_str(&string);
91-
}
92-
9386
pub fn year(&self) -> i32 {
9487
self.0.year()
9588
}

0 commit comments

Comments
 (0)