Skip to content

Instantly share code, notes, and snippets.

@rizo
Created August 7, 2015 17:13
Show Gist options
  • Select an option

  • Save rizo/e2459845aaa730cab51c to your computer and use it in GitHub Desktop.

Select an option

Save rizo/e2459845aaa730cab51c to your computer and use it in GitHub Desktop.
let add_missing_hours
: Date.t -> (Time.t * 'a) list -> (Time.t * 'a) list
= fun date hourly_counts ->
let gen_day_hours ~start =
List.map (List.range 0 24) (fun hr -> Time.add start (Time.Span.create ~hr ())) in
let day_hours = gen_day_hours
~start:(Time.of_date_ofday date Core.Ofday.start_of_day Core.Zone.utc) in
List.fold day_hours ~init:hourly_counts
~f:(fun hourly_counts' hour ->
if List.Assoc.mem hourly_counts' hour then hourly_counts'
else List.Assoc.add hourly_counts' hour 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment