@@ -243,16 +243,69 @@ impl<A: AsCalendar> Date<A> {
243243 Date { inner, calendar }
244244 }
245245
246- /// The number of months in the year of this date.
246+ /// The day-of-month of this date.
247247 #[ inline]
248- pub fn months_in_year ( & self ) -> u8 {
249- self . calendar . as_calendar ( ) . months_in_year ( self . inner ( ) )
248+ pub fn day_of_month ( & self ) -> types :: DayOfMonth {
249+ self . calendar . as_calendar ( ) . day_of_month ( & self . inner )
250250 }
251251
252- /// The number of days in the year of this date.
252+ /// The day-of- year of this date.
253253 #[ inline]
254- pub fn days_in_year ( & self ) -> u16 {
255- self . calendar . as_calendar ( ) . days_in_year ( self . inner ( ) )
254+ pub fn day_of_year ( & self ) -> types:: DayOfYear {
255+ self . calendar . as_calendar ( ) . day_of_year ( & self . inner )
256+ }
257+
258+ /// The weekday of this date.
259+ #[ inline]
260+ pub fn weekday ( & self ) -> types:: Weekday {
261+ self . to_rata_die ( ) . into ( )
262+ }
263+
264+ /// The weekday of this date.
265+ ///
266+ /// This is *not* the day of the week, an ordinal number that is locale
267+ /// dependent.
268+ #[ deprecated( since = "2.2.0" , note = "use `Date::weekday" ) ]
269+ pub fn day_of_week ( & self ) -> types:: Weekday {
270+ self . to_rata_die ( ) . into ( )
271+ }
272+
273+ /// The month of this date.
274+ #[ inline]
275+ pub fn month ( & self ) -> types:: MonthInfo {
276+ self . calendar . as_calendar ( ) . month ( & self . inner )
277+ }
278+
279+ /// The year of this date.
280+ ///
281+ /// This returns an enum, see [`Date::era_year()`] and [`Date::cyclic_year()`] which are available
282+ /// for concrete calendar types and return concrete types.
283+ #[ inline]
284+ pub fn year ( & self ) -> types:: YearInfo {
285+ self . calendar . as_calendar ( ) . year_info ( & self . inner ) . into ( )
286+ }
287+
288+ /// The "extended year" of this date.
289+ ///
290+ /// This year number can be used when you need a simple numeric representation
291+ /// of the year, and can be meaningfully compared with extended years from other
292+ /// eras or used in arithmetic.
293+ ///
294+ /// For calendars defined in Temporal, this will match the "arithmetic year"
295+ /// as defined in <https://tc39.es/proposal-intl-era-monthcode/>.
296+ /// This is typically anchored with year 1 as the year 1 of either the most modern or
297+ /// otherwise some "major" era for the calendar.
298+ ///
299+ /// See [`Self::year()`] for more information about the year.
300+ #[ inline]
301+ pub fn extended_year ( & self ) -> i32 {
302+ self . year ( ) . extended_year ( )
303+ }
304+
305+ /// Whether this date is in a leap year.
306+ #[ inline]
307+ pub fn is_in_leap_year ( & self ) -> bool {
308+ self . calendar . as_calendar ( ) . is_in_leap_year ( & self . inner )
256309 }
257310
258311 /// The number of days in the month of this date.
@@ -261,10 +314,16 @@ impl<A: AsCalendar> Date<A> {
261314 self . calendar . as_calendar ( ) . days_in_month ( self . inner ( ) )
262315 }
263316
264- /// The day of the week of this date.
317+ /// The number of days in the year of this date.
265318 #[ inline]
266- pub fn day_of_week ( & self ) -> types:: Weekday {
267- self . to_rata_die ( ) . into ( )
319+ pub fn days_in_year ( & self ) -> u16 {
320+ self . calendar . as_calendar ( ) . days_in_year ( self . inner ( ) )
321+ }
322+
323+ /// The number of months in the year of this date.
324+ #[ inline]
325+ pub fn months_in_year ( & self ) -> u8 {
326+ self . calendar . as_calendar ( ) . months_in_year ( self . inner ( ) )
268327 }
269328
270329 /// Add a `duration` to this date, mutating it
@@ -359,56 +418,6 @@ impl<A: AsCalendar> Date<A> {
359418 . until ( self . inner ( ) , other. inner ( ) , options)
360419 }
361420
362- /// The year of this date.
363- ///
364- /// This returns an enum, see [`Date::era_year()`] and [`Date::cyclic_year()`] which are available
365- /// for concrete calendar types and return concrete types.
366- #[ inline]
367- pub fn year ( & self ) -> types:: YearInfo {
368- self . calendar . as_calendar ( ) . year_info ( & self . inner ) . into ( )
369- }
370-
371- /// The "extended year" of this date.
372- ///
373- /// This year number can be used when you need a simple numeric representation
374- /// of the year, and can be meaningfully compared with extended years from other
375- /// eras or used in arithmetic.
376- ///
377- /// For calendars defined in Temporal, this will match the "arithmetic year"
378- /// as defined in <https://tc39.es/proposal-intl-era-monthcode/>.
379- /// This is typically anchored with year 1 as the year 1 of either the most modern or
380- /// otherwise some "major" era for the calendar.
381- ///
382- /// See [`Self::year()`] for more information about the year.
383- #[ inline]
384- pub fn extended_year ( & self ) -> i32 {
385- self . year ( ) . extended_year ( )
386- }
387-
388- /// Whether this date is in a leap year.
389- #[ inline]
390- pub fn is_in_leap_year ( & self ) -> bool {
391- self . calendar . as_calendar ( ) . is_in_leap_year ( & self . inner )
392- }
393-
394- /// The month of this date.
395- #[ inline]
396- pub fn month ( & self ) -> types:: MonthInfo {
397- self . calendar . as_calendar ( ) . month ( & self . inner )
398- }
399-
400- /// The day-of-month of this date.
401- #[ inline]
402- pub fn day_of_month ( & self ) -> types:: DayOfMonth {
403- self . calendar . as_calendar ( ) . day_of_month ( & self . inner )
404- }
405-
406- /// The day-of-month of this date.
407- #[ inline]
408- pub fn day_of_year ( & self ) -> types:: DayOfYear {
409- self . calendar . as_calendar ( ) . day_of_year ( & self . inner )
410- }
411-
412421 /// Construct a date from raw values for a given calendar. This does not check any
413422 /// invariants for the date and calendar, and should only be called by calendar implementations.
414423 ///
@@ -483,7 +492,7 @@ impl Date<Iso> {
483492 as u16 ,
484493 self . days_in_year ( ) ,
485494 self . day_of_year ( ) . 0 ,
486- self . day_of_week ( ) ,
495+ self . weekday ( ) ,
487496 )
488497 . unwrap_or_else ( |_| {
489498 // ISO calendar has more than 14 days per year
@@ -648,20 +657,20 @@ mod tests {
648657 }
649658
650659 #[ test]
651- fn test_day_of_week ( ) {
660+ fn test_weekday ( ) {
652661 // June 23, 2021 is a Wednesday
653662 assert_eq ! (
654- Date :: try_new_iso( 2021 , 6 , 23 ) . unwrap( ) . day_of_week ( ) ,
663+ Date :: try_new_iso( 2021 , 6 , 23 ) . unwrap( ) . weekday ( ) ,
655664 Weekday :: Wednesday ,
656665 ) ;
657666 // Feb 2, 1983 was a Wednesday
658667 assert_eq ! (
659- Date :: try_new_iso( 1983 , 2 , 2 ) . unwrap( ) . day_of_week ( ) ,
668+ Date :: try_new_iso( 1983 , 2 , 2 ) . unwrap( ) . weekday ( ) ,
660669 Weekday :: Wednesday ,
661670 ) ;
662671 // Jan 21, 2021 was a Tuesday
663672 assert_eq ! (
664- Date :: try_new_iso( 2020 , 1 , 21 ) . unwrap( ) . day_of_week ( ) ,
673+ Date :: try_new_iso( 2020 , 1 , 21 ) . unwrap( ) . weekday ( ) ,
665674 Weekday :: Tuesday ,
666675 ) ;
667676 }
0 commit comments