当前位置: 首页>>代码示例>>Python>>正文


Python timezonefinder.TimezoneFinder方法代码示例

本文整理汇总了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 
开发者ID:pnbruckner,项目名称:ha-composite-tracker,代码行数:26,代码来源:__init__.py

示例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 
开发者ID:architecture-building-systems,项目名称:CityEnergyAnalyst,代码行数:26,代码来源:solar_equations.py

示例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 
开发者ID:architecture-building-systems,项目名称:CityEnergyAnalyst,代码行数:29,代码来源:radiation.py

示例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 
开发者ID:claytonjn,项目名称:hass-circadian_lighting,代码行数:9,代码来源:__init__.py


注:本文中的timezonefinder.TimezoneFinder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。