示例#1
0
    def test_timelib(self):
        mt = timelib.localtime_mutable()
        print mt
        mt.add_seconds(3600)
        print mt
        print timelib.strftime("%Y-%m-%d", timelib.weekof(timelib.time()))

        t = timelib.now()
        for d in range(1, 60):
            week = timelib.weekof(t+(d*60*60*24))
            print timelib.MutableTime(week)

        print "Local time:"
        print timelib.localtimestamp()

        p = timelib.TimespecParser()
        for spec, secs in [
            ("0s", 0.0),
            ("3m", 180.0),
            ("3.0m", 180.0),
            ("3minute+2secs", 182.0),
            ("2h 3minute+2.2secs", 7382.2),
            ("-3m", -180.0),
            ("-3.0m", -180.0),
            ("1h3m", 3780.0),
            ("1h-3m", 3420.0),
            ("1d 3m", 86580.0)]:
            p.parse(spec)
            self.assert_(p.seconds == secs)

        self.assertRaises(ValueError, p.parse, "12m -m")
示例#2
0
    def test_timelib(self):
        mt = timelib.localtime_mutable()
        print(mt)
        mt.add_seconds(3600)
        print(mt)
        print(timelib.strftime("%Y-%m-%d", timelib.weekof(timelib.time())))

        t = timelib.now()
        for d in range(1, 60):
            week = timelib.weekof(t+(d*60*60*24))
            print(timelib.MutableTime(week))

        print("Local time:")
        print(timelib.localtimestamp())

        p = timespec.TimespecParser()
        for spec, secs in [
            ("0s", 0.0),
            ("3m", 180.0),
            ("3.0m", 180.0),
            ("3minute+2secs", 182.0),
            ("2h 3minute+2.2secs", 7382.2),
            ("-3m", -180.0),
            ("-3.0m", -180.0),
            ("1h3m", 3780.0),
            ("1h-3m", 3420.0),
            ("1d 3m", 86580.0)]:
            p.parse(spec)
            self.assert_(p.seconds == secs)

        self.assertRaises(ValueError, p.parse, "12m -m")
示例#3
0
文件: rfc2822.py 项目: kdart/pycopia3
def formatdate(timeval=None):
    """Returns time format preferred for Internet standards.

    Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123

    According to RFC 1123, day and month names must always be in
    English.  If not for that, this code could use strftime().  It
    can't because strftime() honors the locale and could generated
    non-English names.
    """
    from pycopia import timelib
    if timeval is None:
        timeval = timelib.time()
    timeval = timelib.gmtime(timeval)
    return "%s, %02d %s %04d %02d:%02d:%02d GMT" % (
            ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][timeval[6]],
            timeval[2],
            ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
             "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][timeval[1]-1],
                                timeval[0], timeval[3], timeval[4], timeval[5])
示例#4
0
def formatdate(timeval=None):
    """Returns time format preferred for Internet standards.

    Sun, 06 Nov 1994 08:49:37 GMT  ; RFC 822, updated by RFC 1123

    According to RFC 1123, day and month names must always be in
    English.  If not for that, this code could use strftime().  It
    can't because strftime() honors the locale and could generated
    non-English names.
    """
    from pycopia import timelib
    if timeval is None:
        timeval = timelib.time()
    timeval = timelib.gmtime(timeval)
    return "%s, %02d %s %04d %02d:%02d:%02d GMT" % ([
        "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
    ][timeval[6]], timeval[2], [
        "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
        "Nov", "Dec"
    ][timeval[1] - 1], timeval[0], timeval[3], timeval[4], timeval[5])