本文整理汇总了Python中khayyam.JalaliDate类的典型用法代码示例。如果您正苦于以下问题:Python JalaliDate类的具体用法?Python JalaliDate怎么用?Python JalaliDate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JalaliDate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ordinal
def test_ordinal(self):
min_ = JalaliDate.fromordinal(1)
max_ = JalaliDate.fromordinal(JalaliDate.max.toordinal())
self.assertEqual(min_.year, 1)
self.assertEqual(min_.month, 1)
self.assertEqual(min_.day, 1)
self.assertEqual(min_, JalaliDate.min)
self.assertEqual(max_, JalaliDate.max)
示例2: test_ordinal
def test_ordinal(self):
min = JalaliDate.fromordinal(1)
max = JalaliDate.fromordinal(JalaliDate.max.toordinal())
self.assertEqual(min.year, 1)
self.assertEqual(min.month, 1)
self.assertEqual(min.day, 1)
self.assertEqual(min, JalaliDate.min)
self.assertEqual(max, JalaliDate.max)
示例3: __init__
def __init__(self, year=1, month=1, day=1, hour=0, minute=0, second=0, microsecond=0, tzinfo=None):
if isinstance(year, JalaliDate):
jd = year
year = jd.year
month = jd.month
day = jd.day
JalaliDate.__init__(self, year, month, day)
self._time = time(hour, minute, second, microsecond, tzinfo)
示例4: test_locale_date
def test_locale_date(self):
"""
Testing:
%x Locale’s appropriate date representation.
"""
self.assertEqual(JalaliDate(1361, 6, 15).strftime('%x'), u'دوشنبه ۱۵ شهریور ۱۳۶۱')
self.assertEqual(JalaliDate().strftime('%x'), u'جمعه ۱ فروردین ۱')
self.assertEqual(JalaliDate.strptime(u'جمعه ۱ فروردین ۱', '%x'), JalaliDate.min)
self.assertEqual(JalaliDate(1375, 1, 31).strftime('%x'), u'جمعه ۳۱ فروردین ۱۳۷۵')
self.assertEqual(JalaliDate.strptime(u'جمعه ۳۱ فروردین ۱۳۷۵%', '%x%%'),
JalaliDate(1375, 1, 31))
示例5: test_instantiate
def test_instantiate(self):
jdate = JalaliDate(1376, 5, 23)
self.assertFalse(jdate is None)
self.assertEqual(JalaliDate(jdate.todate()), jdate)
self.assertEqual(JalaliDate(jdate), jdate)
self.assertEqual(JalaliDate(julian_day=2450674), jdate)
self.assertRaises(ValueError, JalaliDate, MAXYEAR + 1, 5, 23)
self.assertRaises(ValueError, JalaliDate, MAXYEAR, 13, 23)
self.assertRaises(ValueError, JalaliDate, MAXYEAR, 12, 30)
示例6: test_algorithm
def test_algorithm(self):
min = date(623, 1, 1)
max_days = 5000
days = 0
while True:
dt = min + timedelta(days=days)
jd = JalaliDate(dt)
# print('Processing day: %s' % jd)
dt2 = jd.todate()
self.assertEqual(dt, dt2)
days += 1
if days > max_days:
break
示例7: test_operators
def test_operators(self):
invalid_object = dict(a=2)
d1 = JalaliDate(1361, 6, 15)
d2 = JalaliDate(1361, 6, 16)
self.assertRaises(TypeError, d1.__add__, invalid_object)
self.assertRaises(TypeError, d1.__sub__, invalid_object)
self.assertRaises(TypeError, d1.__lt__, invalid_object)
self.assertRaises(TypeError, d1.__gt__, invalid_object)
self.assertRaises(TypeError, d1.__eq__, invalid_object)
self.assertFalse(d1 == 0)
self.assertTrue(d1 == d1.todate())
self.assertTrue(d1 < d2)
self.assertTrue(d1 <= d1.copy())
self.assertFalse(d1 > d2)
self.assertTrue(d1 >= d1.copy())
示例8: test_percent
def test_percent(self):
"""
Testing:
%% A literal '%' character.
"""
self.assert_parse_and_format(JalaliDate(1375, 1, 31), "%Y-%m-%d %%")
self.assert_parse_and_format(JalaliDate(1375, 1, 31), "%Y-%m-%d %% %% %%")
self.assertEqual(JalaliDate(1375, 1, 31).strftime("%Y %%"), "1375 %")
self.assertEqual(JalaliDate.strptime("1375 %", "%Y %%"), JalaliDate(1375, 1, 1))
示例9: test_week
def test_week(self):
"""
Testing:
%a Locale’s abbreviated weekday name.
%A Locale’s full weekday name.
%e ASCII Locale’s abbreviated weekday name.
%E ASCII Locale’s full weekday name.
%T ASCII English full weekday name.
%w Weekday as a decimal number [0(Saturday), 6(Friday)].
%W Week number of the year (SATURDAY as the first day of the week) as a decimal number [00, 53].
All days in a new year preceding the first Monday are considered to be in week 0.
%U Week number of the year (Sunday as the first day of the week) as a decimal number [00, 53].
All days in a new year preceding the first Sunday are considered to be in week 0.
"""
d1 = JalaliDate(1361, 6, 15)
self.assertEqual(d1.strftime('%a'), u'د')
self.assertEqual(d1.strftime('%A'), u'دوشنبه')
self.assertEqual(d1.strftime('%e'), u'D')
self.assertEqual(d1.strftime('%E'), u'Doshanbeh')
self.assertEqual(d1.strftime('%T'), u'Monday')
self.assertEqual(d1.strftime('%w'), u'2')
self.assertEqual(d1.strftime('%W'), u'24')
for i in range(7):
self.assert_parse_and_format(JalaliDate.min + timedelta(i), '%d %w %W %U')
self.assertEqual(
JalaliDate.strptime('1345 10 10 %s' % c.PERSIAN_WEEKDAY_ABBRS[i], '%Y %m %d %a'),
JalaliDate(year=1345, month=10, day=10))
self.assertEqual(
JalaliDate.strptime('1345 10 10 %s' % c.PERSIAN_WEEKDAY_ABBRS_ASCII[i], '%Y %m %d %e'),
JalaliDate(year=1345, month=10, day=10))
self.assertEqual(
JalaliDate.strptime('1345 10 10 %s' % c.PERSIAN_WEEKDAY_NAMES[i], '%Y %m %d %A'),
JalaliDate(year=1345, month=10, day=10))
self.assertEqual(
JalaliDate.strptime('1345 10 10 %s' % c.PERSIAN_WEEKDAY_NAMES_ASCII[i], '%Y %m %d %E'),
JalaliDate(year=1345, month=10, day=10))
self.assertEqual(
JalaliDate.strptime('1345 10 10 %s' % c.ENGLISH_WEEKDAY_NAMES_ASCII[i], '%Y %m %d %T'),
JalaliDate(year=1345, month=10, day=10))
示例10: test_strptime
def test_strptime(self):
"""
%Z not working at all
"""
self.assertEqual(JalaliDate.strptime('1361', '%Y'), JalaliDate(1361))
self.assertEqual(JalaliDate.strptime('1361%C', '%Y%C'), JalaliDate(1361))
self.assertEqual(JalaliDate.strptime(u'اریا1361گلگشت', u'اریا%Yگلگشت'), JalaliDate(1361))
current_century = int(JalaliDate.today().year / 100) * 100
self.assertEqual(JalaliDate.strptime('61', '%y'), JalaliDate(current_century + 61))
self.assertEqual(JalaliDate.strptime('61%C', '%y%C'), JalaliDate(current_century + 61))
self.assertEqual(JalaliDate.strptime(u'اریا61گلگشت', u'اریا%yگلگشت'), JalaliDate(current_century+61))
self.assertEqual(JalaliDate.strptime(u'جمعه 01 اردیبهشت 0001', u'%A %d %B %Y'),
JalaliDate(month=2, day=1))
示例11: test_strptime
def test_strptime(self):
"""
%Z not working at all
"""
def check_format(jdate ,fmt):
jdate_str = jdate.strftime(fmt)
d2 = JalaliDate.strptime(jdate_str, fmt)
self.assertEqual(jdate, d2)
# Test Year
self.assertEqual(JalaliDate.strptime('1361', '%Y'), JalaliDate(1361))
self.assertEqual(JalaliDate.strptime('1361%C', '%Y%C'), JalaliDate(1361))
self.assertEqual(JalaliDate.strptime('اریا1361گلگشت', 'اریا%Yگلگشت'), JalaliDate(1361))
current_century = int(JalaliDate.today().year / 100) * 100
self.assertEqual(JalaliDate.strptime('61', '%y'), JalaliDate(current_century + 61))
self.assertEqual(JalaliDate.strptime('61%C', '%y%C'), JalaliDate(current_century + 61))
self.assertEqual(JalaliDate.strptime('اریا61گلگشت', 'اریا%yگلگشت'), JalaliDate(current_century+61))
# Test months
for i in range(1, 13):
self.assertEqual(JalaliDate.strptime(str(i), '%m'), JalaliDate(month=i))
self.assertEqual(JalaliDate.strptime('1345 %s' % PERSIAN_MONTH_ABBRS[i], '%Y %b'),
JalaliDate(year=1345, month=i, day=1))
self.assertEqual(JalaliDate.strptime('1345 %s' % PERSIAN_MONTH_NAMES[i], '%Y %B'),
JalaliDate(year=1345, month=i, day=1))
self.assertEqual(JalaliDate.strptime('1345 %s' % PERSIAN_MONTH_ABBRS_ASCII[i], '%Y %g'),
JalaliDate(year=1345, month=i, day=1))
self.assertEqual(JalaliDate.strptime('1345 %s' % PERSIAN_MONTH_NAMES_ASCII[i], '%Y %G'),
JalaliDate(year=1345, month=i, day=1))
self.assertRaises(ValueError, JalaliDate.strptime, '13', '%m')
self.assertRaises(ValueError, JalaliDate.strptime, '0', '%m')
self.assertRaises(ValueError, JalaliDate.strptime, '1345 مت', '%Y %b')
self.assertRaises(ValueError, JalaliDate.strptime, '1345 شتران', '%Y %B')
self.assertRaises(ValueError, JalaliDate.strptime, '1345 مت', '%Y %g')
self.assertRaises(ValueError, JalaliDate.strptime, '1345 شتران', '%Y %G')
# Test Week and Weekdays
for i in range(7):
check_format(JalaliDate.min + timedelta(i), '%d %w %W %U')
self.assertEqual(
JalaliDate.strptime('1345 10 10 %s' % PERSIAN_WEEKDAY_ABBRS[i], '%Y %m %d %a'),
JalaliDate(year=1345, month=10, day=10))
self.assertEqual(
JalaliDate.strptime('1345 10 10 %s' % PERSIAN_WEEKDAY_ABBRS_ASCII[i], '%Y %m %d %e'),
JalaliDate(year=1345, month=10, day=10))
self.assertEqual(
JalaliDate.strptime('1345 10 10 %s' % PERSIAN_WEEKDAY_NAMES[i], '%Y %m %d %A'),
JalaliDate(year=1345, month=10, day=10))
self.assertEqual(
JalaliDate.strptime('1345 10 10 %s' % PERSIAN_WEEKDAY_NAMES_ASCII[i], '%Y %m %d %E'),
JalaliDate(year=1345, month=10, day=10))
# Test days
for i in range(1, 32):
self.assertEqual(JalaliDate.strptime(str(i), '%d'), JalaliDate(day=i))
self.assertRaises(ValueError, JalaliDate.strptime, '32', '%d')
self.assertRaises(ValueError, JalaliDate.strptime, '0', '%d')
# Test day of year
for i in range(1, 366):
self.assertEqual(JalaliDate.strptime(str(i), '%j'), JalaliDate.fromordinal(i))
self.assertRaises(ValueError, JalaliDate.strptime, '366', '%j')
self.assertRaises(ValueError, JalaliDate.strptime, '0', '%j')
self.assertEqual(JalaliDate.strptime('1345 5', '%Y %j'),
JalaliDate(year=1345, month=1, day=5))
self.assertEqual(JalaliDate.strptime('1302 123 3 4', '%Y %j %m %d'),
JalaliDate(year=1302, month=4, day=30))
self.assertEqual(JalaliDate.strptime('1302 3 4', '%Y %m %d'),
JalaliDate(year=1302, month=3, day=4))
self.assertEqual(JalaliDate.strptime(u'جمعه 01 اردیبهشت 0001', '%A %d %B %Y'),
JalaliDate(month=2, day=1))
self.assertEqual(JalaliDate.strptime(u'جمعه 01 فروردین 0001', '%x'),
JalaliDate.min)
self.assertEqual(JalaliDate.strptime(u'جمعه 31 فروردین 1375%', '%x%%'),
JalaliDate(1375, 1, 31))
check_format(JalaliDate(1375, 1, 31), "%Y-%m-%d %%")
check_format(JalaliDate(1375, 1, 31), "%Y-%m-%d %% %% %%")
for i in xrange(1, 400):
check_format(JalaliDate.fromordinal(i), "%Y-%m-%d %a%A%b%B%j%w%W%e%E%g%G%x %% %% %%")
d = JalaliDate.today().replace(month=1, day=1)
for i in xrange(1, algorithms.days_in_year(d.year)):
check_format(d + timedelta(i), "%y-%m-%d")
示例12: test_replace
def test_replace(self):
d1 = JalaliDate(1391, 12, 30)
self.assertEqual(d1.replace(year=1395), JalaliDate(1395, 12, 30))
self.assertEqual(d1.replace(month=1), JalaliDate(1391, 1, 30))
self.assertEqual(d1.replace(day=1), JalaliDate(1391, 12, 1))
self.assertRaises(ValueError, d1.replace, year=1392)
示例13: test_year
def test_year(self):
"""
Testing:
%y Year without century as a zero padded decimal number [00, 99].
%n Year without century as a decimal number in persian form [۱, ۹۹].
%u Year without century as a zero padded decimal number in persian form [۰۱, ۹۹].
%Y Year with century as a decimal number [1-3178].
%N Year with century as a decimal number in persian form [۱-۳۱۷۸].
%O Year with century as a zero padded decimal number in persian form [۰۰۰۱-۳۱۷۸].
"""
self.assertEqual(JalaliDate(1361, 6, 15).strftime('%y'), u'61')
self.assertEqual(JalaliDate(1361, 6, 15).strftime('%Y'), u'1361')
self.assertEqual(JalaliDate(61, 11, 5).strftime('%N'), u'۶۱')
self.assertEqual(JalaliDate(61, 11, 5).strftime('%O'), u'۰۰۶۱')
self.assertEqual(JalaliDate.strptime('94', '%y'), JalaliDate(1394))
self.assertEqual(JalaliDate.strptime('01', '%y'), JalaliDate(1301))
self.assertEqual(JalaliDate.strptime('00', '%y'), JalaliDate(1300))
self.assertEqual(JalaliDate.strptime(u'۹۴', '%n'), JalaliDate(1394))
self.assertEqual(JalaliDate.strptime(u'۱', '%n'), JalaliDate(1301))
self.assertEqual(JalaliDate.strptime(u'۰', '%n'), JalaliDate(1300))
self.assertEqual(JalaliDate.strptime(u'۹۴', '%u'), JalaliDate(1394))
self.assertEqual(JalaliDate.strptime(u'۰۱', '%u'), JalaliDate(1301))
self.assertEqual(JalaliDate.strptime(u'۰۰', '%u'), JalaliDate(1300))
self.assertEqual(JalaliDate.strptime(u'۰۰۴', '%N'), JalaliDate(4, 1, 1))
self.assertEqual(JalaliDate.strptime(u'۰۴', '%N'), JalaliDate(4, 1, 1))
self.assertEqual(JalaliDate.strptime(u'۴', '%N'), JalaliDate(4, 1, 1))
self.assertEqual(JalaliDate.strptime(u'۰۰۴', '%O'), JalaliDate(4, 1, 1))
self.assertEqual(JalaliDate.strptime(u'۰۴', '%O'), JalaliDate(4, 1, 1))
self.assertEqual(JalaliDate.strptime(u'۴', '%O'), JalaliDate(4, 1, 1))
this_century = JalaliDate(int(JalaliDate.today().year/100) * 100)
for i in range(99):
self.assert_parse_and_format(this_century.replace(year=this_century.year+i), '%y')
self.assert_parse_and_format(this_century.replace(year=this_century.year+i), '%n')
self.assert_parse_and_format(this_century.replace(year=this_century.year+i), '%u')
for i in range(1, 1001):
self.assert_parse_and_format(JalaliDate(i), '%Y')
self.assert_parse_and_format(JalaliDate(i), '%N')
self.assert_parse_and_format(JalaliDate(i), '%O')
示例14: test_copy
def test_copy(self):
d1 = JalaliDate(1361, 6, 15)
d2 = d1.copy()
self.assertFalse(d1 is d2)
self.assertEqual(d1, d2)
示例15: test_to_from_date
def test_to_from_date(self):
jdate = JalaliDate(self.leap_year, 12, 23)
jdate2 = JalaliDate.from_date(jdate.todate())
self.assertEqual(jdate, jdate2)