Skip to content

Commit a11b3a7

Browse files
committed
make delivery date skip sunday and saturday
1 parent 4b7bf49 commit a11b3a7

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

basic-projects/amazon-project/data/delivery-options.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
import dayjs from 'https://cdn.jsdelivr.net/npm/dayjs/+esm';
22

3+
4+
function correctDate(day){
5+
6+
const dayName = day.format('dddd')
7+
8+
if (dayName === 'Sunday'){
9+
day = day.add(1, 'days')
10+
}
11+
12+
if (dayName === 'Saturday'){
13+
day = day.add(2, 'days')
14+
}
15+
16+
// Format only once at the end.
17+
// Calling .format() earlier would convert `day` to a string
18+
// and break future Dayjs operations like .add()
19+
return day.format('dddd, MMMM D')
20+
}
21+
322
export const deliveryOptions = [{
423
id: '1',
5-
date: dayjs().add(7, 'days').format('dddd, MMMM D'),
24+
date: correctDate(dayjs().add(7, 'days')),
625
priceCents: 0
726
},
827
{
928
id: '2',
10-
date: dayjs().add(3, 'days').format('dddd, MMMM D'),
29+
date: correctDate(dayjs().add(3, 'days')),
1130
priceCents: 499
1231
},
1332
{
1433
id: '3',
15-
date: dayjs().add(1, 'days').format('dddd, MMMM D'),
34+
date: correctDate(dayjs().add(1, 'days')),
1635
priceCents: 999
1736
}];
1837

0 commit comments

Comments
 (0)