Ejemplo n.º 1
0
    def get_relative_year(self,
                          entity,
                          basetime='2018-11-01 12:00:00',
                          commonParser=None):
        time = arrow.get(basetime)
        base_year = time.year
        util = util_tools.Util()
        matcher = self.relative_year_pat.match(entity)
        decorate_deviation = ''
        if matcher:
            if matcher.group(1):
                decorate_deviation = matcher.group(1)
            year_shift = util.rel_deviation(matcher.group(2),
                                            decorate_deviation)
            if commonParser:
                commonParser.timeUnit[1] = True
                commonParser.date = commonParser.date.shift(years=year_shift)
            return year_shift + base_year
        else:
            matcher = self.relative_year_diviation_pat.match(entity)
            if matcher:
                year_ = 1
                if matcher.group(1):
                    year_ = digitconv.getNumFromHan(matcher.group(1))
                year_shift = util.rel_deviation_num(matcher.group(2), year_)
                if commonParser:
                    commonParser.timeUnit[7] = True
                    commonParser.date = commonParser.date.shift(
                        years=year_shift)
                return base_year + year_shift

        return None
Ejemplo n.º 2
0
 def get_relative_month(self, entity, basetime='2018-11-01 12:00:00', commonParser=None):
     matcher = self.relative_month_pat.match(entity)
     decorate_deviation,deviation = '',''
     util = util_tools.Util()
     time = arrow.get(basetime)
     base_month = time.month
     if matcher:
         if matcher.group(1):
             decorate_deviation = matcher.group(1)
         shift_month = util.rel_deviation(matcher.group(2), decorate_deviation)
         if commonParser:
             commonParser.timeUnit[2] = True
             if shift_month != 0:
                 commonParser.date = commonParser.date.shift(months=shift_month)
         return base_month + shift_month
     else:
         matcher = self.relative_month_diviation_pat.match(entity)
         if matcher:
             month_ = digitconv.getNumFromHan(matcher.group(1))
             shift_month = util.rel_deviation_num(matcher.group(2), month_)
             if commonParser:
                 commonParser.timeUnit[7] = True
                 commonParser.date = commonParser.date.shift(months=shift_month)
             return shift_month + base_month
     return None
Ejemplo n.º 3
0
 def get_relative_hour(self, entity, basetime='2018-11-01 12:00:00', commonParser=None):
     matcher = self.relative_hour_pat.match(entity)
     decorate_deviation,deviation = '',''
     time = arrow.get(basetime)
     base_hour = time.hour
     util = util_tools.Util()
     if matcher:
         if matcher.group(1):
             decorate_deviation = matcher.group(1)
         util = util_tools.Util()
         realHour = base_hour + util.rel_deviation(matcher.group(2), decorate_deviation)
         if commonParser:
             commonParser.timeUnit[5] = True
         return realHour
     else:
         matcher = self.relative_hour_diviation_pat.match(entity)
         if matcher:
             hour = base_hour + util.rel_deviation_num(matcher.group(2), int(matcher.group(1)))
             if commonParser:
                 commonParser.timeUnit[5] = True
             return hour
     return None
Ejemplo n.º 4
0
 def get_relative_second(self,
                         entity,
                         basetime='2018-11-01 12:00:00',
                         commonParser=None):
     matcher = self.relative_second_pat.match(entity)
     decorate_deviation, deviation = '', ''
     if matcher:
         if matcher.group(1):
             decorate_deviation = matcher.group(1)
         if matcher.group(2):
             deviation = matcher.group(2)
         time = arrow.get(basetime)
         if deviation != '':
             util = util_tools.Util()
             realSecond = time.second + util.rel_deviation(
                 deviation, decorate_deviation)
             if commonParser:
                 commonParser.timeUnit[7] = True
             return realSecond
     return None
Ejemplo n.º 5
0
 def get_relative_day(self, entity, basetime='2018-11-01 12:00:00', commonParser=None):
     matcher = self.relative_day_pat.match(entity)
     decorate_deviation, deviation = '', ''
     time = arrow.get(basetime)
     util = util_tools.Util()
     base_day = time.day
     if matcher:
         if matcher.group(1):
             decorate_deviation = matcher.group(1)
         shift_day = util.rel_deviation(matcher.group(2), decorate_deviation)
         if commonParser:
             commonParser.timeUnit[3] = True
             commonParser.date = commonParser.date.shift(days=shift_day)
         return shift_day
     else:
         weekday = time.weekday()#basetime是周四
         matcher = self.week_day_pat.match(entity)
         if matcher:
             week_day = util.week_deviation_num(matcher.group(1), matcher.group(3))
             shift_day = week_day - weekday
             if commonParser:
                 commonParser.timeUnit[3] = True
                 commonParser.date = commonParser.date.shift(days=shift_day)
             return shift_day