我在我的Ionic应用程序上使用https://github.com/mattlewis92/angular-calendar。当我从我的组件文件中加载一个事件数组时,一切都很好。我是这么做的
.ts:
bookingsToLoad: BookingEvent[] = [
{
id: 1,
title: "First booking",
start: new Date(2021, 6, 7, 12, 30, 0, 0),
end: new Date(2021, 6, 7, 13, 30, 0, 0),
userId: 2,
},
{
id: 2,
title: "Second booking",
start: new Date(2021, 6, 8, 13, 30, 0, 0),
end: new Date(2021, 6, 8, 14, 30, 0, 0),
},
];
.html:
<mwl-calendar-week-view
*ngSwitchCase="'week'"
[viewDate]="viewDate"
[events]="bookingsFromServer"
(dayHeaderClicked)="clickedDate = $event.day.date"
(hourSegmentClicked)="openCalModal($event)"
[dayStartHour] = "8"
[dayEndHour] = "18"
[refresh]="refresh"
[startDay] = "1"
[weekStartsOn] = "1"
>
</mwl-calendar-week-view>
但是,当我从我的server.ts文件(使用express node.js)中获取相同的事件时,它崩溃并显示以下错误:
Starting with v2.0.0-beta.1 date-fns doesn't accept strings as date arguments. Please use `parseISO` to parse strings.
Error
at toDate (index.js:47)
at startOfSecond (index.js:28)
at isSameSecond (index.js:32)
at isEventIsPeriod (calendar-utils.js:152)
at calendar-utils.js:165
at Array.filter (<anonymous>)
at getEventsInPeriod (calendar-utils.js:164)
at getWeekView (calendar-utils.js:361)
at CalendarUtils.getWeekView (angular-calendar.js:1406)
at CalendarWeekViewComponent.getWeekView (angular-calendar.js:2803)
如果我这样写我的日期:
start: new Date('2021-7-13T12:30:00.000Z'),
end: new Date('2021-7-13T12:30:00.000Z'),
它显示:
angular-calendar.js:776 angular-calendar Event is missing the `start` property
{id: 1, title: "First booking", start: null, end: null, userId: 2}
end: null
id: 1
start: null
title: "First booking"
userId: 2
有谁知道如何解决这个问题吗?
非常感谢
2条答案
按热度按时间hs1ihplo1#
new Date('2021-7-13T12:30:00.000Z')
产生一个无效的日期,这就是为什么你的start
和end
属性设置为null
。正确的字符串格式应为:
new Date('2021-07-13T12:30:00.000Z')
(月份使用两位数字)。如果出于某种原因,你需要坚持原来的字符串格式,我建议你像这样使用date-fns的
parse
函数:34gzjxbg2#
在我的例子中,在reactjs中,我通过使用const dateDob = Date.parse('2021 -7- 13 T12:30:00.000Z ')得出结论,它以毫秒为单位返回Date,然后用途:
new Date(dateDob)