DRY up historical bucket_idx calculation