本文整理匯總了Python中timezonefinder.TimezoneFinder方法的典型用法代碼示例。如果您正苦於以下問題:Python timezonefinder.TimezoneFinder方法的具體用法?Python timezonefinder.TimezoneFinder怎麽用?Python timezonefinder.TimezoneFinder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類timezonefinder
的用法示例。
在下文中一共展示了timezonefinder.TimezoneFinder方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup
# 需要導入模塊: import timezonefinder [as 別名]
# 或者: from timezonefinder import TimezoneFinder [as 別名]
def setup(hass, config):
if (any(conf[CONF_TIME_AS] in (TZ_DEVICE_UTC, TZ_DEVICE_LOCAL)
for conf in (config.get(DT_DOMAIN) or [])
if conf[CONF_PLATFORM] == DOMAIN)):
pkg = config[DOMAIN][CONF_TZ_FINDER]
try:
asyncio.run_coroutine_threadsafe(
async_process_requirements(
hass, '{}.{}'.format(DOMAIN, DT_DOMAIN), [pkg]),
hass.loop
).result()
except RequirementsNotFound:
_LOGGER.debug('Process requirements failed: %s', pkg)
return False
else:
_LOGGER.debug('Process requirements suceeded: %s', pkg)
if pkg.split('==')[0].strip().endswith('L'):
from timezonefinderL import TimezoneFinder
else:
from timezonefinder import TimezoneFinder
hass.data[DOMAIN] = TimezoneFinder()
return True
示例2: get_local_etc_timezone
# 需要導入模塊: import timezonefinder [as 別名]
# 或者: from timezonefinder import TimezoneFinder [as 別名]
def get_local_etc_timezone(latitude, longitude):
'''
This function gets the time zone at a given latitude and longitude in 'Etc/GMT' format.
This time zone format is used in order to avoid issues caused by Daylight Saving Time (DST) (i.e., redundant or
missing times in regions that use DST).
However, note that 'Etc/GMT' uses a counter intuitive sign convention, where West of GMT is POSITIVE, not negative.
So, for example, the time zone for Zurich will be returned as 'Etc/GMT-1'.
:param latitude: Latitude at the project location
:param longitude: Longitude at the project location
'''
# get the time zone at the given coordinates
tf = TimezoneFinder()
time = pytz.timezone(tf.timezone_at(lng=longitude, lat=latitude)).localize(
datetime.datetime(2011, 1, 1)).strftime('%z')
# invert sign and return in 'Etc/GMT' format
if time[0] == '-':
time_zone = 'Etc/GMT+' + time[2]
else:
time_zone = 'Etc/GMT-' + time[2]
return time_zone
示例3: calculate_sunrise
# 需要導入模塊: import timezonefinder [as 別名]
# 或者: from timezonefinder import TimezoneFinder [as 別名]
def calculate_sunrise(year_to_simulate, longitude, latitude):
"""
Calculate the hour of sunrise for a given year, longitude and latitude. Returns an array
of hours.
"""
# get the time zone name
tf = TimezoneFinder()
time_zone = tf.timezone_at(lng=longitude, lat=latitude)
# define the city_name
location = Location()
location.name = 'name'
location.region = 'region'
location.latitude = latitude
location.longitude = longitude
location.timezone = time_zone
location.elevation = 0
sunrise = []
for day in range(1, 366): # Calculated according to NOAA website
dt = datetime.datetime(year_to_simulate, 1, 1) + datetime.timedelta(day - 1)
dt = pytz.timezone(time_zone).localize(dt)
sun = location.sun(dt)
sunrise.append(sun['sunrise'].hour)
print('complete calculating sunrise')
return sunrise
示例4: get_timezone
# 需要導入模塊: import timezonefinder [as 別名]
# 或者: from timezonefinder import TimezoneFinder [as 別名]
def get_timezone(self):
from timezonefinder import TimezoneFinder
tf = TimezoneFinder()
timezone_string = tf.timezone_at(lng=self.data['longitude'], lat=self.data['latitude'])
timezone = get_time_zone(timezone_string)
_LOGGER.debug("Timezone: " + str(timezone))
return timezone