示例#1
0
def convert_datestruct_to_dategui(datestruct, ln=None, output_format="d MMM Y, H:mm"):
    """Convert: (2005, 11, 16, 15, 11, 44, 2, 320, 0) => '16 nov 2005, 15:11'
    Month is internationalized
    """
    assert ln is None, 'setting language is not supported'
    try:
        if datestruct[0] and datestruct[1] and datestruct[2]:
            dt = datetime.fromtimestamp(time.mktime(datestruct))
            return babel_format_datetime(dt, output_format)
        else:
            raise ValueError
    except:
        return _("N/A")
示例#2
0
def convert_datestruct_to_dategui(datestruct, ln=None):
    """Convert: (2005, 11, 16, 15, 11, 44, 2, 320, 0) => '16 nov 2005, 15:11'
    Month is internationalized
    """
    ln = default_ln(ln)
    with set_locale(ln):
        try:
            if datestruct[0] and datestruct[1] and datestruct[2]:
                output_format = "d MMM Y, H:mm"
                dt = datetime.fromtimestamp(time.mktime(datestruct))
                return babel_format_datetime(dt, output_format).encode('utf8')
            else:
                raise ValueError
        except:
            return _("N/A").encode('utf8')
示例#3
0
def convert_datestruct_to_dategui(datestruct, ln=None):
    """Convert: (2005, 11, 16, 15, 11, 44, 2, 320, 0) => '16 nov 2005, 15:11'
    Month is internationalized
    """
    ln = default_ln(ln)
    with set_locale(ln):
        try:
            if datestruct[0] and datestruct[1] and datestruct[2]:
                output_format = "d MMM Y, H:mm"
                dt = datetime.fromtimestamp(time.mktime(datestruct))
                return babel_format_datetime(dt, output_format).encode('utf8')
            else:
                raise ValueError
        except:
            return _("N/A").encode('utf8')
示例#4
0
def convert_datetext_to_dategui(datetext, ln=None, secs=False):
    """Convert: '2005-11-16 15:11:57' => '16 nov 2005, 15:11'

    Or optionally with seconds:
    '2005-11-16 15:11:57' => '16 nov 2005, 15:11:57'
    Month is internationalized
    """
    assert ln is None, 'setting language is not supported'
    try:
        datestruct = convert_datetext_to_datestruct(datetext)
        if datestruct == datestruct_default:
            raise ValueError

        if secs:
            output_format = "d MMM Y, H:mm:ss"
        else:
            output_format = "d MMM Y, H:mm"
        dt = datetime.fromtimestamp(time.mktime(datestruct))
        return babel_format_datetime(dt, output_format)
    except ValueError:
        return _("N/A")
示例#5
0
def convert_datetext_to_dategui(datetext, ln=None, secs=False):
    """Convert: '2005-11-16 15:11:57' => '16 nov 2005, 15:11'

    Or optionally with seconds:
    '2005-11-16 15:11:57' => '16 nov 2005, 15:11:57'
    Month is internationalized
    """
    ln = default_ln(ln)
    with set_locale(ln):
        try:
            datestruct = convert_datetext_to_datestruct(datetext)
            if datestruct == datestruct_default:
                raise ValueError

            if secs:
                output_format = "d MMM Y, H:mm:ss"
            else:
                output_format = "d MMM Y, H:mm"
            dt = datetime.fromtimestamp(time.mktime(datestruct))
            return babel_format_datetime(dt, output_format).encode('utf8')
        except ValueError:
            return _("N/A").encode('utf8')
示例#6
0
def convert_datetext_to_dategui(datetext, ln=None, secs=False):
    """Convert: '2005-11-16 15:11:57' => '16 nov 2005, 15:11'

    Or optionally with seconds:
    '2005-11-16 15:11:57' => '16 nov 2005, 15:11:57'
    Month is internationalized
    """
    ln = default_ln(ln)
    with set_locale(ln):
        try:
            datestruct = convert_datetext_to_datestruct(datetext)
            if datestruct == datestruct_default:
                raise ValueError

            if secs:
                output_format = "d MMM Y, H:mm:ss"
            else:
                output_format = "d MMM Y, H:mm"
            dt = datetime.fromtimestamp(time.mktime(datestruct))
            return babel_format_datetime(dt, output_format).encode('utf8')
        except ValueError:
            return _("N/A").encode('utf8')