5
5
//! Functions for region-specific weekday information.
6
6
7
7
use crate :: { error:: RangeError , provider:: * , types:: Weekday } ;
8
- use icu_locale_core:: preferences:: define_preferences;
8
+ use icu_locale_core:: preferences:: { define_preferences, extensions :: unicode :: keywords :: FirstDay } ;
9
9
use icu_provider:: prelude:: * ;
10
10
11
11
/// Minimum number of days in a month unit required for using this module
@@ -15,7 +15,10 @@ define_preferences!(
15
15
/// The preferences for the week information.
16
16
[ Copy ]
17
17
WeekPreferences ,
18
- { }
18
+ {
19
+ /// The first day of the week
20
+ first_weekday: FirstDay
21
+ }
19
22
) ;
20
23
21
24
/// Information about the first day of the week and the weekend.
@@ -46,7 +49,16 @@ impl WeekInformation {
46
49
..Default :: default ( )
47
50
} )
48
51
. map ( |response| WeekInformation {
49
- first_weekday : response. payload . get ( ) . first_weekday ,
52
+ first_weekday : match prefs. first_weekday {
53
+ Some ( FirstDay :: Mon ) => Weekday :: Monday ,
54
+ Some ( FirstDay :: Tue ) => Weekday :: Tuesday ,
55
+ Some ( FirstDay :: Wed ) => Weekday :: Wednesday ,
56
+ Some ( FirstDay :: Thu ) => Weekday :: Thursday ,
57
+ Some ( FirstDay :: Fri ) => Weekday :: Friday ,
58
+ Some ( FirstDay :: Sat ) => Weekday :: Saturday ,
59
+ Some ( FirstDay :: Sun ) => Weekday :: Sunday ,
60
+ _ => response. payload . get ( ) . first_weekday ,
61
+ } ,
50
62
weekend : response. payload . get ( ) . weekend ,
51
63
} )
52
64
}
@@ -524,6 +536,32 @@ mod tests {
524
536
}
525
537
}
526
538
539
+ #[ test]
540
+ fn test_first_day ( ) {
541
+ use icu_locale_core:: locale;
542
+
543
+ assert_eq ! (
544
+ WeekInformation :: try_new( locale!( "und-US" ) . into( ) )
545
+ . unwrap( )
546
+ . first_weekday,
547
+ Weekday :: Sunday ,
548
+ ) ;
549
+
550
+ assert_eq ! (
551
+ WeekInformation :: try_new( locale!( "und-FR" ) . into( ) )
552
+ . unwrap( )
553
+ . first_weekday,
554
+ Weekday :: Monday ,
555
+ ) ;
556
+
557
+ assert_eq ! (
558
+ WeekInformation :: try_new( locale!( "und-FR-u-fw-tue" ) . into( ) )
559
+ . unwrap( )
560
+ . first_weekday,
561
+ Weekday :: Tuesday ,
562
+ ) ;
563
+ }
564
+
527
565
#[ test]
528
566
fn test_weekend ( ) {
529
567
use icu_locale_core:: locale;
0 commit comments