private void appendToOutputChunk(StreamEventCloner streamEventCloner,
                                     List<ComplexEventChunk<StreamEvent>> complexEventChunks,
                                     long currentTime, boolean preserveCurrentEvents, WindowState state) {
        ComplexEventChunk<StreamEvent> newEventChunk = new ComplexEventChunk<>();
        ComplexEventChunk<StreamEvent> sentEventChunk = new ComplexEventChunk<>();
        if (state.currentEventChunk.getFirst() != null) {
            if (state.expiredEventChunk != null && state.expiredEventChunk.getFirst() != null) {
                // mark the timestamp for the expiredType event
                state.expiredEventChunk.reset();
                while (state.expiredEventChunk.hasNext()) {
                    StreamEvent expiredEvent = state.expiredEventChunk.next();

                    if (outputExpectsExpiredEvents) {
                        // add expired event to newEventChunk.
                        StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(expiredEvent);
                        toExpireEvent.setTimestamp(currentTime);
                        newEventChunk.add(toExpireEvent);
                    }

                    StreamEvent toSendEvent = streamEventCloner.copyStreamEvent(expiredEvent);
                    toSendEvent.setType(ComplexEvent.Type.CURRENT);
                    sentEventChunk.add(toSendEvent);
                }
            }

            // add reset event in front of current events
            StreamEvent toResetEvent = streamEventCloner.copyStreamEvent(state.resetEvent);
            toResetEvent.setTimestamp(currentTime);
            newEventChunk.add(toResetEvent);

            //add old events
            newEventChunk.add(sentEventChunk.getFirst());

            // move to expired events
            if (preserveCurrentEvents || state.expiredEventChunk != null) {
                state.currentEventChunk.reset();
                while (state.currentEventChunk.hasNext()) {
                    StreamEvent currentEvent = state.currentEventChunk.next();
                    StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
                    toExpireEvent.setType(StreamEvent.Type.EXPIRED);
                    state.expiredEventChunk.add(toExpireEvent);
                }
            }

            // add current event chunk to next processor
            newEventChunk.add(state.currentEventChunk.getFirst());

        }
        state.currentEventChunk.clear();

        if (newEventChunk.getFirst() != null) {
            complexEventChunks.add(newEventChunk);
        }
    }
Here an assumption is taken:
Parameter: timestamp: The time which the window determines as current time and will act upon,
the value of this parameter should be monotonically increasing.
from https://docs.wso2.com/display/CEP400/Inbuilt+Windows#InbuiltWindows-externalTime
modules/siddhi-core/src/main/java/io/siddhi/core/query/processor/stream/window/ExternalTimeBatchWindowProcessor.java