@@ -349,33 +349,44 @@ const formatToDateTime = (value) => {
349349 const date = pad (value .getDate (), 2 );
350350 const hours = pad (value .getHours (), 2 );
351351 const minutes = pad (value .getMinutes (), 2 );
352- const seconds = pad (value .getSeconds (), 2 );
353- return year + ' -' + month + ' -' + date + ' T' + hours + ' :' + minutes + ' :' + seconds;
352+ return year + ' -' + month + ' -' + date + ' T' + hours + ' :' + minutes;
354353};
355354
356355const toValues = (from , to ) => [formatToDateTime (from), formatToDateTime (to)];
356+ const toViews = (from , to ) => {
357+ from = new Date (from)
358+ to = new Date (to)
359+ const year = (value ) => pad (value .getFullYear (), 4 );
360+ const month = (value ) => pad (value .getMonth () + 1 , 2 );
361+ return [` ${ year (from)} -${ month (from)} ` , ` ${ year (to)} -${ month (to)} ` ]
362+ };
363+
357364const rangePicker = document .querySelector (' ef-datetime-picker' );
358365document .getElementById (' today' ).addEventListener (' tap' , () => {
359366 const to = new Date ().setSeconds (0 , 0 );
360367 const from = new Date (to).setHours (0 , 0 , 0 , 0 );
361368 rangePicker .values = toValues (from, to);
369+ rangePicker .views = toViews (from, to);
362370});
363371document .getElementById (' 1-week' ).addEventListener (' tap' , () => {
364372 const to = new Date ().setSeconds (0 , 0 );
365373 const from = new Date (to) - 7 * 24 * 60 * 60 * 1000 ;
366374 rangePicker .values = toValues (from, to);
375+ rangePicker .views = toViews (from, to);
367376});
368377document .getElementById (' 1-month' ).addEventListener (' tap' , () => {
369378 const now = new Date ();
370379 const to = now .setSeconds (0 , 0 );
371380 const from = new Date (now .getFullYear (), now .getMonth () - 1 , now .getDate (), now .getHours (), now .getMinutes ());
372381 rangePicker .values = toValues (from, to);
382+ rangePicker .views = toViews (from, to);
373383});
374384document .getElementById (' 3-months' ).addEventListener (' tap' , () => {
375385 const now = new Date ();
376386 const to = now .setSeconds (0 , 0 );
377387 const from = new Date (now .getFullYear (), now .getMonth () - 3 , now .getDate (), now .getHours (), now .getMinutes ());
378388 rangePicker .values = toValues (from, to);
389+ rangePicker .views = toViews (from, to);
379390});
380391```
381392``` css
@@ -546,7 +557,7 @@ datetimePicker.addEventListener('before-cell-render', (event) => {
546557 const { cell, calendar } = event .detail ;
547558 const prefix = calendar .id === ' calendar-to' ? ' to-' : ' from-' ;
548559 const customCell = sourceDatetimePicker .querySelector (` [slot="${prefix }${cell .value }"] ` );
549-
560+
550561 // skip style overriding if there is no content for the cell
551562 if (! customCell ) { return ; }
552563
@@ -576,7 +587,7 @@ datetimePicker?.addEventListener('before-cell-render', (event) => {
576587
577588 // skip style overriding if there is no content for the cell
578589 if (! customCell ) { return ; }
579-
590+
580591 // use text from component as calendar has built-in locale support
581592 // for instance, Mai instead of May in German
582593 customCell .textContent = cell .text ;
@@ -615,7 +626,7 @@ datetimePicker?.addEventListener('before-cell-render', (event) => {
615626 if (! customCell ) {
616627 return ;
617628 }
618-
629+
619630 // skip style overriding if there is no content for the cell
620631 if (! customCell ) { return ; }
621632
@@ -738,7 +749,7 @@ ef-datetime-picker .custom-cell.selected {
738749` ` `
739750` ` ` html
740751< label id = " event-date" > Event date < / label >
741- < ef - datetime - picker
752+ < ef - datetime - picker
742753 aria - labelledby = " event-date" >
743754< / ef - datetime - picker >
744755` ` `
0 commit comments