Numerical solution of fractional sub-diffusion and time-fractional diffusion-wave equations via fractional-order Legendre functions