github.com/martinohmann/rfoutlet@v1.2.1-0.20220707195255-8a66aa411105/web/src/format.js (about)

     1  export const weekdaysLong = [
     2    'sunday',
     3    'monday',
     4    'tuesday',
     5    'wednesday',
     6    'thursday',
     7    'friday',
     8    'saturday',
     9  ];
    10  
    11  export const weekdaysShort = [
    12    'sun',
    13    'mon',
    14    'tue',
    15    'wed',
    16    'thu',
    17    'fri',
    18    'sat',
    19  ];
    20  
    21  export function formatDayTime(dayTime, trans = ((k) => k)) {
    22    if (null === dayTime) {
    23      return trans('unset');
    24    }
    25  
    26    return dayTime.toFormat('HH:mm');
    27  }
    28  
    29  export function formatDayTimeInterval(interval, trans = ((k) => k)) {
    30    if (null === interval) {
    31      return trans('unset');
    32    }
    33  
    34    return `${formatDayTime(interval.from)} - ${formatDayTime(interval.to)}`;
    35  }
    36  
    37  export function formatWeekdays(weekdays, trans = ((k) => k)) {
    38    if (weekdays.length === 0) {
    39      return trans('unset');
    40    }
    41  
    42    return weekdays.map(i => trans(weekdaysShort[i])).join(', ');
    43  }
    44  
    45  export function formatSchedule(schedule, trans = ((k) => k)) {
    46    const intervals = schedule.filter(interval => interval.enabled);
    47  
    48    if (intervals.length === 0) {
    49      return '';
    50    }
    51  
    52    return trans('intervals-scheduled', { count: intervals.length });
    53  }