@@ -28,6 +28,8 @@ const config = require("../config");
28
28
const { fromYMDString, to24HourString, toYMDString } = require ( "../util/dateTime" ) ;
29
29
const { CalEvent } = require ( "../models/calEvent" ) ;
30
30
const { CalDaily } = require ( "../models/calDaily" ) ;
31
+ const { EventsRange } = require ( "../models/calConst" ) ;
32
+
31
33
32
34
// the events endpoint:
33
35
exports . get = function ( req , res , next ) {
@@ -58,11 +60,13 @@ exports.get = function(req, res, next) {
58
60
if ( ! start . isValid ( ) || ! end . isValid ( ) ) {
59
61
res . textError ( "need valid start and end times" ) ;
60
62
} else {
61
- const range = end . diff ( start , 'day' ) ;
62
- if ( range < 0 ) {
63
- res . textError ( "start date should be before end date" ) ;
64
- } else if ( range > 100 ) {
65
- res . textError ( `event range too large: ${ range } days requested; max 100 days` ) ;
63
+ // add 1 so days in range is inclusive
64
+ // e.g. (2025-06-10 - 2025-06-01 = 9 days difference) + 1 day = 10 day range
65
+ const range = end . diff ( start , 'day' ) + 1 ;
66
+ if ( range < 1 ) {
67
+ res . textError ( "end date cannot be before start date" ) ;
68
+ } else if ( range > EventsRange . MaxDays ) {
69
+ res . textError ( `event range too large: ${ range } days requested; max ${ EventsRange . MaxDays } days` ) ;
66
70
} else {
67
71
return CalDaily . getRangeVisible ( start , end , includeAllEvents ) . then ( ( dailies ) => {
68
72
return getSummaries ( dailies ) . then ( ( events ) => {
@@ -113,16 +117,23 @@ function specialSummary(evt) {
113
117
// expects days are dayjs objects
114
118
// and count is the number of events between the two
115
119
function getPagination ( firstDay , lastDay , count ) {
116
- const range = lastDay . diff ( firstDay , 'day' ) ;
117
- const nextRangeStart = firstDay . add ( range + 1 , 'day' ) ;
118
- const nextRangeEnd = lastDay . add ( range + 1 , 'day' ) ;
120
+ // add 1 so days in range is inclusive
121
+ const range = lastDay . diff ( firstDay , 'day' ) + 1 ;
122
+
123
+ const prevRangeStart = firstDay . subtract ( range , 'day' ) ;
124
+ const prevRangeEnd = lastDay . subtract ( range , 'day' ) ;
125
+ const prev = getEventRangeUrl ( prevRangeStart , prevRangeEnd ) ;
126
+
127
+ const nextRangeStart = firstDay . add ( range , 'day' ) ;
128
+ const nextRangeEnd = lastDay . add ( range , 'day' ) ;
119
129
const next = getEventRangeUrl ( nextRangeStart , nextRangeEnd ) ;
120
130
121
131
return {
122
132
start : toYMDString ( firstDay ) ,
123
133
end : toYMDString ( lastDay ) ,
124
134
range, // tbd: do we need to send this? can client determine from start, end?
125
135
events : count ,
136
+ prev,
126
137
next,
127
138
} ;
128
139
}
0 commit comments