Skip to content
This repository was archived by the owner on Jun 12, 2018. It is now read-only.

Commit 0f5837a

Browse files
committed
Fix recurring event issue with daylight saving. Refs #433
1 parent 4a29a15 commit 0f5837a

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

client/app/collections/scheduleitems.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = class ScheduleItemsCollection extends Backbone.Collection
2828
eventsInRange.push(
2929
item.toPunctualFullCalendarEvent())
3030

31-
else if item.isInRange start, end
31+
else if item.isInRange(start, end)
3232
eventsInRange.push item.toPunctualFullCalendarEvent()
3333

3434
callback eventsInRange

client/app/models/scheduleitem.coffee

+26-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
Modal = require '../lib/modal'
3-
H = require '../helpers'
3+
H = Helpers = require '../helpers'
44

55
module.exports = class ScheduleItem extends Backbone.Model
66

@@ -64,10 +64,6 @@ module.exports = class ScheduleItem extends Backbone.Model
6464
if @isAllDay()
6565
return moment.tz modelDateStr, 'UTC'
6666

67-
if @isRecurrent()
68-
# Parse with the event timezone
69-
modelDateStr = moment.tz modelDateStr, @get 'timezone'
70-
7167
# convert to the cozy's timezone
7268
return H.toTimezonedMoment modelDateStr
7369

@@ -83,17 +79,18 @@ module.exports = class ScheduleItem extends Backbone.Model
8379
@getDateObject().add 30, 'm'
8480

8581
# Format a moment to the string format of the model.
86-
_formatMoment: (m) ->
82+
_formatMoment: (momentDate) ->
8783
if @isAllDay()
88-
s = H.momentToDateString(m)
84+
formattedDate = Helpers.momentToDateString(momentDate)
8985

90-
else if @isRecurrent() and not @has('timezone')
91-
s = moment.tz(m, @get('timezone')).toISOString()
86+
else if @isRecurrent()
87+
formattedDate = Helpers.momentToAmbiguousString(momentDate)
9288

9389
else
94-
s = m.toISOString()
90+
formattedDate = momentDate.toISOString()
91+
92+
return formattedDate
9593

96-
return s
9794

9895
addToStart: (duration) ->
9996
@set @startDateField, @_formatMoment @getStartDateObject().add duration
@@ -263,12 +260,28 @@ module.exports = class ScheduleItem extends Backbone.Model
263260
return @_toFullCalendarEvent @getStartDateObject(), @getEndDateObject()
264261

265262
_toFullCalendarEvent: (start, end) ->
266-
displayedTime = if not @isAllDay() then start.format 'H:mm[ ]' else ''
263+
264+
# Time is not displayed if the event lasts all day
265+
if @isAllDay()
266+
displayedTime = ""
267+
268+
# Recurring event should be displayed without the timezone taken into
269+
# account.
270+
else if @isRecurrent()
271+
# .utc() changes the `start` object, so it's cloned to prevent side
272+
# effects.
273+
displayedTime = moment(start).utc().format('H:mm')
274+
275+
# Otherwise time is displayed, and timezoned (.format applies timezone)
276+
else
277+
displayedTime = start.format 'H:mm'
278+
279+
267280
description = @get 'description'
268281
description = description or t 'no description'
269282
return fcEvent =
270283
id: @cid
271-
title: "#{displayedTime}#{description}"
284+
title: "#{displayedTime} #{description}"
272285
start: start
273286
end: end
274287
allDay: @isAllDay()

0 commit comments

Comments
 (0)