Răsfoiți Sursa

omitZeroMinute

Adam Shaw 7 ani în urmă
părinte
comite
c96b99f5c4

+ 1 - 1
src/agenda/TimeGrid.ts

@@ -173,7 +173,7 @@ export default class TimeGrid extends DateComponent {
     this.labelFormat = createFormatter(input || {
         hour: 'numeric',
         minute: '2-digit',
-        omitZeroMinSec: true,
+        omitZeroMinute: true,
         meridiem: 'short'
     })
 

+ 1 - 1
src/basic/DayGridEventRenderer.ts

@@ -223,7 +223,7 @@ export default class DayGridEventRenderer extends EventRenderer {
     return {
       hour: 'numeric',
       minute: '2-digit',
-      omitZeroMinSec: true,
+      omitZeroMinute: true,
       meridiem: 'narrow'
     }
   }

+ 1 - 1
src/component/renderers/EventRenderer.ts

@@ -308,7 +308,7 @@ export default class EventRenderer {
     return {
       hour: 'numeric',
       minute: '2-digit',
-      omitZeroMinSec: true
+      omitZeroMinute: true
     }
   }
 

+ 33 - 21
src/datelib/formatting-native.ts

@@ -8,7 +8,7 @@ import reselector from '../util/reselector'
 const EXTENDED_SETTINGS_AND_SEVERITIES = {
   week: 3,
   separator: 0, // 0 = not applicable
-  omitZeroMinSec: 0,
+  omitZeroMinute: 0,
   meridiem: 0, // like am/pm
   omitCommas: 0
 }
@@ -157,34 +157,18 @@ function buildNativeFormattingFunc(
   context: DateFormattingContext
 ): (date: ZonedMarker) => string {
   standardDateProps = assignTo({}, standardDateProps) // copy
+  extendedSettings = assignTo({}, extendedSettings) // copy
 
-  // deal with a browser inconsistency where formatting the timezone
-  // requires that the hour/minute be present.
-  if (standardDateProps.timeZoneName) {
-    if (!standardDateProps.hour) {
-      standardDateProps.hour = '2-digit'
-    }
-    if (!standardDateProps.minute) {
-      standardDateProps.minute = '2-digit'
-    }
-  }
-
-  // only support short timezone names
-  if (standardDateProps.timeZoneName === 'long') {
-    standardDateProps.timeZoneName = 'short'
-  }
+  sanitizeSettings(standardDateProps, extendedSettings)
 
   standardDateProps.timeZone = 'UTC' // we leverage the only guaranteed timeZone for our UTC markers
 
   let normalFormat = new Intl.DateTimeFormat(context.locale.codes, standardDateProps)
-  let zeroFormat
+  let zeroFormat // needed?
 
-  if (extendedSettings.omitZeroMinSec) {
+  if (extendedSettings.omitZeroMinute) {
     let zeroProps = assignTo({}, standardDateProps)
-
     delete zeroProps.minute
-    delete zeroProps.second
-
     zeroFormat = new Intl.DateTimeFormat(context.locale.codes, zeroProps)
   }
 
@@ -204,6 +188,30 @@ function buildNativeFormattingFunc(
   }
 }
 
+function sanitizeSettings(standardDateProps, extendedSettings) {
+
+  // deal with a browser inconsistency where formatting the timezone
+  // requires that the hour/minute be present.
+  if (standardDateProps.timeZoneName) {
+    if (!standardDateProps.hour) {
+      standardDateProps.hour = '2-digit'
+    }
+    if (!standardDateProps.minute) {
+      standardDateProps.minute = '2-digit'
+    }
+  }
+
+  // only support short timezone names
+  if (standardDateProps.timeZoneName === 'long') {
+    standardDateProps.timeZoneName = 'short'
+  }
+
+  // if requesting to display seconds, MUST display minutes
+  if (extendedSettings.omitZeroMinute && standardDateProps.second) {
+    delete extendedSettings.omitZeroMinute
+  }
+}
+
 function postProcess(s: string, date: ZonedMarker, standardDateProps, extendedSettings, context: DateFormattingContext): string {
 
   s = s.replace(LTR_RE, '') // remove left-to-right control chars. do first. good for other regexes
@@ -221,6 +229,10 @@ function postProcess(s: string, date: ZonedMarker, standardDateProps, extendedSe
     s = s.replace(COMMA_RE, '').trim()
   }
 
+  if (extendedSettings.omitZeroMinute) {
+    s = s.replace(':00', '') // zeroFormat doesn't always achieve this
+  }
+
   // ^ do anything that might create adjacent spaces before this point,
   // because MERIDIEM_RE likes to eat up loading spaces
 

+ 31 - 29
tests/automated/legacy/columnHeaderFormat.js

@@ -4,11 +4,11 @@ describe('columnHeaderFormat', function() {
   describe('when not set', function() {
 
     var viewWithFormat = [
-      { view: 'month', expected: 'Sun', selector: 'th.fc-day-header.fc-sun' },
-      { view: 'basicWeek', expected: 'Sun 5/11', selector: 'th.fc-day-header.fc-sun' },
-      { view: 'agendaWeek', expected: 'Sun 5/11', selector: 'th.fc-widget-header.fc-sun' },
-      { view: 'basicDay', expected: 'Sunday', selector: 'th.fc-day-header.fc-sun' },
-      { view: 'agendaDay', expected: 'Sunday', selector: 'th.fc-widget-header.fc-sun' }
+      { view: 'month', expected: /^Sun$/, selector: 'th.fc-day-header.fc-sun' },
+      { view: 'basicWeek', expected: /^Sun 5[/ ]11$/, selector: 'th.fc-day-header.fc-sun' },
+      { view: 'agendaWeek', expected: /^Sun 5[/ ]11$/, selector: 'th.fc-widget-header.fc-sun' },
+      { view: 'basicDay', expected: /^Sunday$/, selector: 'th.fc-day-header.fc-sun' },
+      { view: 'agendaDay', expected: /^Sunday$/, selector: 'th.fc-widget-header.fc-sun' }
     ]
 
     beforeEach(function() {
@@ -22,7 +22,7 @@ describe('columnHeaderFormat', function() {
       for (var i = 0; i < viewWithFormat.length; i++) {
         var crtView = viewWithFormat[i]
         currentCalendar.changeView(crtView.view)
-        expect($(currentCalendar.el).find(crtView.selector).text()).toBe(crtView.expected)
+        expect($(currentCalendar.el).find(crtView.selector).text()).toMatch(crtView.expected)
       };
     })
   })
@@ -30,9 +30,9 @@ describe('columnHeaderFormat', function() {
   describe('when columnHeaderFormat is set on a per-view basis', function() {
 
     var viewWithFormat = [
-      { view: 'month', expected: 'Sunday', selector: 'th.fc-day-header.fc-sun' },
-      { view: 'agendaDay', expected: 'Sunday, May 11', selector: 'th.fc-widget-header.fc-sun' },
-      { view: 'basicWeek', expected: 'Sunday, 5/11', selector: 'th.fc-day-header.fc-sun' }
+      { view: 'month', expected: /^Sunday$/, selector: 'th.fc-day-header.fc-sun' },
+      { view: 'agendaDay', expected: /^Sunday, May 11$/, selector: 'th.fc-widget-header.fc-sun' },
+      { view: 'basicWeek', expected: /^Sunday, 5[/ ]11$/, selector: 'th.fc-day-header.fc-sun' }
     ]
 
     beforeEach(function() {
@@ -51,7 +51,7 @@ describe('columnHeaderFormat', function() {
       for (var i = 0; i < viewWithFormat.length; i++) {
         var crtView = viewWithFormat[i]
         currentCalendar.changeView(crtView.view)
-        expect($(currentCalendar.el).find(crtView.selector).text()).toBe(crtView.expected)
+        expect($(currentCalendar.el).find(crtView.selector).text()).toMatch(crtView.expected)
       };
     })
   })
@@ -59,11 +59,11 @@ describe('columnHeaderFormat', function() {
   describe('when locale is French', function() {
 
     var viewWithFormat = [
-      { view: 'month', expected: 'dim.', selector: 'th.fc-day-header.fc-sun' },
-      { view: 'basicWeek', expected: 'dim. 11/05', selector: 'th.fc-day-header.fc-sun' },
-      { view: 'agendaWeek', expected: 'dim. 11/05', selector: 'th.fc-widget-header.fc-sun' },
-      { view: 'basicDay', expected: 'dimanche', selector: 'th.fc-day-header.fc-sun' },
-      { view: 'agendaDay', expected: 'dimanche', selector: 'th.fc-widget-header.fc-sun' }
+      { view: 'month', expected: /^dim\.$/, selector: 'th.fc-day-header.fc-sun' },
+      { view: 'basicWeek', expected: /^dim\. 11[/ ]0?5$/, selector: 'th.fc-day-header.fc-sun' },
+      { view: 'agendaWeek', expected: /^dim\. 11[/ ]0?5$/, selector: 'th.fc-widget-header.fc-sun' },
+      { view: 'basicDay', expected: /^dimanche$/, selector: 'th.fc-day-header.fc-sun' },
+      { view: 'agendaDay', expected: /^dimanche$/, selector: 'th.fc-widget-header.fc-sun' }
     ]
 
     beforeEach(function() {
@@ -78,7 +78,7 @@ describe('columnHeaderFormat', function() {
       for (var i = 0; i < viewWithFormat.length; i++) {
         var crtView = viewWithFormat[i]
         currentCalendar.changeView(crtView.view)
-        expect($(currentCalendar.el).find(crtView.selector).text()).toBe(crtView.expected)
+        expect($(currentCalendar.el).find(crtView.selector).text()).toMatch(crtView.expected)
       };
     })
   })
@@ -86,11 +86,11 @@ describe('columnHeaderFormat', function() {
   describe('when locale is en-gb', function() {
 
     var viewWithFormat = [
-      { view: 'month', expected: 'Sun', selector: 'th.fc-day-header.fc-sun' },
-      { view: 'basicWeek', expected: 'Sun 11/05', selector: 'th.fc-day-header.fc-sun' },
-      { view: 'agendaWeek', expected: 'Sun 11/05', selector: 'th.fc-widget-header.fc-sun' },
-      { view: 'basicDay', expected: 'Sunday', selector: 'th.fc-day-header.fc-sun' },
-      { view: 'agendaDay', expected: 'Sunday', selector: 'th.fc-widget-header.fc-sun' }
+      { view: 'month', expected: /^Sun$/, selector: 'th.fc-day-header.fc-sun' },
+      { view: 'basicWeek', expected: /^Sun 11[/ ]0?5$/, selector: 'th.fc-day-header.fc-sun' },
+      { view: 'agendaWeek', expected: /^Sun 11[/ ]0?5$/, selector: 'th.fc-widget-header.fc-sun' },
+      { view: 'basicDay', expected: /^Sunday$/, selector: 'th.fc-day-header.fc-sun' },
+      { view: 'agendaDay', expected: /^Sunday$/, selector: 'th.fc-widget-header.fc-sun' }
     ]
 
     beforeEach(function() {
@@ -105,7 +105,7 @@ describe('columnHeaderFormat', function() {
       for (var i = 0; i < viewWithFormat.length; i++) {
         var crtView = viewWithFormat[i]
         currentCalendar.changeView(crtView.view)
-        expect($(currentCalendar.el).find(crtView.selector).text()).toBe(crtView.expected)
+        expect($(currentCalendar.el).find(crtView.selector).text()).toMatch(crtView.expected)
       };
     })
   })
@@ -113,11 +113,11 @@ describe('columnHeaderFormat', function() {
   describe('when locale is Korean', function() {
 
     var viewWithFormat = [
-      { view: 'month', expected: '일', selector: 'th.fc-day-header.fc-sun' },
-      { view: 'basicWeek', expected: '5. 11. (일)', selector: 'th.fc-day-header.fc-sun' },
-      { view: 'agendaWeek', expected: '5. 11. (일)', selector: 'th.fc-widget-header.fc-sun' },
-      { view: 'basicDay', expected: '일요일', selector: 'th.fc-day-header.fc-sun' },
-      { view: 'agendaDay', expected: '일요일', selector: 'th.fc-widget-header.fc-sun' }
+      { view: 'month', expected: /^일$/, selector: 'th.fc-day-header.fc-sun' },
+      { view: 'basicWeek', expected: /^5[.월] 11[.일] \(?일\)?$/,  selector: 'th.fc-day-header.fc-sun' },
+      { view: 'agendaWeek', expected: /^5[.월] 11[.일] \(?일\)?$/,  selector: 'th.fc-widget-header.fc-sun' },
+      { view: 'basicDay', expected: /^일요일$/, selector: 'th.fc-day-header.fc-sun' },
+      { view: 'agendaDay', expected: /^일요일$/, selector: 'th.fc-widget-header.fc-sun' }
     ]
 
     beforeEach(function() {
@@ -131,7 +131,7 @@ describe('columnHeaderFormat', function() {
       for (var i = 0; i < viewWithFormat.length; i++) {
         var crtView = viewWithFormat[i]
         currentCalendar.changeView(crtView.view)
-        expect($(currentCalendar.el).find(crtView.selector).text()).toBe(crtView.expected)
+        expect($(currentCalendar.el).find(crtView.selector).text()).toMatch(crtView.expected)
       };
     })
   })
@@ -191,7 +191,9 @@ describe('columnHeaderFormat', function() {
         defaultView: 'multiDay',
         defaultDate: '2014-12-25'
       })
-      expect($('.fc-day-header:first')).toHaveText('Thu 12/25')
+      expect(
+        $('.fc-day-header:first').text()
+      ).toMatch(/^Thu 12[/ ]25$/)
     })
   })
 })

+ 33 - 34
tests/automated/legacy/dayNames.js

@@ -1,12 +1,8 @@
-import { getHeaderEl } from './../view-render/DayGridRenderUtils'
-import { DAY_CLASSES } from './../lib/constants'
+import { getHeaderEl } from '../view-render/DayGridRenderUtils'
+import { DAY_CLASSES } from '../lib/constants'
+import { removeLtrCharCodes } from '../lib/string'
 
 describe('day names', function() {
-  var testableClasses = [
-    'basicDay',
-    'agendaDay'
-  ]
-
   var sundayDate = new Date('2014-05-25T06:00:00')
   var locales = [ 'es', 'fr', 'de', 'zh-cn', 'nl' ]
 
@@ -14,46 +10,49 @@ describe('day names', function() {
     now: sundayDate
   })
 
-  testableClasses.forEach(function(viewClass, index, viewClasses) {
-    describe('when view is basicDay', function() {
+  describe('when view is basicDay', function() {
+    pushOptions({
+      defaultView: 'basicDay'
+    })
+    describe('when locale is default', function() {
       pushOptions({
-        defaultView: 'basicDay'
+        locale: 'en'
       })
-      describe('when locale is default', function() {
-        pushOptions({
-          locale: 'en'
+      DAY_CLASSES.forEach(function(cls, index) {
+        var dayDate = FullCalendar.addDays(sundayDate, index)
+        var dayText = removeLtrCharCodes(
+          dayDate.toLocaleString('en', { weekday: 'long' })
+        )
+
+        it('should be ' + dayText, function() {
+          initCalendar({
+            now: dayDate
+          })
+          expect(getHeaderEl().find(`.${cls}`)).toHaveText(dayText)
         })
+      })
+    })
+
+    $.each(locales, function(index, locale) {
+      describe('when locale is ' + locale, function() {
         DAY_CLASSES.forEach(function(cls, index, classes) {
           var dayDate = FullCalendar.addDays(sundayDate, index)
-          var dayText = dayDate.toLocaleString('en', { weekday: 'long' })
+          var dayText = removeLtrCharCodes(
+            dayDate.toLocaleString(locale, { weekday: 'long' })
+          )
+
+          it('should be the translation for ' + dayText, function() {
 
-          it('should be ' + dayText, function() {
             initCalendar({
+              locale: locale,
               now: dayDate
             })
-            expect(getHeaderEl().find(`.${cls}`)).toHaveText(dayText)
-          })
-        })
-      })
-
-      $.each(locales, function(index, locale) {
-        describe('when locale is ' + locale, function() {
-          DAY_CLASSES.forEach(function(cls, index, classes) {
-            var dayDate = FullCalendar.addDays(sundayDate, index)
-            var dayText = dayDate.toLocaleString(locale, { weekday: 'long' })
-
-            it('should be the translation for ' + dayText, function() {
 
-              initCalendar({
-                locale: locale,
-                now: dayDate
-              })
-
-              expect(getHeaderEl().find(`.${cls}`)).toHaveText(dayText)
-            })
+            expect(getHeaderEl().find(`.${cls}`)).toHaveText(dayText)
           })
         })
       })
     })
   })
+
 })

+ 4 - 0
tests/automated/lib/string.js

@@ -0,0 +1,4 @@
+
+export function removeLtrCharCodes(s) {
+  return s.replace(/\u200e/g, '')
+}