44
55import calendar
66import datetime
7+ import warnings
78
89from .date import Date
910from .time import Time
@@ -612,7 +613,7 @@ def date(self):
612613 def time (self ):
613614 return Time (self .hour , self .minute , self .second , self .microsecond )
614615
615- def with_date (self , year , month , day ):
616+ def on (self , year , month , day ):
616617 """
617618 Returns a new instance with the current date set to a different date.
618619
@@ -627,13 +628,34 @@ def with_date(self, year, month, day):
627628
628629 :rtype: Pendulum
629630 """
630- dt = self .replace (
631+ return self .replace (
631632 year = int (year ), month = int (month ), day = int (day )
632633 )
633634
634- return self ._tz .convert (dt )
635+ def with_date (self , year , month , day ):
636+ """
637+ Returns a new instance with the current date set to a different date.
635638
636- def with_time (self , hour , minute , second , microsecond = 0 ):
639+ :param year: The year
640+ :type year: int
641+
642+ :param month: The month
643+ :type month: int
644+
645+ :param day: The day
646+ :type day: int
647+
648+ :rtype: Pendulum
649+ """
650+ warnings .warn (
651+ 'with_date() is deprecated. Use on() instead.' ,
652+ category = DeprecationWarning ,
653+ stacklevel = 2
654+ )
655+
656+ return self .on (year , month , day )
657+
658+ def at (self , hour , minute , second , microsecond = 0 ):
637659 """
638660 Returns a new instance with the current time to a different time.
639661
@@ -651,13 +673,36 @@ def with_time(self, hour, minute, second, microsecond=0):
651673
652674 :rtype: Pendulum
653675 """
654- dt = self ._datetime .replace (
655- hour = int (hour ), minute = int (minute ), second = int (second ),
656- microsecond = microsecond ,
657- tzinfo = None
676+ return self .replace (
677+ hour = hour , minute = minute , second = second ,
678+ microsecond = microsecond
679+ )
680+
681+ def with_time (self , hour , minute , second , microsecond = 0 ):
682+ """
683+ Returns a new instance with the current time set to a different time.
684+
685+ :param hour: The hour
686+ :type hour: int
687+
688+ :param minute: The minute
689+ :type minute: int
690+
691+ :param second: The second
692+ :type second: int
693+
694+ :param microsecond: The microsecond
695+ :type microsecond: int
696+
697+ :rtype: Pendulum
698+ """
699+ warnings .warn (
700+ 'with_time() is deprecated. Use at() instead.' ,
701+ category = DeprecationWarning ,
702+ stacklevel = 2
658703 )
659704
660- return self .instance ( dt , self . _tz )
705+ return self .at ( hour , minute , second , microsecond )
661706
662707 def with_date_time (self , year , month , day , hour , minute , second , microsecond = 0 ):
663708 """
@@ -672,15 +717,12 @@ def with_date_time(self, year, month, day, hour, minute, second, microsecond=0):
672717
673718 :rtype: Pendulum
674719 """
675- dt = self . _datetime .replace (
720+ return self .replace (
676721 year = year , month = month , day = day ,
677- hour = int (hour ), minute = int (minute ), second = int (second ),
678- microsecond = microsecond ,
679- tzinfo = None
722+ hour = hour , minute = minute , second = second ,
723+ microsecond = microsecond
680724 )
681725
682- return self .instance (dt , self ._tz )
683-
684726 def with_time_from_string (self , time ):
685727 """
686728 Returns a new instance with the time set by time string.
@@ -692,11 +734,11 @@ def with_time_from_string(self, time):
692734 """
693735 time = time .split (':' )
694736
695- hour = time [0 ]
696- minute = time [1 ] if len (time ) > 1 else 0
697- second = time [2 ] if len (time ) > 2 else 0
737+ hour = int ( time [0 ])
738+ minute = int ( time [1 ]) if len (time ) > 1 else 0
739+ second = int ( time [2 ]) if len (time ) > 2 else 0
698740
699- return self .with_time (hour , minute , second )
741+ return self .at (hour , minute , second )
700742
701743 def in_timezone (self , tz ):
702744 """
@@ -1425,15 +1467,15 @@ def _start_of_day(self):
14251467
14261468 :rtype: Pendulum
14271469 """
1428- return self .with_time (0 , 0 , 0 )
1470+ return self .at (0 , 0 , 0 )
14291471
14301472 def _end_of_day (self ):
14311473 """
14321474 Reset the time to 23:59:59.999999
14331475
14341476 :rtype: Pendulum
14351477 """
1436- return self .with_time (23 , 59 , 59 , 999999 )
1478+ return self .at (23 , 59 , 59 , 999999 )
14371479
14381480 def _start_of_month (self ):
14391481 """
@@ -1753,7 +1795,7 @@ def _first_of_quarter(self, day_of_week=None):
17531795
17541796 :rtype: Pendulum
17551797 """
1756- return self .with_date (self .year , self .quarter * 3 - 2 , 1 ).first_of ('month' , day_of_week )
1798+ return self .on (self .year , self .quarter * 3 - 2 , 1 ).first_of ('month' , day_of_week )
17571799
17581800 def _last_of_quarter (self , day_of_week = None ):
17591801 """
@@ -1766,7 +1808,7 @@ def _last_of_quarter(self, day_of_week=None):
17661808
17671809 :rtype: Pendulum
17681810 """
1769- return self .with_date (self .year , self .quarter * 3 , 1 ).last_of ('month' , day_of_week )
1811+ return self .on (self .year , self .quarter * 3 , 1 ).last_of ('month' , day_of_week )
17701812
17711813 def _nth_of_quarter (self , nth , day_of_week ):
17721814 """
@@ -1795,7 +1837,7 @@ def _nth_of_quarter(self, nth, day_of_week):
17951837 if last_month < dt .month or year != dt .year :
17961838 return False
17971839
1798- return self .with_date (self .year , dt .month , dt .day ).start_of ('day' )
1840+ return self .on (self .year , dt .month , dt .day ).start_of ('day' )
17991841
18001842 def _first_of_year (self , day_of_week = None ):
18011843 """
@@ -1848,7 +1890,7 @@ def _nth_of_year(self, nth, day_of_week):
18481890 if year != dt .year :
18491891 return False
18501892
1851- return self .with_date (self .year , dt .month , dt .day ).start_of ('day' )
1893+ return self .on (self .year , dt .month , dt .day ).start_of ('day' )
18521894
18531895 def average (self , dt = None ):
18541896 """
@@ -1939,7 +1981,8 @@ def utctimetuple(self):
19391981 return self ._datetime .utctimetuple ()
19401982
19411983 def replace (self , year = None , month = None , day = None , hour = None ,
1942- minute = None , second = None , microsecond = None , tzinfo = True ):
1984+ minute = None , second = None , microsecond = None , tzinfo = True ,
1985+ fold = None ):
19431986 year = year if year is not None else self ._year
19441987 month = month if month is not None else self ._month
19451988 day = day if day is not None else self ._day
@@ -1952,14 +1995,14 @@ def replace(self, year=None, month=None, day=None, hour=None,
19521995 if tzinfo is not None and tzinfo is not True :
19531996 tzinfo = self ._safe_create_datetime_zone (tzinfo )
19541997 elif tzinfo is None :
1955- tzinfo = tzinfo
1998+ tzinfo = UTC
19561999 else :
1957- tzinfo = self ._tzinfo
2000+ tzinfo = self ._tzinfo . tz
19582001
1959- return self .instance (
1960- self . _datetime . replace ( year = year , month = month , day = day ,
1961- hour = hour , minute = minute , second = second ,
1962- microsecond = microsecond , tzinfo = tzinfo )
2002+ return self .__class__ (
2003+ year , month , day ,
2004+ hour , minute , second , microsecond ,
2005+ tzinfo = tzinfo , fold = fold
19632006 )
19642007
19652008 def astimezone (self , tz = None ):
0 commit comments