blackbluegl / calendar-component

initial Vaadin8 calendar-component
Apache License 2.0
11 stars 21 forks source link

Daterange is too big (max 60) = 61 #35

Open allenvpn312 opened 5 years ago

allenvpn312 commented 5 years ago

While testing the addon on Vaadin 8, I came across a runtime error. The strange thing is it only happens when you jump from March to April in month mode. You can reproduce the error by overriding the BasicForwardHandler forward(ForwardEvent event) method.

        // Forward handler
        accountCalendar.setHandler(new BasicForwardHandler() {
            /**
             * 
             */
            private static final long serialVersionUID = 1L;

            /*
             * (non-Javadoc)
             * 
             * @see
             * org.vaadin.addon.calendar.handler.BasicForwardHandler#forward(org.vaadin.
             * addon.calendar.ui.CalendarComponentEvents.ForwardEvent)
             */
            @Override
            public void forward(ForwardEvent event) {
                ZonedDateTime bstart = event.getComponent().getStartDate();
                ZonedDateTime bend = event.getComponent().getEndDate();

                long bduration = Duration.between(bstart, bend).toDays();

                System.out.println("Before super start " + bstart);
                System.out.println("Before super end " + bend);
                System.out.println("Before super duration " + bduration);

                // Let the super handle the rest
                super.forward(event);

                ZonedDateTime astart = event.getComponent().getStartDate();
                ZonedDateTime aend = event.getComponent().getEndDate();

                long aduration = Duration.between(bstart, bend).toDays();

                System.out.println("After super start " + astart);
                System.out.println("After super end " + aend);

                System.out.println("After super duration " + aduration);
            }
        });

Stacktrace

java.lang.RuntimeException: Daterange is too big (max 60) = 61 at org.vaadin.addon.calendar.Calendar.setupDaysAndActions(Calendar.java:595) at org.vaadin.addon.calendar.Calendar.beforeClientResponse(Calendar.java:323) at com.vaadin.server.communication.UidlWriter.write(UidlWriter.java:126) at com.vaadin.server.communication.AtmospherePushConnection.push(AtmospherePushConnection.java:168) at com.vaadin.server.communication.PushHandler.lambda$new$1(PushHandler.java:149) at com.vaadin.server.communication.PushHandler.callWithUi(PushHandler.java:248) at com.vaadin.server.communication.PushHandler.onMessage(PushHandler.java:534) at com.vaadin.server.communication.PushAtmosphereHandler.onMessage(PushAtmosphereHandler.java:87) at com.vaadin.server.communication.PushAtmosphereHandler.onRequest(PushAtmosphereHandler.java:77) at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:225) at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:114) at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:67) at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2297) at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:594) at org.atmosphere.websocket.DefaultWebSocketProcessor$3.run(DefaultWebSocketProcessor.java:345) at org.atmosphere.util.VoidExecutorService.execute(VoidExecutorService.java:101) at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:340) at org.atmosphere.websocket.DefaultWebSocketProcessor.invokeWebSocketProtocol(DefaultWebSocketProcessor.java:448) at org.atmosphere.container.JSR356Endpoint$3.onMessage(JSR356Endpoint.java:272) at org.atmosphere.container.JSR356Endpoint$3.onMessage(JSR356Endpoint.java:269) at org.apache.tomcat.websocket.WsFrameBase.sendMessageText(WsFrameBase.java:395) at org.apache.tomcat.websocket.server.WsFrameServer.sendMessageText(WsFrameServer.java:119) at org.apache.tomcat.websocket.WsFrameBase.processDataText(WsFrameBase.java:495) at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:294) at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:133) at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:82) at org.apache.tomcat.websocket.server.WsFrameServer.doOnDataAvailable(WsFrameServer.java:171) at org.apache.tomcat.websocket.server.WsFrameServer.notifyDataAvailable(WsFrameServer.java:151) at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:148) at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:54) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)

allenvpn312 commented 5 years ago

I tested again to confirm just using the BasicBackwardHandler and BasicForwardHandler with no overriding logic. In month mode, press the backward button until you get to March of any year. Wait for a few seconds then press the forward button to jump to April. This will produce the runtime exception every time. If navigating repeatedly from month to month using the backward/forward button, the errors doesn't seem to occur. I will review the project code to see if I can identify what is triggering it. Overall, great add-on, except for this issue, I am able to get all the calendar functions working correctly.

allenvpn312 commented 5 years ago

I think this may have to do with the leap year date/time check.

allenvpn312 commented 5 years ago

Can someone please help me with this issue? Thank you.

lemagnecharle commented 4 years ago

I was struggeling with this issue myself and the error occurs in the calender-component-demo too.

While debugging I found out that the org.vaadin.addon.calendar.handler.BasicBackwardHandler

seems to be the problem.

In month view, when stepping forward, it always uses the first day of month A and B to set the dates eg 1.3.2020 and 1.4.2020

when stepping backwards, it suddenly uses the last day of month A-1 and the last day of month A to set the dates eg 29.2.2020 and 31.3.2020.

I don't know if that's the desired behaviour.

Steps to reproduce:

  1. Switch to month mode
  2. Step to March 2020
  3. Step to April 2020
  4. Step back to March 2020
  5. Step to April 2020 again