|
| 1 | +import isEmpty from 'lodash/isEmpty'; |
| 2 | + |
| 3 | +const today = new Date().toISOString().split('T')[0]; |
| 4 | +const fastDate = getPastDate(3); |
| 5 | +const futureDates = getFutureDates(12); |
| 6 | +const dates = [fastDate, today].concat(futureDates); |
| 7 | + |
| 8 | +function getFutureDates(numberOfDays: number) { |
| 9 | + const array = []; |
| 10 | + for (let index = 1; index <= numberOfDays; index++) { |
| 11 | + let d = Date.now(); |
| 12 | + if (index > 8) { |
| 13 | + // set dates on the next month |
| 14 | + const newMonth = new Date(d).getMonth() + 1; |
| 15 | + d = new Date(d).setMonth(newMonth); |
| 16 | + } |
| 17 | + const date = new Date(d + 864e5 * index); // 864e5 == 86400000 == 24*60*60*1000 |
| 18 | + const dateString = date.toISOString().split('T')[0]; |
| 19 | + array.push(dateString); |
| 20 | + } |
| 21 | + return array; |
| 22 | +} |
| 23 | +function getPastDate(numberOfDays: number) { |
| 24 | + return new Date(Date.now() - 864e5 * numberOfDays).toISOString().split('T')[0]; |
| 25 | +} |
| 26 | + |
| 27 | +export const agendaItems = [ |
| 28 | + { |
| 29 | + title: dates[0], |
| 30 | + data: [{hour: '12am', duration: '1h', title: 'First Yoga'}] |
| 31 | + }, |
| 32 | + { |
| 33 | + title: dates[1], |
| 34 | + data: [ |
| 35 | + {hour: '4pm', duration: '1h', title: 'Pilates ABC'}, |
| 36 | + {hour: '5pm', duration: '1h', title: 'Vinyasa Yoga'} |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + title: dates[2], |
| 41 | + data: [ |
| 42 | + {hour: '1pm', duration: '1h', title: 'Ashtanga Yoga'}, |
| 43 | + {hour: '2pm', duration: '1h', title: 'Deep Stretches'}, |
| 44 | + {hour: '3pm', duration: '1h', title: 'Private Yoga'} |
| 45 | + ] |
| 46 | + }, |
| 47 | + { |
| 48 | + title: dates[3], |
| 49 | + data: [{hour: '12am', duration: '1h', title: 'Ashtanga Yoga'}] |
| 50 | + }, |
| 51 | + { |
| 52 | + title: dates[4], |
| 53 | + data: [{}] |
| 54 | + }, |
| 55 | + { |
| 56 | + title: dates[5], |
| 57 | + data: [ |
| 58 | + {hour: '9pm', duration: '1h', title: 'Middle Yoga'}, |
| 59 | + {hour: '10pm', duration: '1h', title: 'Ashtanga'}, |
| 60 | + {hour: '11pm', duration: '1h', title: 'TRX'}, |
| 61 | + {hour: '12pm', duration: '1h', title: 'Running Group'} |
| 62 | + ] |
| 63 | + }, |
| 64 | + { |
| 65 | + title: dates[6], |
| 66 | + data: [ |
| 67 | + {hour: '12am', duration: '1h', title: 'Ashtanga Yoga'} |
| 68 | + ] |
| 69 | + }, |
| 70 | + { |
| 71 | + title: dates[7], |
| 72 | + data: [{}] |
| 73 | + }, |
| 74 | + { |
| 75 | + title: dates[8], |
| 76 | + data: [ |
| 77 | + {hour: '9pm', duration: '1h', title: 'Pilates Reformer'}, |
| 78 | + {hour: '10pm', duration: '1h', title: 'Ashtanga'}, |
| 79 | + {hour: '11pm', duration: '1h', title: 'TRX'}, |
| 80 | + {hour: '12pm', duration: '1h', title: 'Running Group'} |
| 81 | + ] |
| 82 | + }, |
| 83 | + { |
| 84 | + title: dates[9], |
| 85 | + data: [ |
| 86 | + {hour: '1pm', duration: '1h', title: 'Ashtanga Yoga'}, |
| 87 | + {hour: '2pm', duration: '1h', title: 'Deep Stretches'}, |
| 88 | + {hour: '3pm', duration: '1h', title: 'Private Yoga'} |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + title: dates[10], |
| 93 | + data: [ |
| 94 | + {hour: '12am', duration: '1h', title: 'Last Yoga'} |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + title: dates[11], |
| 99 | + data: [ |
| 100 | + {hour: '1pm', duration: '1h', title: 'Ashtanga Yoga'}, |
| 101 | + {hour: '2pm', duration: '1h', title: 'Deep Stretches'}, |
| 102 | + {hour: '3pm', duration: '1h', title: 'Private Yoga'} |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + title: dates[12], |
| 107 | + data: [ |
| 108 | + {hour: '12am', duration: '1h', title: 'Last Yoga'} |
| 109 | + ] |
| 110 | + }, |
| 111 | + { |
| 112 | + title: dates[13], |
| 113 | + data: [ |
| 114 | + {hour: '12am', duration: '1h', title: 'Last Yoga'} |
| 115 | + ] |
| 116 | + } |
| 117 | +]; |
| 118 | + |
| 119 | +type MarkedDate = { |
| 120 | + [key: string]: object; |
| 121 | +} |
| 122 | + |
| 123 | +export function getMarkedDates() { |
| 124 | + const marked: MarkedDate = {}; |
| 125 | + |
| 126 | + agendaItems.forEach(item => { |
| 127 | + // NOTE: only mark dates with data |
| 128 | + if (item.data && item.data.length > 0 && !isEmpty(item.data[0])) { |
| 129 | + marked[item.title] = {marked: true}; |
| 130 | + } else { |
| 131 | + marked[item.title] = {disabled: true}; |
| 132 | + } |
| 133 | + }); |
| 134 | + return marked; |
| 135 | +} |
0 commit comments