如何检查两个日期之间
How to check between two dates
我有两个不同的数组:
accomodation: [
{
id: 1,
name: "Senator Hotel Fnideq",
address: "Route de Ceuta, 93100 Fnidek, Morocco",
checkin: "September 1",
fullCheckinDate: "2021-09-01",
checkout: "September 3",
fullCheckoutDate: "2021-09-03",
nights: 2,
mealplan: "Breakfast,Lunch"
},
{
id: 2,
name: "Kabek Morocco Hotel",
address: "Omis Juy, 93100 Kabek, Morocco",
checkin: "September 3",
fullCheckinDate: "2021-09-03",
checkout: "September 5",
fullCheckoutDate: "2021-09-05",
nights: 2,
mealplan: "Breakfast,Lunch"
}
]
experiences: [
{
id: 1,
fullDate: "2021-09-01",
title: "Arrival",
itinerary: // []
},
{
id: 2,
fullDate: "2021-09-02",
title: "Sightseeing",
itinerary: // []
}
]
我想找到一种方法将住宿和体验之间相同的日期组合成一个对象。
myTrips: [
{
accomodation: {
id: 1,
name: "Senator Hotel Fnideq",
address: "Route de Ceuta, 93100 Fnidek, Morocco",
checkin: "September 1",
fullCheckinDate: "2021-09-01",
checkout: "September 3",
fullCheckoutDate: "2021-09-03",
nights: 2,
mealplan: "Breakfast,Lunch"
},
experiences: {
id: 1,
fullDate: "2021-09-01",
title: "Arrival",
itinerary: // []
}
},
//... another object
]
我正在使用 dayjs
来帮助确定日期。我该怎么做
const accomodation = [
{
id: 1,
name: "Senator Hotel Fnideq",
address: "Route de Ceuta, 93100 Fnidek, Morocco",
checkin: "September 1",
fullCheckinDate: "2021-09-01",
checkout: "September 3",
fullCheckoutDate: "2021-09-03",
nights: 2,
mealplan: "Breakfast,Lunch"
},
{
id: 2,
name: "Kabek Morocco Hotel",
address: "Omis Juy, 93100 Kabek, Morocco",
checkin: "September 3",
fullCheckinDate: "2021-09-03",
checkout: "September 5",
fullCheckoutDate: "2021-09-05",
nights: 2,
mealplan: "Breakfast,Lunch"
}
];
const experiences = [
{
id: 1,
fullDate: "2021-09-01",
title: "Arrival",
itinerary: []
},
{
id: 2,
fullDate: "2021-09-02",
title: "Sightseeing",
itinerary: []
}
];
const myTrips = [];
accomodation.map(acc => {
const experience = experiences.filter(exp => {
const date = new Date(exp.fullDate);
return date >= new Date(acc.fullCheckinDate) && date <= new Date(acc.fullCheckoutDate);
});
myTrips.push({accomodation: acc, experience});
});
console.log(myTrips);
我有两个不同的数组:
accomodation: [
{
id: 1,
name: "Senator Hotel Fnideq",
address: "Route de Ceuta, 93100 Fnidek, Morocco",
checkin: "September 1",
fullCheckinDate: "2021-09-01",
checkout: "September 3",
fullCheckoutDate: "2021-09-03",
nights: 2,
mealplan: "Breakfast,Lunch"
},
{
id: 2,
name: "Kabek Morocco Hotel",
address: "Omis Juy, 93100 Kabek, Morocco",
checkin: "September 3",
fullCheckinDate: "2021-09-03",
checkout: "September 5",
fullCheckoutDate: "2021-09-05",
nights: 2,
mealplan: "Breakfast,Lunch"
}
]
experiences: [
{
id: 1,
fullDate: "2021-09-01",
title: "Arrival",
itinerary: // []
},
{
id: 2,
fullDate: "2021-09-02",
title: "Sightseeing",
itinerary: // []
}
]
我想找到一种方法将住宿和体验之间相同的日期组合成一个对象。
myTrips: [
{
accomodation: {
id: 1,
name: "Senator Hotel Fnideq",
address: "Route de Ceuta, 93100 Fnidek, Morocco",
checkin: "September 1",
fullCheckinDate: "2021-09-01",
checkout: "September 3",
fullCheckoutDate: "2021-09-03",
nights: 2,
mealplan: "Breakfast,Lunch"
},
experiences: {
id: 1,
fullDate: "2021-09-01",
title: "Arrival",
itinerary: // []
}
},
//... another object
]
我正在使用 dayjs
来帮助确定日期。我该怎么做
const accomodation = [
{
id: 1,
name: "Senator Hotel Fnideq",
address: "Route de Ceuta, 93100 Fnidek, Morocco",
checkin: "September 1",
fullCheckinDate: "2021-09-01",
checkout: "September 3",
fullCheckoutDate: "2021-09-03",
nights: 2,
mealplan: "Breakfast,Lunch"
},
{
id: 2,
name: "Kabek Morocco Hotel",
address: "Omis Juy, 93100 Kabek, Morocco",
checkin: "September 3",
fullCheckinDate: "2021-09-03",
checkout: "September 5",
fullCheckoutDate: "2021-09-05",
nights: 2,
mealplan: "Breakfast,Lunch"
}
];
const experiences = [
{
id: 1,
fullDate: "2021-09-01",
title: "Arrival",
itinerary: []
},
{
id: 2,
fullDate: "2021-09-02",
title: "Sightseeing",
itinerary: []
}
];
const myTrips = [];
accomodation.map(acc => {
const experience = experiences.filter(exp => {
const date = new Date(exp.fullDate);
return date >= new Date(acc.fullCheckinDate) && date <= new Date(acc.fullCheckoutDate);
});
myTrips.push({accomodation: acc, experience});
});
console.log(myTrips);