@@ -50,6 +50,7 @@ class BaseCalendar
5050 /**
5151 * Returns a date object for which the all time balance will be calculated.
5252 * If current month, returns the actual day. If not, first day of following month.
53+ * // deepcode ignore valid-jsdoc: <not yet implemented>
5354 * @return {Date }
5455 */
5556 _getTargetDayForAllTimeBalance ( )
@@ -274,6 +275,24 @@ class BaseCalendar
274275 return this . _preferences [ 'hide-non-working-days' ] ;
275276 }
276277
278+ /**
279+ * Returns if "enable prefill break time" was set in preferences
280+ * @return {Boolean }
281+ */
282+ _getEnablePrefillBreakTime ( )
283+ {
284+ return this . _preferences [ 'enable-prefill-break-time' ] ;
285+ }
286+
287+ /**
288+ * Returns "break time interval" set in preferences
289+ * @return {string }
290+ */
291+ _getBreakTimeInterval ( )
292+ {
293+ return this . _preferences [ 'break-time-interval' ] ;
294+ }
295+
277296 /**
278297 * Returns if "count today" was set in preferences.
279298 * @return {Boolean }
@@ -388,6 +407,20 @@ class BaseCalendar
388407 this . _togglePunchButton ( enableButton ) ;
389408 }
390409
410+ /**
411+ * Calculates time for break end based on break interval
412+ * @param {string } breakBegin
413+ * @return {string }
414+ */
415+ _calculateBreakEnd ( breakBegin )
416+ {
417+ let breakInterval = this . _getBreakTimeInterval ( ) ;
418+ let breakEnd = sumTime ( breakBegin , breakInterval ) ;
419+
420+ breakEnd = validateTime ( breakEnd ) ? breakEnd : '23:59' ;
421+ return breakEnd ;
422+ }
423+
391424 /**
392425 * Adds the next missing entry on the actual day and updates calendar.
393426 */
@@ -410,17 +443,42 @@ class BaseCalendar
410443 const value = hourMinToHourFormatted ( hour , min ) ;
411444 const key = generateKey ( year , month , day ) ;
412445 const inputs = $ ( '#' + key + ' input[type="time"]' ) ;
413- for ( const element of inputs )
446+
447+ for ( let i = 0 ; i < inputs . length ; i ++ )
414448 {
415- if ( $ ( element ) . val ( ) . length === 0 )
449+ if ( $ ( inputs [ i ] ) . val ( ) . length === 0 )
416450 {
417- $ ( element ) . val ( value ) ;
451+ $ ( inputs [ i ] ) . val ( value ) ;
452+
453+ //Prefill break time
454+ if ( this . _prefillEntryIndex ( i , inputs ) )
455+ {
456+ const breakEnd = this . _calculateBreakEnd ( value ) ;
457+ $ ( inputs [ i + 1 ] ) . val ( breakEnd ) ;
458+ }
418459 this . _updateTimeDayCallback ( key ) ;
419460 break ;
420461 }
421462 }
422463 }
423464
465+ /**
466+ * Returns true if next entry should be prefilled based on break interval
467+ * @param {number } idx
468+ * @param {array } inputs
469+ * @return {Boolean }
470+ */
471+ _prefillEntryIndex ( idx , inputs )
472+ {
473+ if ( this . _getEnablePrefillBreakTime ( ) &&
474+ idx !== inputs . length - 1 &&
475+ idx % 2 === 1 )
476+ {
477+ return true ;
478+ }
479+ return false ;
480+ }
481+
424482 /**
425483 * Based on the key of the input, updates the values for total in DB and display it on page.
426484 * @param {string } key
0 commit comments