Density functional approach to the band gaps of finite and periodic two-dimensional systems