fixing loads of bugs in TimePeriod calcs.