All files / ee/app/assets/javascripts/oncall_schedules/components/schedule utils.js

100% Statements 12/12
0% Branches 0/1
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52                                9x 5x 5x 5x   5x     5x     10x     10x     5x                               9x 30x  
import { newDate } from '~/lib/utils/datetime_utility';
import { sprintf, __ } from '~/locale';
import { PRESET_DEFAULTS, DAYS_IN_WEEK } from '../../constants';
 
/**
 * This method returns array of Dates representing 2-weeks timeframe based on provided initialDate
 *
 * For eg; If initialDate is 31th Dec 2017
 *         we show 2 weeks starting from the current date
 * So returned array from this method will be;
 *        [
 *          31 Dec 2017, 7 Jan 2018
 *        ]
 *
 * @param {Date} initialDate
 */
export const getTimeframeForWeeksView = (initialDate = new Date()) => {
  const timeframe = [];
  const startDate = newDate(initialDate);
  startDate.setHours(0, 0, 0, 0);
 
  const rangeLength = PRESET_DEFAULTS.WEEKS.TIMEFRAME_LENGTH;
 
  // Iterate for the length of this preset
  for (let i = 0; i < rangeLength; i += 1) {
    // Push date to timeframe only when day is
    // the first day of the next week (if initial date is Tuesday next date will be also Tuesday but of the next week)
    timeframe.push(newDate(startDate));
 
    // Move date to the next in a week
    startDate.setDate(startDate.getDate() + DAYS_IN_WEEK);
  }
 
  return timeframe;
};
 
/**
 * This method returns the formatted offset for a
 * given timezone against UTC
 *
 *
 * @param {String} offset - the selected timezone offset.
 * @returns {String}
 *
 * @example
 * selectedTimezoneFormattedOffset(offset:"-10:00")
 * => (UTC -10:00)
 *
 */
export const selectedTimezoneFormattedOffset = (offset) =>
  sprintf(__('(UTC %{offset})'), { offset });