@@ -386,54 +386,6 @@ class DeliveryPeriod:
386386 duration : DeliveryDuration
387387 """The length of the delivery period."""
388388
389- def __init__ (
390- self ,
391- start : datetime ,
392- duration : timedelta ,
393- ) -> None :
394- """
395- Initialize the DeliveryPeriod object.
396-
397- Args:
398- start: Start UTC timestamp represents the beginning of the delivery period.
399- duration: The length of the delivery period.
400-
401- Raises:
402- ValueError: If the start timestamp does not have a timezone.
403- or if the duration is not 5, 15, 30, or 60 minutes.
404- """
405- if start .tzinfo is None :
406- raise ValueError ("Start timestamp must have a timezone." )
407- if start .tzinfo != timezone .utc :
408- _logger .warning (
409- "Start timestamp is not in UTC timezone. Converting to UTC."
410- )
411- start = start .astimezone (timezone .utc )
412- self .start = start
413-
414- minutes = duration .total_seconds () / 60
415- match minutes :
416- case 5 :
417- self .duration = DeliveryDuration .MINUTES_5
418- case 15 :
419- self .duration = DeliveryDuration .MINUTES_15
420- case 30 :
421- self .duration = DeliveryDuration .MINUTES_30
422- case 60 :
423- self .duration = DeliveryDuration .MINUTES_60
424- case _:
425- raise ValueError (
426- "Invalid duration value. Duration must be 5, 15, 30, or 60 minutes."
427- )
428-
429- def __hash__ (self ) -> int :
430- """
431- Create hash of the DeliveryPeriod object.
432-
433- Returns:
434- Hash of the DeliveryPeriod object.
435- """
436- return hash ((self .start , self .duration ))
437389
438390 def __eq__ (
439391 self ,
@@ -481,27 +433,10 @@ def from_pb(cls, delivery_period: delivery_duration_pb2.DeliveryPeriod) -> Self:
481433
482434 Returns:
483435 DeliveryPeriod object corresponding to the protobuf message.
484-
485- Raises:
486- ValueError: If the duration is not 5, 15, 30, or 60 minutes.
487436 """
488437 start = delivery_period .start .ToDatetime (tzinfo = timezone .utc )
489438 delivery_duration_enum = DeliveryDuration .from_pb (delivery_period .duration )
490-
491- match delivery_duration_enum :
492- case DeliveryDuration .MINUTES_5 :
493- duration = timedelta (minutes = 5 )
494- case DeliveryDuration .MINUTES_15 :
495- duration = timedelta (minutes = 15 )
496- case DeliveryDuration .MINUTES_30 :
497- duration = timedelta (minutes = 30 )
498- case DeliveryDuration .MINUTES_60 :
499- duration = timedelta (minutes = 60 )
500- case _:
501- raise ValueError (
502- "Invalid duration value. Duration must be 5, 15, 30, or 60 minutes."
503- )
504- return cls (start = start , duration = duration )
439+ return cls (start = start , duration = delivery_duration_enum )
505440
506441 def to_pb (self ) -> delivery_duration_pb2 .DeliveryPeriod :
507442 """Convert a DeliveryPeriod object to protobuf DeliveryPeriod.
0 commit comments