55
66// TODO: It may finally be time to clean up API to use `IsoDate` and `DateDuration` directly.
77
8- use alloc:: borrow:: ToOwned ;
98use alloc:: string:: String ;
109use alloc:: vec:: Vec ;
1110use core:: str:: FromStr ;
@@ -207,67 +206,6 @@ impl FromStr for Calendar {
207206 }
208207}
209208
210- // TODO: Potentially dead code.
211- /// Designate the type of `CalendarFields` needed
212- #[ derive( Debug , Clone , Copy ) ]
213- pub enum CalendarFieldsType {
214- /// Whether the Fields should return for a PlainDate.
215- Date ,
216- /// Whether the Fields should return for a PlainYearMonth.
217- YearMonth ,
218- /// Whether the Fields should return for a PlainMonthDay.
219- MonthDay ,
220- }
221-
222- // TODO: Optimize to TinyStr or &str.
223- impl From < & [ String ] > for CalendarFieldsType {
224- fn from ( value : & [ String ] ) -> Self {
225- let year_present = value. contains ( & "year" . to_owned ( ) ) ;
226- let day_present = value. contains ( & "day" . to_owned ( ) ) ;
227-
228- if year_present && day_present {
229- CalendarFieldsType :: Date
230- } else if year_present {
231- CalendarFieldsType :: YearMonth
232- } else {
233- CalendarFieldsType :: MonthDay
234- }
235- }
236- }
237-
238- /// The `DateLike` objects that can be provided to the `CalendarProtocol`.
239- #[ derive( Debug ) ]
240- pub enum CalendarDateLike < ' a > {
241- /// Represents a `PlainDateTime`.
242- DateTime ( & ' a PlainDateTime ) ,
243- /// Represents a `PlainDate`.
244- Date ( & ' a PlainDate ) ,
245- /// Represents a `PlainYearMonth`.
246- YearMonth ( & ' a PlainYearMonth ) ,
247- /// Represents a `PlainMonthDay`.
248- MonthDay ( & ' a PlainMonthDay ) ,
249- }
250-
251- impl CalendarDateLike < ' _ > {
252- /// Retrieves the internal `IsoDate` field.
253- #[ inline]
254- #[ must_use]
255- pub fn as_iso_date ( & self ) -> IsoDate {
256- match self {
257- CalendarDateLike :: DateTime ( dt) => dt. iso . date ,
258- CalendarDateLike :: Date ( d) => d. iso ,
259- CalendarDateLike :: YearMonth ( ym) => ym. iso ,
260- CalendarDateLike :: MonthDay ( md) => md. iso ,
261- }
262- }
263- }
264-
265- /// A trait for retrieving an internal calendar slice.
266- pub trait GetTemporalCalendar {
267- /// Returns the `TemporalCalendar` value of the implementor.
268- fn get_calendar ( & self ) -> Calendar ;
269- }
270-
271209// ==== Public `CalendarSlot` methods ====
272210
273211impl Calendar {
@@ -422,84 +360,80 @@ impl Calendar {
422360 }
423361
424362 /// `CalendarEra`
425- pub fn era ( & self , date_like : & CalendarDateLike ) -> TemporalResult < Option < TinyAsciiStr < 16 > > > {
363+ pub fn era ( & self , iso_date : & IsoDate ) -> TemporalResult < Option < TinyAsciiStr < 16 > > > {
426364 if self . is_iso ( ) {
427365 return Ok ( None ) ;
428366 }
429- let calendar_date = self . 0 . date_from_iso ( date_like . as_iso_date ( ) . as_icu4x ( ) ?) ;
367+ let calendar_date = self . 0 . date_from_iso ( iso_date . as_icu4x ( ) ?) ;
430368 Ok ( self . 0 . year ( & calendar_date) . standard_era ( ) . map ( |era| era. 0 ) )
431369 }
432370
433371 /// `CalendarEraYear`
434- pub fn era_year ( & self , date_like : & CalendarDateLike ) -> TemporalResult < Option < i32 > > {
372+ pub fn era_year ( & self , iso_date : & IsoDate ) -> TemporalResult < Option < i32 > > {
435373 if self . is_iso ( ) {
436374 return Ok ( None ) ;
437375 }
438- let calendar_date = self . 0 . date_from_iso ( date_like . as_iso_date ( ) . as_icu4x ( ) ?) ;
376+ let calendar_date = self . 0 . date_from_iso ( iso_date . as_icu4x ( ) ?) ;
439377 Ok ( self . 0 . year ( & calendar_date) . era_year ( ) )
440378 }
441379
442380 /// `CalendarYear`
443- pub fn year ( & self , date_like : & CalendarDateLike ) -> TemporalResult < i32 > {
381+ pub fn year ( & self , iso_date : & IsoDate ) -> TemporalResult < i32 > {
444382 if self . is_iso ( ) {
445- return Ok ( date_like . as_iso_date ( ) . year ) ;
383+ return Ok ( iso_date . year ) ;
446384 }
447- let calendar_date = self . 0 . date_from_iso ( date_like . as_iso_date ( ) . as_icu4x ( ) ?) ;
385+ let calendar_date = self . 0 . date_from_iso ( iso_date . as_icu4x ( ) ?) ;
448386 Ok ( self . 0 . year ( & calendar_date) . extended_year )
449387 }
450388
451389 /// `CalendarMonth`
452- pub fn month ( & self , date_like : & CalendarDateLike ) -> TemporalResult < u8 > {
390+ pub fn month ( & self , iso_date : & IsoDate ) -> TemporalResult < u8 > {
453391 if self . is_iso ( ) {
454- return Ok ( date_like . as_iso_date ( ) . month ) ;
392+ return Ok ( iso_date . month ) ;
455393 }
456394
457395 Err ( TemporalError :: range ( ) . with_message ( "Not yet implemented." ) )
458396 }
459397
460398 /// `CalendarMonthCode`
461- pub fn month_code ( & self , date_like : & CalendarDateLike ) -> TemporalResult < TinyAsciiStr < 4 > > {
399+ pub fn month_code ( & self , iso_date : & IsoDate ) -> TemporalResult < TinyAsciiStr < 4 > > {
462400 if self . is_iso ( ) {
463- return Ok ( date_like . as_iso_date ( ) . as_icu4x ( ) ?. month ( ) . standard_code . 0 ) ;
401+ return Ok ( iso_date . as_icu4x ( ) ?. month ( ) . standard_code . 0 ) ;
464402 }
465403
466404 Err ( TemporalError :: range ( ) . with_message ( "Not yet implemented." ) )
467405 }
468406
469407 /// `CalendarDay`
470- pub fn day ( & self , date_like : & CalendarDateLike ) -> TemporalResult < u8 > {
408+ pub fn day ( & self , iso_date : & IsoDate ) -> TemporalResult < u8 > {
471409 if self . is_iso ( ) {
472- return Ok ( date_like . as_iso_date ( ) . day ) ;
410+ return Ok ( iso_date . day ) ;
473411 }
474412
475413 Err ( TemporalError :: range ( ) . with_message ( "Not yet implemented." ) )
476414 }
477415
478416 /// `CalendarDayOfWeek`
479- pub fn day_of_week ( & self , date_like : & CalendarDateLike ) -> TemporalResult < u16 > {
417+ pub fn day_of_week ( & self , iso_date : & IsoDate ) -> TemporalResult < u16 > {
480418 if self . is_iso ( ) {
481- return Ok ( date_like . as_iso_date ( ) . as_icu4x ( ) ?. day_of_week ( ) as u16 ) ;
419+ return Ok ( iso_date . as_icu4x ( ) ?. day_of_week ( ) as u16 ) ;
482420 }
483421
484422 Err ( TemporalError :: range ( ) . with_message ( "Not yet implemented." ) )
485423 }
486424
487425 /// `CalendarDayOfYear`
488- pub fn day_of_year ( & self , date_like : & CalendarDateLike ) -> TemporalResult < u16 > {
426+ pub fn day_of_year ( & self , iso_date : & IsoDate ) -> TemporalResult < u16 > {
489427 if self . is_iso ( ) {
490- return Ok ( date_like
491- . as_iso_date ( )
492- . as_icu4x ( ) ?
493- . day_of_year_info ( )
494- . day_of_year ) ;
428+ return Ok ( iso_date. as_icu4x ( ) ?. day_of_year_info ( ) . day_of_year ) ;
495429 }
496430 Err ( TemporalError :: range ( ) . with_message ( "Not yet implemented." ) ) ?
497431 }
498432
499433 /// `CalendarWeekOfYear`
500- pub fn week_of_year ( & self , date_like : & CalendarDateLike ) -> TemporalResult < Option < u16 > > {
434+ pub fn week_of_year ( & self , iso_date : & IsoDate ) -> TemporalResult < Option < u16 > > {
501435 if self . is_iso ( ) {
502- let date = date_like . as_iso_date ( ) . as_icu4x ( ) ?;
436+ let date = iso_date . as_icu4x ( ) ?;
503437
504438 let week_calculator = WeekCalculator :: default ( ) ;
505439
@@ -511,9 +445,9 @@ impl Calendar {
511445 }
512446
513447 /// `CalendarYearOfWeek`
514- pub fn year_of_week ( & self , date_like : & CalendarDateLike ) -> TemporalResult < Option < i32 > > {
448+ pub fn year_of_week ( & self , iso_date : & IsoDate ) -> TemporalResult < Option < i32 > > {
515449 if self . is_iso ( ) {
516- let date = date_like . as_iso_date ( ) . as_icu4x ( ) ?;
450+ let date = iso_date . as_icu4x ( ) ?;
517451
518452 let week_calculator = WeekCalculator :: default ( ) ;
519453
@@ -529,42 +463,42 @@ impl Calendar {
529463 }
530464
531465 /// `CalendarDaysInWeek`
532- pub fn days_in_week ( & self , _date_like : & CalendarDateLike ) -> TemporalResult < u16 > {
466+ pub fn days_in_week ( & self , _iso_date : & IsoDate ) -> TemporalResult < u16 > {
533467 if self . is_iso ( ) {
534468 return Ok ( 7 ) ;
535469 }
536470 Err ( TemporalError :: range ( ) . with_message ( "Not yet implemented." ) )
537471 }
538472
539473 /// `CalendarDaysInMonth`
540- pub fn days_in_month ( & self , date_like : & CalendarDateLike ) -> TemporalResult < u16 > {
474+ pub fn days_in_month ( & self , iso_date : & IsoDate ) -> TemporalResult < u16 > {
541475 if self . is_iso ( ) {
542- return Ok ( date_like . as_iso_date ( ) . as_icu4x ( ) ?. days_in_month ( ) as u16 ) ;
476+ return Ok ( iso_date . as_icu4x ( ) ?. days_in_month ( ) as u16 ) ;
543477 }
544478 Err ( TemporalError :: range ( ) . with_message ( "Not yet implemented." ) )
545479 }
546480
547481 /// `CalendarDaysInYear`
548- pub fn days_in_year ( & self , date_like : & CalendarDateLike ) -> TemporalResult < u16 > {
482+ pub fn days_in_year ( & self , iso_date : & IsoDate ) -> TemporalResult < u16 > {
549483 if self . is_iso ( ) {
550- return Ok ( date_like . as_iso_date ( ) . as_icu4x ( ) ?. days_in_year ( ) ) ;
484+ return Ok ( iso_date . as_icu4x ( ) ?. days_in_year ( ) ) ;
551485 }
552486
553487 Err ( TemporalError :: range ( ) . with_message ( "Not yet implemented." ) )
554488 }
555489
556490 /// `CalendarMonthsInYear`
557- pub fn months_in_year ( & self , _date_like : & CalendarDateLike ) -> TemporalResult < u16 > {
491+ pub fn months_in_year ( & self , _iso_date : & IsoDate ) -> TemporalResult < u16 > {
558492 if self . is_iso ( ) {
559493 return Ok ( 12 ) ;
560494 }
561495 Err ( TemporalError :: range ( ) . with_message ( "Not yet implemented." ) )
562496 }
563497
564498 /// `CalendarInLeapYear`
565- pub fn in_leap_year ( & self , date_like : & CalendarDateLike ) -> TemporalResult < bool > {
499+ pub fn in_leap_year ( & self , iso_date : & IsoDate ) -> TemporalResult < bool > {
566500 if self . is_iso ( ) {
567- return Ok ( date_like . as_iso_date ( ) . as_icu4x ( ) ?. is_in_leap_year ( ) ) ;
501+ return Ok ( iso_date . as_icu4x ( ) ?. is_in_leap_year ( ) ) ;
568502 }
569503 Err ( TemporalError :: range ( ) . with_message ( "Not yet implemented." ) )
570504 }
0 commit comments