Beispiel #1
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")
Beispiel #2
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')