コード例 #1
0
ファイル: test_jalali_date.py プロジェクト: siminbar/khayyam
 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
0
ファイル: test_jalali_date.py プロジェクト: danghara/danesh
 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
0
ファイル: test_jalali_date.py プロジェクト: pylover/khayyam
 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)
コード例 #4
0
ファイル: test_jalali_date.py プロジェクト: siminbar/khayyam
    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")
コード例 #5
0
    def test_day(self):
        """
        Testing:
            %d           Day of the month as a decimal number [01, 31].
            %D           Day of the month as a decimal number in persian form [۱, ۳۱].
            %K           Day of the month as a zero padded decimal number in persian form [۰۱, ۳۱].
            %j           Day of the year as a zero padded decimal number [001, 366].
            %J           Day of the year as a decimal number in persian form [۱, ۳۶۶].
            %V           Day of the year as a zero padded decimal number in persian form [..۱, ۳۶۶].

        """

        d1 = JalaliDate(1361, 6, 15)
        self.assertEqual(d1.strftime('%d'), u'15')
        self.assertEqual(d1.strftime('%j'), u'170')
        self.assertEqual(d1.strftime('%D'), u'۱۵')

        self.assertEqual(JalaliDate(1361, 6, 2).strftime('%D'), u'۲')
        self.assertEqual(JalaliDate(1361, 6, 2).strftime('%K'), u'۰۲')
        self.assertEqual(JalaliDate(1361, 6, 2).strftime('%J'), u'۱۵۷')
        self.assertEqual(JalaliDate(1361, 1, 5).strftime('%J'), u'۵')
        self.assertEqual(JalaliDate(1361, 1, 25).strftime('%V'), u'۰۲۵')
        self.assertEqual(JalaliDate(1361, 1, 5).strftime('%V'), u'۰۰۵')

        # 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'۲', '%D'), JalaliDate(2))
        self.assertRaises(ValueError, JalaliDate.strptime, u'۰۲', '%D')

        self.assertEqual(JalaliDate.strptime(u'۰۲', '%K'), JalaliDate(1, 1, 2))
        self.assertRaises(ValueError, JalaliDate.strptime, u'۲', '%K')

        self.assertEqual(JalaliDate.strptime(u'۰۲', '%K'), JalaliDate(1, 1, 2))
        self.assertRaises(ValueError, JalaliDate.strptime, u'۲', '%K')

        self.assertEqual(JalaliDate.strptime(u'۱۵۷', '%J'), JalaliDate(1, 6, 2))
        self.assertEqual(JalaliDate.strptime(u'۷', '%J'), JalaliDate(1, 1, 7))
        self.assertRaises(ValueError, JalaliDate.strptime, u'۰۷', '%J')
        self.assertRaises(ValueError, JalaliDate.strptime, u'۰۴۷', '%J')

        self.assertEqual(JalaliDate.strptime(u'۰۴۷', '%V'), JalaliDate(1, 2, 16))
        self.assertEqual(JalaliDate.strptime(u'۰۰۷', '%V'), JalaliDate(1, 1, 7))
        self.assertRaises(ValueError, JalaliDate.strptime, u'۷', '%V')
        self.assertRaises(ValueError, JalaliDate.strptime, u'۴۷', '%V')


        for i in range(1, 400):
            self.assert_parse_and_format(JalaliDate.fromordinal(i), "%Y-%m-%d")
            self.assert_parse_and_format(JalaliDate.fromordinal(i), "%Y-%m-%D")
            self.assert_parse_and_format(JalaliDate.fromordinal(i), "%Y-%m-%K")
            self.assert_parse_and_format(JalaliDate.fromordinal(i), "%Y-%j")
            self.assert_parse_and_format(JalaliDate.fromordinal(i), "%Y-%J")
            self.assert_parse_and_format(JalaliDate.fromordinal(i), "%Y-%V")
コード例 #6
0
    def test_day(self):
        """
        Testing:
            %d           Day of the month as a decimal number [01, 31].
            %D           Day of the month as a decimal number in persian form [۱, ۳۱].
            %K           Day of the month as a zero padded decimal number in persian form [۰۱, ۳۱].
            %j           Day of the year as a zero padded decimal number [001, 366].
            %J           Day of the year as a decimal number in persian form [۱, ۳۶۶].
            %V           Day of the year as a zero padded decimal number in persian form [..۱, ۳۶۶].

        """

        d1 = JalaliDate(1361, 6, 15)
        self.assertEqual(d1.strftime('%d'), u'15')
        self.assertEqual(d1.strftime('%j'), u'170')
        self.assertEqual(d1.strftime('%D'), u'۱۵')

        self.assertEqual(JalaliDate(1361, 6, 2).strftime('%D'), u'۲')
        self.assertEqual(JalaliDate(1361, 6, 2).strftime('%K'), u'۰۲')
        self.assertEqual(JalaliDate(1361, 6, 2).strftime('%J'), u'۱۵۷')
        self.assertEqual(JalaliDate(1361, 1, 5).strftime('%J'), u'۵')
        self.assertEqual(JalaliDate(1361, 1, 25).strftime('%V'), u'۰۲۵')
        self.assertEqual(JalaliDate(1361, 1, 5).strftime('%V'), u'۰۰۵')

        # 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'۲', '%D'), JalaliDate(day=2))
        self.assertRaises(ValueError, JalaliDate.strptime, u'۰۲', '%D')

        self.assertEqual(JalaliDate.strptime(u'۰۲', '%K'), JalaliDate(1, 1, 2))
        self.assertRaises(ValueError, JalaliDate.strptime, u'۲', '%K')

        self.assertEqual(JalaliDate.strptime(u'۰۲', '%K'), JalaliDate(1, 1, 2))
        self.assertRaises(ValueError, JalaliDate.strptime, u'۲', '%K')

        self.assertEqual(JalaliDate.strptime(u'۱۵۷', '%J'),
                         JalaliDate(1, 6, 2))
        self.assertEqual(JalaliDate.strptime(u'۷', '%J'), JalaliDate(1, 1, 7))
        self.assertRaises(ValueError, JalaliDate.strptime, u'۰۷', '%J')
        self.assertRaises(ValueError, JalaliDate.strptime, u'۰۴۷', '%J')

        self.assertEqual(JalaliDate.strptime(u'۰۴۷', '%V'),
                         JalaliDate(1, 2, 16))
        self.assertEqual(JalaliDate.strptime(u'۰۰۷', '%V'),
                         JalaliDate(1, 1, 7))
        self.assertRaises(ValueError, JalaliDate.strptime, u'۷', '%V')
        self.assertRaises(ValueError, JalaliDate.strptime, u'۴۷', '%V')

        for i in range(1, 400):
            self.assert_parse_and_format(JalaliDate.fromordinal(i), "%Y-%m-%d")
            self.assert_parse_and_format(JalaliDate.fromordinal(i), "%Y-%m-%D")
            self.assert_parse_and_format(JalaliDate.fromordinal(i), "%Y-%m-%K")
            self.assert_parse_and_format(JalaliDate.fromordinal(i), "%Y-%j")
            self.assert_parse_and_format(JalaliDate.fromordinal(i), "%Y-%J")
            self.assert_parse_and_format(JalaliDate.fromordinal(i), "%Y-%V")