from datetime import datetime, timedelta, timezone class Booking: def __init__( self, bookingId, startDate, endDate, bookableProductId, linkedProductId, isAvailable=False, **kwargs, ): self.booking_id = bookingId self.start = datetime.strptime(startDate, "%Y-%m-%dT%H:%M:%S.%fZ").replace( tzinfo=timezone.utc ) self.end = datetime.strptime(endDate, "%Y-%m-%dT%H:%M:%S.%fZ").replace( tzinfo=timezone.utc ) self.bookable_product_id = bookableProductId self.linked_product_id = linkedProductId self.available = isAvailable self.booking_dict = kwargs @property def start_stamp(self): ## Get string representation of the timestamp in GMT +2 with only Day of week and month, hour and minute gmt_plus_2 = timezone(timedelta(hours=2)) return self.start.astimezone(gmt_plus_2).strftime("%A %d %B %H:%M") @property def end_stamp(self): gmt_plus_2 = timezone(timedelta(hours=2)) return self.start.astimezone(gmt_plus_2).strftime("%A %d %B %H:%M") def __str__(self): return ( f"Booking(booking_id={self.booking_id}, start={self.start}, end={self.end})" ) def __eq__(self, other): if isinstance(other, Booking): return ( self.booking_id == other.booking_id and self.start == other.start and self.end == other.end ) return False def __repr__(self) -> str: return self.__str__() def __hash__(self): return hash((self.booking_id, self.start, self.end)) def time_left_to_booking(self, current_date): current_datetime = datetime.strptime(current_date, "%Y-%m-%dT%H:%M:%S.%fZ") time_left = self.start - current_datetime if time_left.total_seconds() > 0: return time_left else: return timedelta(0) # No time left if the booking has already started