2 deleted 73 characters in body
source | link

I would suggest a simple solution based on replacement rules combined with Reap/Sow.:

fillGaps[list_] := With[{rules = (Rule @@@ list) ~Join~ {_List -> 0}}, 
    {First@list} ~Join~ (Last@Reap@NestWhile[NestWhileList[
        Composition[(Sow[{#, # /. rules}]; #) &, DatePlus[#, 1] &]&, 
 First],  
       list[[1, 1]]First@list, 
        #First@# =!= list[[-1, 1]] &&]
    ] ~Flatten~ 1)
]

fillGaps[dateList]    
(* {{{2012, 1, 1}, 1}, {{2012, 1, 2}, 2}, {{2012, 1, 3}, 0}, {{2012, 1, 4}, 0}, 
    {{2012, 1, 5}, 3}, {{2012, 1, 6}, 0}, {{2012, 1, 7}, 0}, {{2012, 1, 8}, 4}} *)

I would suggest a simple solution based on replacement rules combined with Reap/Sow.

fillGaps[list_] := With[{rules = (Rule @@@ list) ~Join~ {_List -> 0}}, 
    {First@list} ~Join~ (Last@Reap@NestWhile[
        Composition[(Sow[{#, # /. rules}]; #) &, DatePlus[#, 1] &], 
         list[[1, 1]], 
        # =!= list[[-1, 1]] &
    ] ~Flatten~ 1)
]

fillGaps[dateList]    
(* {{{2012, 1, 1}, 1}, {{2012, 1, 2}, 2}, {{2012, 1, 3}, 0}, {{2012, 1, 4}, 0}, 
    {{2012, 1, 5}, 3}, {{2012, 1, 6}, 0}, {{2012, 1, 7}, 0}, {{2012, 1, 8}, 4}} *)

I would suggest a simple solution based on replacement rules:

fillGaps[list_] := With[{rules = (Rule @@@ list) ~Join~ {_List -> 0}}, 
    NestWhileList[
        Composition[{#, # /. rules} &, DatePlus[#, 1] &, First],  
        First@list,
        First@# =!= list[[-1, 1]] &]
    ]

fillGaps[dateList]    
(* {{{2012, 1, 1}, 1}, {{2012, 1, 2}, 2}, {{2012, 1, 3}, 0}, {{2012, 1, 4}, 0}, 
    {{2012, 1, 5}, 3}, {{2012, 1, 6}, 0}, {{2012, 1, 7}, 0}, {{2012, 1, 8}, 4}} *)
1
source | link

I would suggest a simple solution based on replacement rules combined with Reap/Sow.

fillGaps[list_] := With[{rules = (Rule @@@ list) ~Join~ {_List -> 0}}, 
    {First@list} ~Join~ (Last@Reap@NestWhile[
        Composition[(Sow[{#, # /. rules}]; #) &, DatePlus[#, 1] &], 
        list[[1, 1]], 
        # =!= list[[-1, 1]] &
    ] ~Flatten~ 1)
]

fillGaps[dateList]    
(* {{{2012, 1, 1}, 1}, {{2012, 1, 2}, 2}, {{2012, 1, 3}, 0}, {{2012, 1, 4}, 0}, 
    {{2012, 1, 5}, 3}, {{2012, 1, 6}, 0}, {{2012, 1, 7}, 0}, {{2012, 1, 8}, 4}} *)