@@ -55,7 +55,7 @@ export class AddonBlockTimelineProvider {
5555 ) : Promise < { events : AddonCalendarEvent [ ] ; canLoadMore ?: number } > {
5656 const site = await CoreSites . getSite ( siteId ) ;
5757
58- const time = moment ( ) . subtract ( 14 , 'days' ) . unix ( ) ; // Check two weeks ago.
58+ const time = this . getDayStart ( - 14 ) ; // Check two weeks ago.
5959
6060 const data : AddonCalendarGetActionEventsByCourseWSParams = {
6161 timesortfrom : time ,
@@ -109,7 +109,7 @@ export class AddonBlockTimelineProvider {
109109 ) : Promise < { [ courseId : string ] : { events : AddonCalendarEvent [ ] ; canLoadMore ?: number } } > {
110110 const site = await CoreSites . getSite ( siteId ) ;
111111
112- const time = moment ( ) . subtract ( 14 , 'days' ) . unix ( ) ; // Check two weeks ago.
112+ const time = this . getDayStart ( - 14 ) ; // Check two weeks ago.
113113
114114 const data : AddonCalendarGetActionEventsByCoursesWSParams = {
115115 timesortfrom : time ,
@@ -164,7 +164,7 @@ export class AddonBlockTimelineProvider {
164164 ) : Promise < { events : AddonCalendarEvent [ ] ; canLoadMore ?: number } > {
165165 const site = await CoreSites . getSite ( siteId ) ;
166166
167- const timesortfrom = moment ( ) . subtract ( 14 , 'days' ) . unix ( ) ; // Check two weeks ago.
167+ const timesortfrom = this . getDayStart ( - 14 ) ; // Check two weeks ago.
168168 const limitnum = AddonBlockTimelineProvider . EVENTS_LIMIT ;
169169
170170 const data : AddonCalendarGetActionEventsByTimesortWSParams = {
@@ -275,6 +275,16 @@ export class AddonBlockTimelineProvider {
275275 } ;
276276 }
277277
278+ /**
279+ * Returns the timestamp at the start of the day with an optional offset.
280+ *
281+ * @param daysOffset Offset days to add or substract.
282+ * @return timestamp.
283+ */
284+ getDayStart ( daysOffset = 0 ) : number {
285+ return moment ( ) . startOf ( 'day' ) . add ( daysOffset , 'days' ) . unix ( ) ;
286+ }
287+
278288}
279289
280290export const AddonBlockTimeline = makeSingleton ( AddonBlockTimelineProvider ) ;
0 commit comments