@@ -42,6 +42,14 @@ const NAME = 'BCalendar'
4242// Key Codes
4343const { UP , DOWN , LEFT , RIGHT , PAGEUP , PAGEDOWN , HOME , END , ENTER , SPACE } = KeyCodes
4444
45+ // Common calendar option value strings
46+ export const STR_GREGORY = 'gregory'
47+ export const STR_NUMERIC = 'numeric'
48+ export const STR_2_DIGIT = '2-digit'
49+ export const STR_LONG = 'long'
50+ export const STR_SHORT = 'short'
51+ export const STR_NARROW = 'narrow'
52+
4553// --- BCalendar component ---
4654
4755// @vue /component
@@ -224,13 +232,25 @@ export const BCalendar = Vue.extend({
224232 } ,
225233 dateFormatOptions : {
226234 // `Intl.DateTimeFormat` object
235+ // Note: This value is *not* to be placed in the global config
227236 type : Object ,
228237 default : ( ) => ( {
229- year : 'numeric' ,
230- month : 'long' ,
231- day : 'numeric' ,
232- weekday : 'long'
238+ year : STR_NUMERIC ,
239+ month : STR_LONG ,
240+ day : STR_NUMERIC ,
241+ weekday : STR_LONG
233242 } )
243+ } ,
244+ weekdayHeaderFormat : {
245+ // Format of the weekday names at the top of the calendar
246+ // Note: This value is *not* to be placed in the global config
247+ type : String ,
248+ // `short` is typically a 3 letter abbreviation,
249+ // `narrow` is typically a single letter
250+ // `long` is the full week day name
251+ // Although some locales may override this (i.e `ar`, etc)
252+ default : STR_SHORT ,
253+ validator : value => arrayIncludes ( [ STR_LONG , STR_SHORT , STR_NARROW ] , value )
234254 }
235255 } ,
236256 data ( ) {
@@ -271,18 +291,18 @@ export const BCalendar = Vue.extend({
271291 } ,
272292 computedLocale ( ) {
273293 // Returns the resolved locale used by the calendar
274- return resolveLocale ( concat ( this . locale ) . filter ( identity ) , 'gregory' )
294+ return resolveLocale ( concat ( this . locale ) . filter ( identity ) , STR_GREGORY )
275295 } ,
276296 calendarLocale ( ) {
277297 // This locale enforces the gregorian calendar (for use in formatter functions)
278298 // Needed because IE 11 resolves `ar-IR` as islamic-civil calendar
279299 // and IE 11 (and some other browsers) do not support the `calendar` option
280300 // And we currently only support the gregorian calendar
281- const fmt = new Intl . DateTimeFormat ( this . computedLocale , { calendar : 'gregory' } )
301+ const fmt = new Intl . DateTimeFormat ( this . computedLocale , { calendar : STR_GREGORY } )
282302 const calendar = fmt . resolvedOptions ( ) . calendar
283303 let locale = fmt . resolvedOptions ( ) . locale
284304 /* istanbul ignore if: mainly for IE 11 and a few other browsers, hard to test in JSDOM */
285- if ( calendar !== 'gregory' ) {
305+ if ( calendar !== STR_GREGORY ) {
286306 // Ensure the locale requests the gregorian calendar
287307 // Mainly for IE 11, and currently we can't handle non-gregorian calendars
288308 // TODO: Should we always return this value?
@@ -384,9 +404,9 @@ export const BCalendar = Vue.extend({
384404 // Ensure we have year, month, day shown for screen readers/ARIA
385405 // If users really want to leave one of these out, they can
386406 // pass `undefined` for the property value
387- year : 'numeric' ,
388- month : '2-digit' ,
389- day : '2-digit' ,
407+ year : STR_NUMERIC ,
408+ month : STR_2_DIGIT ,
409+ day : STR_2_DIGIT ,
390410 // Merge in user supplied options
391411 ...this . dateFormatOptions ,
392412 // Ensure hours/minutes/seconds are not shown
@@ -395,26 +415,37 @@ export const BCalendar = Vue.extend({
395415 minute : undefined ,
396416 second : undefined ,
397417 // Ensure calendar is gregorian
398- calendar : 'gregory'
418+ calendar : STR_GREGORY
399419 } )
400420 } ,
401421 formatYearMonth ( ) {
402422 // Returns a date formatter function
403423 return createDateFormatter ( this . calendarLocale , {
404- year : 'numeric' ,
405- month : 'long' ,
406- calendar : 'gregory'
424+ year : STR_NUMERIC ,
425+ month : STR_LONG ,
426+ calendar : STR_GREGORY
407427 } )
408428 } ,
409429 formatWeekdayName ( ) {
410- return createDateFormatter ( this . calendarLocale , { weekday : 'long' , calendar : 'gregory' } )
430+ // Long weekday name for weekday header aria-label
431+ return createDateFormatter ( this . calendarLocale , {
432+ weekday : STR_LONG ,
433+ calendar : STR_GREGORY
434+ } )
411435 } ,
412436 formatWeekdayNameShort ( ) {
413- // Used as the header cells
414- return createDateFormatter ( this . calendarLocale , { weekday : 'short' , calendar : 'gregory' } )
437+ // Weekday header cell format
438+ // defaults to 'short' 3 letter days, where possible
439+ return createDateFormatter ( this . calendarLocale , {
440+ weekday : this . weekdayHeaderFormat || STR_SHORT ,
441+ calendar : STR_GREGORY
442+ } )
415443 } ,
416444 formatDay ( ) {
417- return createDateFormatter ( this . calendarLocale , { day : 'numeric' , calendar : 'gregory' } )
445+ return createDateFormatter ( this . calendarLocale , {
446+ day : STR_NUMERIC ,
447+ calendar : STR_GREGORY
448+ } )
418449 } ,
419450 // Disabled states for the nav buttons
420451 prevDecadeDisabled ( ) {
0 commit comments