Question: Having this timestamp: `1519347000`, I want to convert it into date format inside interpolation like this:

```
{{$ctrl.myTimestamp | date:'MMM d y, hh:mm'}}

```

The resulted values is **Jan 18 1970, 04:02** which is obviously wrong, the correct one should be in this case **February 23, 2018 12:50**

[Plunker here](https://plnkr.co/edit/NdzVbBQMsWq1mXKVNv2a?p=preview).

Any ideas what's going wrong?

Answer: 
`StatefulProtocol` is helpful for protocols like this.

```
from twisted.protocols.stateful import StatefulProtocol

HEADER_LENGTH = 4

class YourProtocol(StatefulProtocol):

    # Define the first handler and what data it expects.
    def getInitialState(self):
        return (
            # The first handler is self._header
            self._header, 
            # And it expects HEADER_LENGTH (4) bytes
            HEADER_LENGTH,
        )

    # When HEADER_LENGTH bytes have been received, this is called.
    def _header(self, data):
        # It returns a tuple representing the next state handler.
        return (
            # The next thing we can handle is a response
            self._response, 
            # And the response is made up of this many bytes.
            int.from_bytes(header, byteorder='big'),
        )

    # When the number of bytes from the header has been received,
    # this is called.
    def _response(self, data):
        # Application dispatch of the data
        self.responseReceived(data)
        # Return to the initial state to process the next received data.
        return self.getInitialState()

```
I've ended up writing the following Custom Receiver

```
HEADER_LENGTH = 4

class CustomReceiver(Protocol):
    _buffer = b''

def dataReceived(self, data):
    logger.info(f'DATA RECEIVED: {data}')

    data = (self._buffer + data)
    header = data[:HEADER_LENGTH]
    logger.info(f'header: {header}   len: {len(header)}')
    while len(header) == HEADER_LENGTH:
        response_length = int.from_bytes(header, byteorder='big')
        response = data[HEADER_LENGTH:][:response_length]
        self.responseReceived(response)
        data = data[HEADER_LENGTH + response_length:]
        header = data[:HEADER_LENGTH]

    self._buffer = header

```

I'm not sure if I should add a locking mechanism for `dataReceived()`, simultaneous invocations will corrupt the `_buffer` data.