Skip to content

Instantly share code, notes, and snippets.

@daTokenizer
Last active December 7, 2015 15:58
Show Gist options
  • Save daTokenizer/baaf5bd23a203680eb17 to your computer and use it in GitHub Desktop.
Save daTokenizer/baaf5bd23a203680eb17 to your computer and use it in GitHub Desktop.
@staticmethod
def timezoneDiffFromGMT(lat, lon):
lon_degrees_per_timezone_hour = 360/24
utc_centeral_lon_degrees = lon_degrees_per_timezone_hour * 12
lon_degrees_from_utc = lon - utc_centeral_lon_degrees
return lon_degrees_from_utc / lon_degrees_per_timezone_hour
def isNight(lat, lon):
hour_at_location = time.gmtime().tm_hour + timezoneDiffFromGMT(lat, lon)
return not 5 < hour_at_location < 22 #set aprox day start and day end times as you like
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment