Skip to content

Commit d67f311

Browse files
year_month fixes & run -p diplomat-gen
1 parent cd48780 commit d67f311

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed

src/builtins/core/date.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,18 @@ impl PartialDate {
7878
})
7979
}
8080

81-
crate::impl_with_fallback_method!(with_fallback_year_month, PlainYearMonth);
82-
crate::impl_with_fallback_method!(with_fallback_date, PlainDate);
83-
crate::impl_with_fallback_method!(with_fallback_datetime, PlainDateTime);
81+
crate::impl_with_fallback_method!(with_fallback_year_month, () PlainYearMonth);
82+
crate::impl_with_fallback_method!(with_fallback_date, (with_day: day) PlainDate);
83+
crate::impl_with_fallback_method!(with_fallback_datetime, (with_day:day) PlainDateTime);
84+
8485
// TODO: ZonedDateTime
8586
}
8687

8788
// Use macro to impl fallback methods to avoid having a trait method.
8889
#[doc(hidden)]
8990
#[macro_export]
9091
macro_rules! impl_with_fallback_method {
91-
($method_name:ident, $component_type:ty) => {
92+
($method_name:ident, ( $(with_day: $day:ident)? ) $component_type:ty) => {
9293
pub(crate) fn $method_name(&self, fallback: &$component_type) -> TemporalResult<Self> {
9394
let era = if let Some(era) = self.era {
9495
Some(era)
@@ -118,10 +119,11 @@ macro_rules! impl_with_fallback_method {
118119
year: Some(self.year.unwrap_or(fallback.year())),
119120
month,
120121
month_code,
121-
day: Some(self.day.unwrap_or(fallback.day().into())),
122+
$($day: Some(self.day.unwrap_or(fallback.day().into())),)?
122123
era,
123124
era_year,
124125
calendar: fallback.calendar().clone(),
126+
..Default::default()
125127
})
126128
}
127129
};

src/builtins/core/year_month.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,6 @@ impl PlainYearMonth {
180180
self.calendar.identifier()
181181
}
182182

183-
/// Returns the calendar day value.
184-
pub fn day(&self) -> TemporalResult<u8> {
185-
self.calendar.day(&self.iso)
186-
}
187-
188183
/// Creates a `PlainYearMonth` using the fields provided from a [`PartialDate`]
189184
pub fn with(
190185
&self,
@@ -194,9 +189,6 @@ impl PlainYearMonth {
194189
// 1. Let yearMonth be the this value.
195190
// 2. Perform ? RequireInternalSlot(yearMonth, [[InitializedTemporalYearMonth]]).
196191
// 3. If ? IsPartialTemporalObject(temporalYearMonthLike) is false, throw a TypeError exception.
197-
if partial.is_empty() {
198-
return Err(TemporalError::r#type().with_message("A PartialDate must have a field."));
199-
};
200192
// 4. Let calendar be yearMonth.[[Calendar]].
201193
// 5. Let fields be ISODateToFields(calendar, yearMonth.[[ISODate]], year-month).
202194
// 6. Let partialYearMonth be ? PrepareCalendarFields(calendar, temporalYearMonthLike, « year, month, month-code », « », partial).
@@ -345,7 +337,7 @@ mod tests {
345337
assert_eq!(with_year.iso_year(), 2001); // year is changed
346338
assert_eq!(with_year.iso_month(), 3); // month is not changed
347339
assert_eq!(
348-
with_year.month_code().unwrap(),
340+
with_year.month_code(),
349341
MonthCode::from_str("M03").unwrap()
350342
); // assert month code has been initialized correctly
351343

@@ -358,7 +350,7 @@ mod tests {
358350
assert_eq!(with_month.iso_year(), 2025); // year is not changed
359351
assert_eq!(with_month.iso_month(), 2); // month is changed
360352
assert_eq!(
361-
with_month.month_code().unwrap(),
353+
with_month.month_code(),
362354
MonthCode::from_str("M02").unwrap()
363355
); // assert month code has changed as well as month
364356

@@ -370,7 +362,7 @@ mod tests {
370362
let with_month_code = base.with(partial, None).unwrap();
371363
assert_eq!(with_month_code.iso_year(), 2025); // year is not changed
372364
assert_eq!(
373-
with_month_code.month_code().unwrap(),
365+
with_month_code.month_code(),
374366
MonthCode::from_str("M05").unwrap()
375367
); // assert month code has changed
376368
assert_eq!(with_month_code.iso_month(), 5); // month is changed as well
@@ -383,7 +375,7 @@ mod tests {
383375
let with_day = base.with(partial, None).unwrap();
384376
assert_eq!(with_day.iso_year(), 2025); // year is not changed
385377
assert_eq!(with_day.iso_month(), 3); // month is not changed
386-
assert_eq!(with_day.iso.day, 15); // day is changed
378+
assert_eq!(with_day.iso.day, 1); // day is ignored
387379

388380
// All
389381
let partial = PartialDate {
@@ -395,7 +387,7 @@ mod tests {
395387
let with_all = base.with(partial, None).unwrap();
396388
assert_eq!(with_all.iso_year(), 2001); // year is changed
397389
assert_eq!(with_all.iso_month(), 2); // month is changed
398-
assert_eq!(with_all.iso.day, 15); // day is changed
390+
assert_eq!(with_all.iso.day, 1); // day is ignored
399391
}
400392

401393
#[test]

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

Lines changed: 1 addition & 1 deletion
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: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)