コード例 #1
0
    def testConversions(self):
        sdt0 = datetime.now()  # this is a timezone naive datetime
        dt0 = DateTime(sdt0)
        self.assertTrue(dt0.timezoneNaive(), (sdt0, dt0))
        sdt1 = datetime(2007, 10, 4, 18, 14, 42, 580, pytz.utc)
        dt1 = DateTime(sdt1)
        self.assertFalse(dt1.timezoneNaive(), (sdt1, dt1))

        # convert back
        sdt2 = dt0.asdatetime()
        self.assertEqual(sdt0, sdt2)
        sdt3 = dt1.utcdatetime()  # this returns a timezone naive datetime
        self.assertEqual(sdt1.hour, sdt3.hour)

        dt4 = DateTime('2007-10-04T10:00:00+05:00')
        sdt4 = datetime(2007, 10, 4, 5, 0)
        self.assertEqual(dt4.utcdatetime(), sdt4)
        self.assertEqual(dt4.asdatetime(), sdt4.replace(tzinfo=pytz.utc))

        dt5 = DateTime('2007-10-23 10:00:00 US/Eastern')
        tz = pytz.timezone('US/Eastern')
        sdt5 = datetime(2007, 10, 23, 10, 0, tzinfo=tz)
        dt6 = DateTime(sdt5)
        self.assertEqual(dt5.asdatetime(), sdt5)
        self.assertEqual(dt6.asdatetime(), sdt5)
        self.assertEqual(dt5, dt6)
        self.assertEqual(dt5.asdatetime().tzinfo, tz)
        self.assertEqual(dt6.asdatetime().tzinfo, tz)
コード例 #2
0
ファイル: wheel.py プロジェクト: natanaelfelix/Estudos
 def _get_extensions(self):
     pathname = os.path.join(self.dirname, self.filename)
     name_ver = '%s-%s' % (self.name, self.version)
     info_dir = '%s.dist-info' % name_ver
     arcname = posixpath.join(info_dir, 'EXTENSIONS')
     wrapper = codecs.getreader('utf-8')
     result = []
     with ZipFile(pathname, 'r') as zf:
         try:
             with zf.open(arcname) as bf:
                 wf = wrapper(bf)
                 extensions = json.load(wf)
                 cache = self._get_dylib_cache()
                 prefix = cache.prefix_to_dir(pathname)
                 cache_base = os.path.join(cache.base, prefix)
                 if not os.path.isdir(cache_base):
                     os.makedirs(cache_base)
                 for name, relpath in extensions.items():
                     dest = os.path.join(cache_base, convert_path(relpath))
                     if not os.path.exists(dest):
                         extract = True
                     else:
                         file_time = os.stat(dest).st_mtime
                         file_time = date.datetime.fromtimestamp(file_time)
                         info = zf.getinfo(relpath)
                         wheel_time = date.datetime(*info.date_time)
                         extract = wheel_time > file_time
                     if extract:
                         zf.extract(relpath, cache_base)
                     result.append((name, dest))
         except KeyError:
             pass
     return result
コード例 #3
0
ファイル: heuristics.py プロジェクト: natanaelfelix/Estudos
    def update_headers(self, response):
        headers = {}

        if "expires" not in response.headers:
            date = parsedate(response.headers["date"])
            expires = expire_after(timedelta(days=1), date=datetime(*date[:6]))
            headers["expires"] = datetime_to_header(expires)
            headers["cache-control"] = "public"
        return headers
コード例 #4
0
 def testBasicTZ(self):
     # psycopg2 supplies it's own tzinfo instances, with no `zone` attribute
     tz = FixedOffset(60, 'GMT+1')
     dt1 = datetime(2008, 8, 5, 12, 0, tzinfo=tz)
     DT = DateTime(dt1)
     dt2 = DT.asdatetime()
     offset1 = dt1.tzinfo.utcoffset(dt1)
     offset2 = dt2.tzinfo.utcoffset(dt2)
     self.assertEqual(offset1, offset2)
コード例 #5
0
 def test_interfaces(self):
     verifyObject(ITimeDelta, timedelta(minutes=20))
     verifyObject(IDate, date(2000, 1, 2))
     verifyObject(IDateTime, datetime(2000, 1, 2, 10, 20))
     verifyObject(ITime, time(20, 30, 15, 1234))
     verifyObject(ITZInfo, tzinfo())
     verifyClass(ITimeDeltaClass, timedelta)
     verifyClass(IDateClass, date)
     verifyClass(IDateTimeClass, datetime)
     verifyClass(ITimeClass, time)
コード例 #6
0
def rose_reply(display, text):
    if not none_or_empty(text):
        update_name(display, text)

    rose = event('七夕西湖玫瑰跑')

    eid = rose[0]
    table = 'event_runner'
    rid, name, nick = runner(display)
    condition = cond({'eid': eid, 'rid': rid})
    if store.exists(table, condition=condition):
        store.delete(table, condition)
    else:
        store.insert(table, ['eid', 'rid', 'date'],
                     [[eid, rid, date.datetime()]])

    return event_rank(rose)
コード例 #7
0
def _load_date(val):
    microsecond = 0
    tz = None
    try:
        if len(val) > 19:
            if val[19] == '.':
                if val[-1].upper() == 'Z':
                    subsecondval = val[20:-1]
                    tzval = "Z"
                else:
                    subsecondvalandtz = val[20:]
                    if '+' in subsecondvalandtz:
                        splitpoint = subsecondvalandtz.index('+')
                        subsecondval = subsecondvalandtz[:splitpoint]
                        tzval = subsecondvalandtz[splitpoint:]
                    elif '-' in subsecondvalandtz:
                        splitpoint = subsecondvalandtz.index('-')
                        subsecondval = subsecondvalandtz[:splitpoint]
                        tzval = subsecondvalandtz[splitpoint:]
                    else:
                        tzval = None
                        subsecondval = subsecondvalandtz
                if tzval is not None:
                    tz = TomlTz(tzval)
                microsecond = int(
                    int(subsecondval) * (10**(6 - len(subsecondval))))
            else:
                tz = TomlTz(val[19:])
    except ValueError:
        tz = None
    if "-" not in val[1:]:
        return None
    try:
        if len(val) == 10:
            d = date.date(int(val[:4]), int(val[5:7]), int(val[8:10]))
        else:
            d = date.datetime(int(val[:4]), int(val[5:7]), int(val[8:10]),
                              int(val[11:13]), int(val[14:16]),
                              int(val[17:19]), microsecond, tz)
    except ValueError:
        return None
    return d
コード例 #8
0
        tt = _time.localtime(stamp)
        return tt.tm_isdst > 0


Local = LocalTimezone()


def first_sunday_on_or_after(dt):
    days_to_go = 6 - dt.weekday()
    if days_to_go:
        dt += timedelta(days_to_go)
    return dt


# In the US, DST starts at 2am (standard time) on the first Sunday in April.
DSTSTART = datetime(1, 4, 1, 2)
# and ends at 2am (DST time; 1am standard time) on the last Sunday of Oct.
# which is the first Sunday on or after Oct 25.
DSTEND = datetime(1, 10, 25, 1)


# A complete implementation of current DST rules for major US time zones.
class USTimeZone(tzinfo):
    def __init__(self, hours, reprname, stdname, dstname):
        self.stdoffset = timedelta(hours=hours)
        self.reprname = reprname
        self.stdname = stdname
        self.dstname = dstname

    def __repr__(self):
        return self.reprname