Fill gaps in period query

When start_at and end_at parameters are provided timeseries are extended to match the query and any gaps are filled with 'empty' items. Empty in this context means they have a count of zero.

This pull request pulls timeseries and period handling out bucket into a separate module and reuses the period start at calculation when writing events.