本文整理匯總了Python中dateutil.relativedelta.SU屬性的典型用法代碼示例。如果您正苦於以下問題:Python relativedelta.SU屬性的具體用法?Python relativedelta.SU怎麽用?Python relativedelta.SU使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類dateutil.relativedelta
的用法示例。
在下文中一共展示了relativedelta.SU屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testRRuleAll
# 需要導入模塊: from dateutil import relativedelta [as 別名]
# 或者: from dateutil.relativedelta import SU [as 別名]
def testRRuleAll(self):
from dateutil.rrule import rrule
from dateutil.rrule import rruleset
from dateutil.rrule import rrulestr
from dateutil.rrule import YEARLY, MONTHLY, WEEKLY, DAILY
from dateutil.rrule import HOURLY, MINUTELY, SECONDLY
from dateutil.rrule import MO, TU, WE, TH, FR, SA, SU
rr_all = (rrule, rruleset, rrulestr,
YEARLY, MONTHLY, WEEKLY, DAILY,
HOURLY, MINUTELY, SECONDLY,
MO, TU, WE, TH, FR, SA, SU)
for var in rr_all:
self.assertIsNot(var, None)
# In the public interface but not in all
from dateutil.rrule import weekday
self.assertIsNot(weekday, None)
示例2: _day_range
# 需要導入模塊: from dateutil import relativedelta [as 別名]
# 或者: from dateutil.relativedelta import SU [as 別名]
def _day_range(self, days):
"""
inspect a given string with days given as integer numbers separated by ","
:param days:
:return: an array with strings containing the days of month
"""
now = datetime.date.today()
wdays = [MO, TU, WE, TH, FR, SA, SU]
result = []
for day in days.split(','):
wday = wdays[int(day)]
# add next weekday occurrence
day = now + dateutil.relativedelta.relativedelta(weekday=wday)
result.append(day.strftime("%d"))
# safety add-on if weekday equals todays weekday
day = now + dateutil.relativedelta.relativedelta(weekday=wday(+2))
result.append(day.strftime("%d"))
return result
示例3: _delta
# 需要導入模塊: from dateutil import relativedelta [as 別名]
# 或者: from dateutil.relativedelta import SU [as 別名]
def _delta(self, x, isend=0):
from dateutil import relativedelta
kwargs = {}
if x.month is not None:
kwargs["month"] = x.month
if x.weekday is not None:
kwargs["weekday"] = relativedelta.weekday(x.weekday, x.week)
if x.week > 0:
kwargs["day"] = 1
else:
kwargs["day"] = 31
elif x.day:
kwargs["day"] = x.day
elif x.yday is not None:
kwargs["yearday"] = x.yday
elif x.jyday is not None:
kwargs["nlyearday"] = x.jyday
if not kwargs:
# Default is to start on first sunday of april, and end
# on last sunday of october.
if not isend:
kwargs["month"] = 4
kwargs["day"] = 1
kwargs["weekday"] = relativedelta.SU(+1)
else:
kwargs["month"] = 10
kwargs["day"] = 31
kwargs["weekday"] = relativedelta.SU(-1)
if x.time is not None:
kwargs["seconds"] = x.time
else:
# Default is 2AM.
kwargs["seconds"] = 7200
if isend:
# Convert to standard time, to follow the documented way
# of working with the extra hour. See the documentation
# of the tzinfo class.
delta = self._dst_offset - self._std_offset
kwargs["seconds"] -= delta.seconds + delta.days * 86400
return relativedelta.relativedelta(**kwargs)
示例4: testRangeCmp1
# 需要導入模塊: from dateutil import relativedelta [as 別名]
# 或者: from dateutil.relativedelta import SU [as 別名]
def testRangeCmp1(self):
self.assertEqual(tz.tzstr("EST5EDT"),
tz.tzrange("EST", -18000, "EDT", -14400,
relativedelta(hours=+2,
month=4, day=1,
weekday=SU(+1)),
relativedelta(hours=+1,
month=10, day=31,
weekday=SU(-1))))
示例5: testRangeOffsets
# 需要導入模塊: from dateutil import relativedelta [as 別名]
# 或者: from dateutil.relativedelta import SU [as 別名]
def testRangeOffsets(self):
TZR = tz.tzrange('EST', -18000, 'EDT', -14400,
start=relativedelta(hours=2, month=4, day=1,
weekday=SU(+2)),
end=relativedelta(hours=1, month=10, day=31,
weekday=SU(-1)))
dt_std = datetime(2014, 4, 11, 12, 0, tzinfo=TZR) # STD
dt_dst = datetime(2016, 4, 11, 12, 0, tzinfo=TZR) # DST
dst_zero = timedelta(0)
dst_hour = timedelta(hours=1)
std_offset = timedelta(hours=-5)
dst_offset = timedelta(hours=-4)
# Check dst()
self.assertEqual(dt_std.dst(), dst_zero)
self.assertEqual(dt_dst.dst(), dst_hour)
# Check utcoffset()
self.assertEqual(dt_std.utcoffset(), std_offset)
self.assertEqual(dt_dst.utcoffset(), dst_offset)
# Check tzname
self.assertEqual(dt_std.tzname(), 'EST')
self.assertEqual(dt_dst.tzname(), 'EDT')
示例6: testRangeEquality
# 需要導入模塊: from dateutil import relativedelta [as 別名]
# 或者: from dateutil.relativedelta import SU [as 別名]
def testRangeEquality(self):
TZR1 = tz.tzrange('EST', -18000, 'EDT', -14400)
# Standard abbreviation different
TZR2 = tz.tzrange('ET', -18000, 'EDT', -14400)
self.assertNotEqual(TZR1, TZR2)
# DST abbreviation different
TZR3 = tz.tzrange('EST', -18000, 'EMT', -14400)
self.assertNotEqual(TZR1, TZR3)
# STD offset different
TZR4 = tz.tzrange('EST', -14000, 'EDT', -14400)
self.assertNotEqual(TZR1, TZR4)
# DST offset different
TZR5 = tz.tzrange('EST', -18000, 'EDT', -18000)
self.assertNotEqual(TZR1, TZR5)
# Start delta different
TZR6 = tz.tzrange('EST', -18000, 'EDT', -14400,
start=relativedelta(hours=+1, month=3,
day=1, weekday=SU(+2)))
self.assertNotEqual(TZR1, TZR6)
# End delta different
TZR7 = tz.tzrange('EST', -18000, 'EDT', -14400,
end=relativedelta(hours=+1, month=11,
day=1, weekday=SU(+2)))
self.assertNotEqual(TZR1, TZR7)
示例7: testRelativeDeltaAll
# 需要導入模塊: from dateutil import relativedelta [as 別名]
# 或者: from dateutil.relativedelta import SU [as 別名]
def testRelativeDeltaAll(self):
from dateutil.relativedelta import relativedelta
from dateutil.relativedelta import MO, TU, WE, TH, FR, SA, SU
for var in (relativedelta, MO, TU, WE, TH, FR, SA, SU):
self.assertIsNot(var, None)
# In the public interface but not in all
from dateutil.relativedelta import weekday
self.assertIsNot(weekday, None)
示例8: __init__
# 需要導入模塊: from dateutil import relativedelta [as 別名]
# 或者: from dateutil.relativedelta import SU [as 別名]
def __init__(self, stdabbr, stdoffset=None,
dstabbr=None, dstoffset=None,
start=None, end=None):
global relativedelta
if not relativedelta:
from dateutil import relativedelta
self._std_abbr = stdabbr
self._dst_abbr = dstabbr
if stdoffset is not None:
self._std_offset = datetime.timedelta(seconds=stdoffset)
else:
self._std_offset = ZERO
if dstoffset is not None:
self._dst_offset = datetime.timedelta(seconds=dstoffset)
elif dstabbr and stdoffset is not None:
self._dst_offset = self._std_offset+datetime.timedelta(hours=+1)
else:
self._dst_offset = ZERO
if dstabbr and start is None:
self._start_delta = relativedelta.relativedelta(
hours=+2, month=4, day=1, weekday=relativedelta.SU(+1))
else:
self._start_delta = start
if dstabbr and end is None:
self._end_delta = relativedelta.relativedelta(
hours=+1, month=10, day=31, weekday=relativedelta.SU(-1))
else:
self._end_delta = end
示例9: _delta
# 需要導入模塊: from dateutil import relativedelta [as 別名]
# 或者: from dateutil.relativedelta import SU [as 別名]
def _delta(self, x, isend=0):
kwargs = {}
if x.month is not None:
kwargs["month"] = x.month
if x.weekday is not None:
kwargs["weekday"] = relativedelta.weekday(x.weekday, x.week)
if x.week > 0:
kwargs["day"] = 1
else:
kwargs["day"] = 31
elif x.day:
kwargs["day"] = x.day
elif x.yday is not None:
kwargs["yearday"] = x.yday
elif x.jyday is not None:
kwargs["nlyearday"] = x.jyday
if not kwargs:
# Default is to start on first sunday of april, and end
# on last sunday of october.
if not isend:
kwargs["month"] = 4
kwargs["day"] = 1
kwargs["weekday"] = relativedelta.SU(+1)
else:
kwargs["month"] = 10
kwargs["day"] = 31
kwargs["weekday"] = relativedelta.SU(-1)
if x.time is not None:
kwargs["seconds"] = x.time
else:
# Default is 2AM.
kwargs["seconds"] = 7200
if isend:
# Convert to standard time, to follow the documented way
# of working with the extra hour. See the documentation
# of the tzinfo class.
delta = self._dst_offset-self._std_offset
kwargs["seconds"] -= delta.seconds+delta.days*86400
return relativedelta.relativedelta(**kwargs)
示例10: __init__
# 需要導入模塊: from dateutil import relativedelta [as 別名]
# 或者: from dateutil.relativedelta import SU [as 別名]
def __init__(self, stdabbr, stdoffset=None,
dstabbr=None, dstoffset=None,
start=None, end=None):
global relativedelta
if not relativedelta:
from dateutil import relativedelta
self._std_abbr = stdabbr
self._dst_abbr = dstabbr
if stdoffset is not None:
self._std_offset = datetime.timedelta(seconds=stdoffset)
else:
self._std_offset = ZERO
if dstoffset is not None:
self._dst_offset = datetime.timedelta(seconds=dstoffset)
elif dstabbr and stdoffset is not None:
self._dst_offset = self._std_offset+datetime.timedelta(hours=+1)
else:
self._dst_offset = ZERO
if dstabbr and start is None:
self._start_delta = relativedelta.relativedelta(
hours=+2, month=4, day=1, weekday=relativedelta.SU(+1))
else:
self._start_delta = start
if dstabbr and end is None:
self._end_delta = relativedelta.relativedelta(
hours=+1, month=10, day=31, weekday=relativedelta.SU(-1))
else:
self._end_delta = end