convert_lecture_data_to_json.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:softuni-course-calendar-scraper 作者: Enether 项目源码 文件源码
def get_utc_offset() -> str:
    '''
    function gets the difference between our timezones in hours and returns a string that will be put into the iso8601 format
    if we're 3 hours ahead, we will return +03:00
    if we're 3 hours behind, we will return -03:00
    :return:
    '''
    now = datetime.datetime.now()
    local_hour = now.hour
    utc_hour = now.utcnow().hour
    utc_offset = local_hour - utc_hour

    str_preamble = '+' if utc_offset >= 0 else '-'

    # convert the fraction and the whole to a string. Works for ints and floats
    fraction, whole = math.modf(utc_offset)
    fraction = str(fraction)[2:].zfill(2)  # from 0.5 get 05 only
    whole = str(int(whole)).zfill(2)

    return '{preamble}{whole}:{fraction}'.format(preamble=str_preamble, whole=whole, fraction=fraction)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号