示例#1
0
 def _get_name_for_time_point(self, time_point: timezone.datetime):
     if self.unit == self.QUARTER:
         return f'Q{m2q(time_point.month)} {time_point.year}'
     if self.unit == self.MONTH:
         return f'{time_point.month}/{time_point.year}'
     if self.unit == self.YEAR:
         return f'{time_point.year}'
     if self.unit == self.DAY:
         return time_point.date().isoformat()
     if self.unit in [self.HOUR]:
         return time_point.isoformat(sep=' ', timespec='hours') + ':00'
     if self.unit in [self.MINUTE]:
         return time_point.isoformat(sep=' ', timespec='minutes')
示例#2
0
文件: gcal.py 项目: milesmcc/tim
 def get_blocks(self, after: datetime = None, until: datetime = None):
     blocks = []
     if after is None:
         after = now() - timedelta(weeks=1)
         until = now() + timedelta(weeks=1)
     resp = (self.service.freebusy().query(
         body={
             "timeMin": after.isoformat(),
             "timeMax": until.isoformat(),
             "items": [{
                 "id": item
             } for item in self.other_cal_ids],
         }).execute())
     for calendar in resp["calendars"].values():
         for block in calendar["busy"]:
             blocks.append(
                 Block(
                     parse_time(block["start"]),
                     parse_time(block["end"]),
                     buffer=self.buffer,
                 ))
     logging.debug(
         f"Successfully loaded {len(blocks)} busy blocks from calendar.")
     return blocks