@contextfilter
def httime(context, time, timeformat='TIME_FORMAT'):
    """ Render time in the current locale """

    if not time:
        return ''

    lang = translation.get_language()

    localeformat = timeformat
    formatspath = getattr(settings, 'FORMAT_MODULE_PATH', 'treeio.formats')
    try:
        modulepath = formatspath + "." + lang + ".formats"
        module = __import__(modulepath, fromlist=[str(modulepath)])
        localeformat = getattr(module, timeformat, timeformat)
    except ImportError:
        pass

    request = context['request']

    user = None
    if request.user.username:
        try:
            user = request.user.profile
        except Exception:
            pass

    # timezone
    default_timezone = settings.HARDTREE_SERVER_DEFAULT_TIMEZONE
    try:
        conf = ModuleSetting.get('default_timezone')[0]
        default_timezone = conf.value
    except:
        pass

    try:
        conf = ModuleSetting.get('default_timezone', user=user)[0]
        default_timezone = conf.value
    except Exception:
        default_timezone = getattr(
            settings, 'HARDTREE_SERVER_TIMEZONE')[default_timezone][0]

    all_timezones = getattr(settings, 'HARDTREE_SERVER_TIMEZONE', [
                            (1, '(GMT-11:00) International Date Line West')])
    title = all_timezones[int(default_timezone)][1]
    GMT = title[4:10]  # with sign e.g. +06:00
    sign = GMT[0:1]  # + or -
    hours = int(GMT[1:3])  # e.g. 06
    mins = int(GMT[4:6])

    if sign == "-":
        time = time - timedelta(hours=hours, minutes=mins)
    else:
        time = time + timedelta(hours=hours, minutes=mins)

    result = djangotime(time, localeformat)

    return Markup(result)
dataset/ETHPy150Open treeio/treeio/treeio/core/templatetags/modules.py/httime/original