Ejemplo n.º 1
0
def calculate_fake_gas_reading_timestamp(
        now: timezone.datetime, is_dsmr_v5: bool) -> timezone.datetime:
    """ When overriding time, we cannot fake each gas reading to have its own timestamp. Simulate meters instead. """
    now = now.replace(second=0, microsecond=0)

    if not is_dsmr_v5:
        # DSMR v4 should group by hour.
        return now.replace(minute=0)

    # Group by 5 minutes.
    return now.replace(minute=now.minute - now.minute % 5, )
Ejemplo n.º 2
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')
Ejemplo n.º 3
0
def get_converted_time_string(t: timezone.datetime):
    now = timezone.now()
    delta = now - t
    delta_minutes = int(delta.total_seconds() // 60)
    # print(t.strftime("%y/%m/%d %H:%M")) # => 한국 시간으로 잘 나온다.
    if delta_minutes < 5:
        return "지금"
    elif delta_minutes < 60:
        return str(delta_minutes) + "분 전"
    elif t.year == now.year and t.month == now.month and t.day == now.day:
        return t.strftime("%H:%M")
    elif t.year == now.year:
        return t.strftime("%m/%d %H:%M")

    return t.strftime("%y/%m/%d %H:%M")
Ejemplo n.º 4
0
 def _group_count_factory(
     count_total: int,
     count_seen: int,
     count_not_seen: int,
     count_bar: int,
     needs_attn: bool = False,
     datetimecounted: datetime = None,
     comment: str = "",
     group: Group = group_B,
     user: User = user_base,
     enclosure: Enclosure = enclosure_base,
 ) -> GroupCount:
     if datetimecounted is None:
         datetimecounted = localtime()
     return GroupCount.objects.create(
         group=group,
         datetimecounted=datetimecounted,
         datecounted=datetimecounted.date(),
         user=user,
         enclosure=enclosure,
         count_total=count_total,
         count_seen=count_seen,
         count_not_seen=count_not_seen,
         count_bar=count_bar,
         needs_attn=needs_attn,
         comment=comment,
     )
Ejemplo n.º 5
0
def display_clock(time: timezone.datetime):
    time = time.astimezone(ctz)
    base = int("1F54F", 16)
    hour = time.hour % 12
    if hour == 0:
        hour = 12
    return chr(base + hour)
Ejemplo n.º 6
0
 def generate_webhook_signature(
     self, payload: str, secret: str, timestamp: timezone.datetime = None,
 ) -> str:
     timestamp = timezone.now() if not timestamp else timestamp
     computed_timestamp: int = int(timestamp.timestamp())
     signature: str = compute_webhook_signature(
         "%d.%s" % (computed_timestamp, payload), secret,
     )
     return f"t={computed_timestamp},v1={signature}"
Ejemplo n.º 7
0
Archivo: gcal.py Proyecto: 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
Ejemplo n.º 8
0
 def _species_count_factory(
     count: int,
     user: User = user_base,
     enclosure: Enclosure = enclosure_base,
     species: Species = species_base,
     datetimecounted: datetime = None,
 ) -> SpeciesCount:
     if datetimecounted is None:
         datetimecounted = localtime()
     return SpeciesCount.objects.create(
         datetimecounted=datetimecounted,
         datecounted=datetimecounted.date(),
         species=species,
         user=user,
         enclosure=enclosure,
         count=count,
     )
Ejemplo n.º 9
0
 def _animal_count_factory(
     condition: str,
     datetimecounted: datetime = None,
     comment: str = "",
     animal: Animal = animal_A,
     user: User = user_base,
     enclosure: Enclosure = enclosure_base,
 ) -> AnimalCount:
     if datetimecounted is None:
         datetimecounted = localtime()
     return AnimalCount.objects.create(
         datetimecounted=datetimecounted,
         datecounted=datetimecounted.date(),
         condition=condition,
         comment=comment,
         animal=animal,
         user=user,
         enclosure=enclosure,
     )
Ejemplo n.º 10
0
def _plus_one_calendar_year(start_at: timezone.datetime) -> timezone.datetime:
    return start_at.replace(year=start_at.year + 1)
Ejemplo n.º 11
0
def format_time(time: timezone.datetime):
    return time.astimezone().strftime('%Y-%m-%d %H:%M:%S')
Ejemplo n.º 12
0
def to_timezone_cst(dt: timezone.datetime) -> timezone.datetime:
    delta = timezone.timedelta(hours=8)
    return dt.astimezone(timezone.timezone(delta))
Ejemplo n.º 13
0
def one_year(time: timezone.datetime):
    return time.replace(year=time.year - 1)
Ejemplo n.º 14
0
 def datetime_to_timestamp(datetime: timezone.datetime) -> float:
     """Convert datetime to timestamp"""
     return datetime.timestamp()