better logic for checking night timings and refactored the code into its own function now