1
1
2
2
Modal = require ' ../lib/modal'
3
- H = require ' ../helpers'
3
+ H = Helpers = require ' ../helpers'
4
4
5
5
module .exports = class ScheduleItem extends Backbone.Model
6
6
@@ -64,10 +64,6 @@ module.exports = class ScheduleItem extends Backbone.Model
64
64
if @ isAllDay ()
65
65
return moment .tz modelDateStr, ' UTC'
66
66
67
- if @ isRecurrent ()
68
- # Parse with the event timezone
69
- modelDateStr = moment .tz modelDateStr, @ get ' timezone'
70
-
71
67
# convert to the cozy's timezone
72
68
return H .toTimezonedMoment modelDateStr
73
69
@@ -83,17 +79,18 @@ module.exports = class ScheduleItem extends Backbone.Model
83
79
@ getDateObject ().add 30 , ' m'
84
80
85
81
# Format a moment to the string format of the model.
86
- _formatMoment : (m ) ->
82
+ _formatMoment : (momentDate ) ->
87
83
if @ isAllDay ()
88
- s = H .momentToDateString (m )
84
+ formattedDate = Helpers .momentToDateString (momentDate )
89
85
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 )
92
88
93
89
else
94
- s = m .toISOString ()
90
+ formattedDate = momentDate .toISOString ()
91
+
92
+ return formattedDate
95
93
96
- return s
97
94
98
95
addToStart : (duration ) ->
99
96
@ set @startDateField , @ _formatMoment @ getStartDateObject ().add duration
@@ -263,12 +260,28 @@ module.exports = class ScheduleItem extends Backbone.Model
263
260
return @ _toFullCalendarEvent @ getStartDateObject (), @ getEndDateObject ()
264
261
265
262
_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
+
267
280
description = @ get ' description'
268
281
description = description or t ' no description'
269
282
return fcEvent =
270
283
id : @cid
271
- title : " #{ displayedTime}#{ description} "
284
+ title : " #{ displayedTime} #{ description} "
272
285
start : start
273
286
end : end
274
287
allDay : @ isAllDay ()
0 commit comments