コード例 #1
0
ファイル: antiquity.py プロジェクト: haxolotl/antiquity
    def __init__(self, *args, **kwargs):
        self.fuzziness = kwargs.get('fuzziness', timedelta(days=0))
        if kwargs.has_key('days'):
            # julian_day
            super(FuzzyPGDate, self).__init__(**kwargs)
            return
            
        year = int(args[0])
        if year < 0:
            year = year + 1
        elif year == 0:
            raise ValueError("There is no year zero - http://lmgtfy.com/?q=year+0")
            
        if len(args) == 1:
            self.create_from_Y(*args)
            return
        month = int(args[1])
        if month > 12 or month < 1:
            raise ValueError("Month must not be less than 1 or greater than 12")
            
        if len(args) == 2:
            self.create_from_YM(*args)
            return

        day = int(args[2]) 
        maxdays = get_month_length(year, month)
        if day < 1 or day > maxdays:
            raise ValueError("Day must not be less than 1 or greater than %s" % maxdays)

        if len(args) == 3:
            self.create_from_YMD(*args) 
            return
              
        raise TypeError("__init__() takes either 1, 2 or 3 arguments")
コード例 #2
0
    def __init__(self, *args, **kwargs):
        self.fuzziness = kwargs.get('fuzziness', timedelta(days=0))
        if kwargs.has_key('days'):
            # julian_day
            super(FuzzyPGDate, self).__init__(**kwargs)
            return

        year = int(args[0])
        if year < 0:
            year = year + 1
        elif year == 0:
            raise ValueError(
                "There is no year zero - http://lmgtfy.com/?q=year+0")

        if len(args) == 1:
            self.create_from_Y(*args)
            return
        month = int(args[1])
        if month > 12 or month < 1:
            raise ValueError(
                "Month must not be less than 1 or greater than 12")

        if len(args) == 2:
            self.create_from_YM(*args)
            return

        day = int(args[2])
        maxdays = get_month_length(year, month)
        if day < 1 or day > maxdays:
            raise ValueError("Day must not be less than 1 or greater than %s" %
                             maxdays)

        if len(args) == 3:
            self.create_from_YMD(*args)
            return

        raise TypeError("__init__() takes either 1, 2 or 3 arguments")
コード例 #3
0
 def create_from_YM(self, year, month):
     day = get_month_length(year, month) / 2.0
     self.fuzziness = self.fuzziness + timedelta(days=day)
     self.create_from_YMD(year, month, day + 1)
コード例 #4
0
 def month_length(self):
     return get_month_length(self.year, self.month)
コード例 #5
0
ファイル: antiquity.py プロジェクト: haxolotl/antiquity
 def create_from_YM(self, year, month):
     day = get_month_length(year, month)/2.0
     self.fuzziness = self.fuzziness + timedelta(days=day)
     self.create_from_YMD(year, month, day + 1)
コード例 #6
0
ファイル: antiquity.py プロジェクト: haxolotl/antiquity
 def month_length(self):
     return get_month_length(self.year, self.month)