ソースを参照

dateStr/startStr/endStr for dateClick/select/event-func

Adam Shaw 7 年 前
コミット
a5011ec75b

+ 1 - 0
src/Calendar.ts

@@ -1038,6 +1038,7 @@ export default class Calendar {
     this.publiclyTrigger('dateClick', [
     this.publiclyTrigger('dateClick', [
       {
       {
         date: this.dateEnv.toDate(dateSpan.range.start),
         date: this.dateEnv.toDate(dateSpan.range.start),
+        dateStr: this.dateEnv.formatIso(dateSpan.range.start, { omitTime: dateSpan.isAllDay }),
         isAllDay: dateSpan.isAllDay,
         isAllDay: dateSpan.isAllDay,
         dayEl,
         dayEl,
         jsEvent: ev,
         jsEvent: ev,

+ 2 - 0
src/event-sources/func-event-source.ts

@@ -31,6 +31,8 @@ registerEventSourceDef({
       func.bind(null, { // the function returned from parseMeta
       func.bind(null, { // the function returned from parseMeta
         start: dateEnv.toDate(arg.range.start),
         start: dateEnv.toDate(arg.range.start),
         end: dateEnv.toDate(arg.range.end),
         end: dateEnv.toDate(arg.range.end),
+        startStr: dateEnv.formatIso(arg.range.start),
+        endStr: dateEnv.formatIso(arg.range.end),
         timeZone: dateEnv.timeZone
         timeZone: dateEnv.timeZone
       }),
       }),
       function(rawEvents) { // success
       function(rawEvents) { // success

+ 3 - 0
src/structs/date-span.ts

@@ -137,5 +137,8 @@ export function buildDateSpanApi(span: DateSpan, dateEnv: DateEnv): DateSpanApi
   props.start = dateEnv.toDate(span.range.start)
   props.start = dateEnv.toDate(span.range.start)
   props.end = dateEnv.toDate(span.range.end)
   props.end = dateEnv.toDate(span.range.end)
 
 
+  props.startStr = dateEnv.formatIso(span.range.start, { omitTime: span.isAllDay })
+  props.endStr = dateEnv.formatIso(span.range.end, { omitTime: span.isAllDay })
+
   return props
   return props
 }
 }

+ 6 - 0
tests/automated/legacy/dateClick.js

@@ -24,6 +24,7 @@ describe('dateClick', function() {
                 expect(typeof arg.view).toEqual('object') // "
                 expect(typeof arg.view).toEqual('object') // "
                 expect(arg.isAllDay).toEqual(true)
                 expect(arg.isAllDay).toEqual(true)
                 expect(arg.date).toEqualDate('2014-05-07')
                 expect(arg.date).toEqualDate('2014-05-07')
+                expect(arg.dateStr).toEqual('2014-05-07')
                 done()
                 done()
               }
               }
 
 
@@ -47,6 +48,7 @@ describe('dateClick', function() {
                 expect(typeof arg.view).toEqual('object') // "
                 expect(typeof arg.view).toEqual('object') // "
                 expect(arg.isAllDay).toEqual(true)
                 expect(arg.isAllDay).toEqual(true)
                 expect(arg.date).toEqualDate('2014-05-28')
                 expect(arg.date).toEqualDate('2014-05-28')
+                expect(arg.dateStr).toEqual('2014-05-28')
                 done()
                 done()
               }
               }
 
 
@@ -71,6 +73,7 @@ describe('dateClick', function() {
                 expect(typeof arg.view).toEqual('object') // "
                 expect(typeof arg.view).toEqual('object') // "
                 expect(arg.isAllDay).toEqual(false)
                 expect(arg.isAllDay).toEqual(false)
                 expect(arg.date).toEqualDate('2014-05-28T09:00:00Z')
                 expect(arg.date).toEqualDate('2014-05-28T09:00:00Z')
+                expect(arg.dateStr).toEqual('2014-05-28T09:00:00Z')
                 done()
                 done()
               }
               }
 
 
@@ -97,6 +100,7 @@ describe('dateClick', function() {
                 expect(typeof arg.view).toEqual('object') // "
                 expect(typeof arg.view).toEqual('object') // "
                 expect(arg.isAllDay).toEqual(false)
                 expect(arg.isAllDay).toEqual(false)
                 expect(arg.date).toEqualDate('2014-05-28T11:00:00Z')
                 expect(arg.date).toEqualDate('2014-05-28T11:00:00Z')
+                expect(arg.dateStr).toEqual('2014-05-28T11:00:00Z')
                 done()
                 done()
               }
               }
 
 
@@ -124,6 +128,7 @@ describe('dateClick', function() {
         expect(typeof arg.view).toEqual('object') // "
         expect(typeof arg.view).toEqual('object') // "
         expect(arg.isAllDay).toEqual(true)
         expect(arg.isAllDay).toEqual(true)
         expect(arg.date).toEqualDate('2014-05-07')
         expect(arg.date).toEqualDate('2014-05-07')
+        expect(arg.dateStr).toEqual('2014-05-07')
         done()
         done()
       }
       }
 
 
@@ -167,6 +172,7 @@ describe('dateClick', function() {
         expect(typeof arg.view).toEqual('object') // "
         expect(typeof arg.view).toEqual('object') // "
         expect(arg.isAllDay).toEqual(true)
         expect(arg.isAllDay).toEqual(true)
         expect(arg.date).toEqualDate('2014-05-07')
         expect(arg.date).toEqualDate('2014-05-07')
+        expect(arg.dateStr).toEqual('2014-05-07')
         done()
         done()
       }
       }
 
 

+ 10 - 4
tests/automated/legacy/events-function.js

@@ -18,7 +18,9 @@ describe('events as a function', function() {
         testEventFunctionParams(arg, callback)
         testEventFunctionParams(arg, callback)
         expect(arg.timeZone).toEqual('local')
         expect(arg.timeZone).toEqual('local')
         expect(arg.start).toEqualDate('2014-04-27T00:00:00') // local
         expect(arg.start).toEqualDate('2014-04-27T00:00:00') // local
+        expect(arg.startStr).toMatch(/^2014-04-27T00:00:00[-+]/)
         expect(arg.end).toEqualDate('2014-06-08T00:00:00') // local
         expect(arg.end).toEqualDate('2014-06-08T00:00:00') // local
+        expect(arg.endStr).toMatch(/^2014-06-08T00:00:00[-+]/)
         callback([])
         callback([])
         done()
         done()
       }
       }
@@ -31,8 +33,10 @@ describe('events as a function', function() {
       events: function(arg, callback) {
       events: function(arg, callback) {
         testEventFunctionParams(arg, callback)
         testEventFunctionParams(arg, callback)
         expect(arg.timeZone).toEqual('UTC')
         expect(arg.timeZone).toEqual('UTC')
-        expect(arg.start).toEqualDate('2014-04-27')
-        expect(arg.end).toEqualDate('2014-06-08')
+        expect(arg.start).toEqualDate('2014-04-27T00:00:00Z')
+        expect(arg.startStr).toEqual('2014-04-27T00:00:00Z')
+        expect(arg.end).toEqualDate('2014-06-08T00:00:00Z')
+        expect(arg.endStr).toEqual('2014-06-08T00:00:00Z')
         callback([])
         callback([])
         done()
         done()
       }
       }
@@ -45,8 +49,10 @@ describe('events as a function', function() {
       events: function(arg, callback) {
       events: function(arg, callback) {
         testEventFunctionParams(arg, callback)
         testEventFunctionParams(arg, callback)
         expect(arg.timeZone).toEqual('America/Chicago')
         expect(arg.timeZone).toEqual('America/Chicago')
-        expect(arg.start).toEqualDate('2014-04-27')
-        expect(arg.end).toEqualDate('2014-06-08')
+        expect(arg.start).toEqualDate('2014-04-27T00:00:00Z')
+        expect(arg.startStr).toEqual('2014-04-27T00:00:00') // no Z
+        expect(arg.end).toEqualDate('2014-06-08T00:00:00Z')
+        expect(arg.endStr).toEqual('2014-06-08T00:00:00') // no Z
         callback([])
         callback([])
         done()
         done()
       }
       }

+ 18 - 0
tests/automated/legacy/select-callback.js

@@ -31,7 +31,9 @@ describe('select callback', function() {
             expect(typeof arg.view).toEqual('object') // "
             expect(typeof arg.view).toEqual('object') // "
             expect(arg.isAllDay).toEqual(true)
             expect(arg.isAllDay).toEqual(true)
             expect(arg.start).toEqualDate('2014-04-28')
             expect(arg.start).toEqualDate('2014-04-28')
+            expect(arg.startStr).toEqual('2014-04-28')
             expect(arg.end).toEqualDate('2014-05-07')
             expect(arg.end).toEqualDate('2014-05-07')
+            expect(arg.endStr).toEqual('2014-05-07')
           }
           }
           spyOn(options, 'select').and.callThrough()
           spyOn(options, 'select').and.callThrough()
           initCalendar(options)
           initCalendar(options)
@@ -51,7 +53,9 @@ describe('select callback', function() {
             expect(typeof arg.view).toEqual('object') // "
             expect(typeof arg.view).toEqual('object') // "
             expect(arg.isAllDay).toEqual(true)
             expect(arg.isAllDay).toEqual(true)
             expect(arg.start).toEqualDate('2014-04-28')
             expect(arg.start).toEqualDate('2014-04-28')
+            expect(arg.startStr).toEqual('2014-04-28')
             expect(arg.end).toEqualDate('2014-05-07')
             expect(arg.end).toEqualDate('2014-05-07')
+            expect(arg.endStr).toEqual('2014-05-07')
           }
           }
           spyOn(options, 'select').and.callThrough()
           spyOn(options, 'select').and.callThrough()
           initCalendar(options)
           initCalendar(options)
@@ -73,7 +77,9 @@ describe('select callback', function() {
             expect(typeof arg.view).toEqual('object') // "
             expect(typeof arg.view).toEqual('object') // "
             expect(arg.isAllDay).toEqual(true)
             expect(arg.isAllDay).toEqual(true)
             expect(arg.start).toEqualDate('2014-04-28')
             expect(arg.start).toEqualDate('2014-04-28')
+            expect(arg.startStr).toEqual('2014-04-28')
             expect(arg.end).toEqualDate('2014-04-29')
             expect(arg.end).toEqualDate('2014-04-29')
+            expect(arg.endStr).toEqual('2014-04-29')
           }
           }
           spyOn(options, 'select').and.callThrough()
           spyOn(options, 'select').and.callThrough()
           initCalendar(options)
           initCalendar(options)
@@ -100,7 +106,9 @@ describe('select callback', function() {
               expect(typeof arg.view).toEqual('object') // "
               expect(typeof arg.view).toEqual('object') // "
               expect(arg.isAllDay).toEqual(true)
               expect(arg.isAllDay).toEqual(true)
               expect(arg.start).toEqualDate('2014-05-28')
               expect(arg.start).toEqualDate('2014-05-28')
+              expect(arg.startStr).toEqual('2014-05-28')
               expect(arg.end).toEqualDate('2014-05-30')
               expect(arg.end).toEqualDate('2014-05-30')
+              expect(arg.endStr).toEqual('2014-05-30')
             }
             }
             spyOn(options, 'select').and.callThrough()
             spyOn(options, 'select').and.callThrough()
             initCalendar(options)
             initCalendar(options)
@@ -120,7 +128,9 @@ describe('select callback', function() {
               expect(typeof arg.view).toEqual('object') // "
               expect(typeof arg.view).toEqual('object') // "
               expect(arg.isAllDay).toEqual(true)
               expect(arg.isAllDay).toEqual(true)
               expect(arg.start).toEqualDate('2014-05-28')
               expect(arg.start).toEqualDate('2014-05-28')
+              expect(arg.startStr).toEqual('2014-05-28')
               expect(arg.end).toEqualDate('2014-05-29')
               expect(arg.end).toEqualDate('2014-05-29')
+              expect(arg.endStr).toEqual('2014-05-29')
             }
             }
             spyOn(options, 'select').and.callThrough()
             spyOn(options, 'select').and.callThrough()
             initCalendar(options)
             initCalendar(options)
@@ -141,7 +151,9 @@ describe('select callback', function() {
               expect(typeof arg.view).toEqual('object') // "
               expect(typeof arg.view).toEqual('object') // "
               expect(arg.isAllDay).toEqual(false)
               expect(arg.isAllDay).toEqual(false)
               expect(arg.start).toEqualDate('2014-05-28T09:00:00Z')
               expect(arg.start).toEqualDate('2014-05-28T09:00:00Z')
+              expect(arg.startStr).toEqual('2014-05-28T09:00:00Z')
               expect(arg.end).toEqualDate('2014-05-28T10:30:00Z')
               expect(arg.end).toEqualDate('2014-05-28T10:30:00Z')
+              expect(arg.endStr).toEqual('2014-05-28T10:30:00Z')
             }
             }
             spyOn(options, 'select').and.callThrough()
             spyOn(options, 'select').and.callThrough()
             initCalendar(options)
             initCalendar(options)
@@ -161,7 +173,9 @@ describe('select callback', function() {
               expect(typeof arg.view).toEqual('object') // "
               expect(typeof arg.view).toEqual('object') // "
               expect(arg.isAllDay).toEqual(false)
               expect(arg.isAllDay).toEqual(false)
               expect(arg.start).toEqualDate('2014-05-28T09:00:00Z')
               expect(arg.start).toEqualDate('2014-05-28T09:00:00Z')
+              expect(arg.startStr).toEqual('2014-05-28T09:00:00Z')
               expect(arg.end).toEqualDate('2014-05-28T10:30:00Z')
               expect(arg.end).toEqualDate('2014-05-28T10:30:00Z')
+              expect(arg.endStr).toEqual('2014-05-28T10:30:00Z')
             }
             }
             spyOn(options, 'select').and.callThrough()
             spyOn(options, 'select').and.callThrough()
             initCalendar(options)
             initCalendar(options)
@@ -185,7 +199,9 @@ describe('select callback', function() {
               expect(typeof arg.view).toEqual('object') // "
               expect(typeof arg.view).toEqual('object') // "
               expect(arg.isAllDay).toEqual(false)
               expect(arg.isAllDay).toEqual(false)
               expect(arg.start).toEqualDate('2014-05-28T09:00:00Z')
               expect(arg.start).toEqualDate('2014-05-28T09:00:00Z')
+              expect(arg.startStr).toEqual('2014-05-28T09:00:00Z')
               expect(arg.end).toEqualDate('2014-05-29T10:30:00Z')
               expect(arg.end).toEqualDate('2014-05-29T10:30:00Z')
+              expect(arg.endStr).toEqual('2014-05-29T10:30:00Z')
             }
             }
             spyOn(options, 'select').and.callThrough()
             spyOn(options, 'select').and.callThrough()
             initCalendar(options)
             initCalendar(options)
@@ -206,7 +222,9 @@ describe('select callback', function() {
               expect(typeof arg.view).toEqual('object') // "
               expect(typeof arg.view).toEqual('object') // "
               expect(arg.isAllDay).toEqual(false)
               expect(arg.isAllDay).toEqual(false)
               expect(arg.start).toEqualDate('2014-05-28T09:00:00Z')
               expect(arg.start).toEqualDate('2014-05-28T09:00:00Z')
+              expect(arg.startStr).toEqual('2014-05-28T09:00:00Z')
               expect(arg.end).toEqualDate('2014-05-28T09:30:00Z')
               expect(arg.end).toEqualDate('2014-05-28T09:30:00Z')
+              expect(arg.endStr).toEqual('2014-05-28T09:30:00Z')
             }
             }
             spyOn(options, 'select').and.callThrough()
             spyOn(options, 'select').and.callThrough()
             initCalendar(options)
             initCalendar(options)