@@ -268,9 +268,9 @@ def now(cls, tz=None):
268268 elif tz is UTC or tz == 'UTC' :
269269 dt = datetime .datetime .utcnow ().replace (tzinfo = UTC )
270270 else :
271+ dt = datetime .datetime .utcnow ().replace (tzinfo = UTC )
271272 tz = cls ._safe_create_datetime_zone (tz )
272-
273- return cls (* cls ._create_datetime (tz ))
273+ dt = tz .convert (dt )
274274
275275 return cls .instance (dt , tz )
276276
@@ -322,43 +322,9 @@ def yesterday(cls, tz=None):
322322 """
323323 return cls .today (tz ).subtract (days = 1 )
324324
325- @classmethod
326- def _create_datetime (cls , tz , year = None , month = None , day = None ,
327- hour = None , minute = None , second = None , microsecond = None ):
328- tzinfo = tz
329-
330- if any ([year is None , month is None , day is None ,
331- hour is None , minute is None , second is None , microsecond is None ]):
332- now = datetime .datetime .utcnow ().replace (tzinfo = UTC )
333- now = tz .convert (now )
334-
335- if year is None :
336- year = now .year
337-
338- if month is None :
339- month = now .month
340-
341- if day is None :
342- day = now .day
343-
344- if hour is None :
345- hour = now .hour
346- minute = now .minute if minute is None else minute
347- second = now .second if second is None else second
348- microsecond = now .microsecond if microsecond is None else microsecond
349- else :
350- minute = 0 if minute is None else minute
351- second = 0 if second is None else second
352- microsecond = 0 if microsecond is None else microsecond
353-
354- tzinfo = now .tzinfo
355-
356- return (year , month , day ,
357- hour , minute , second , microsecond , tzinfo )
358-
359325 @classmethod
360326 def create (cls , year = None , month = None , day = None ,
361- hour = None , minute = None , second = None , microsecond = None ,
327+ hour = 0 , minute = 0 , second = 0 , microsecond = 0 ,
362328 tz = UTC ):
363329 """
364330 Create a new Carbon instance from a specific date and time.
@@ -379,18 +345,30 @@ def create(cls, year=None, month=None, day=None,
379345 """
380346 tz = cls ._safe_create_datetime_zone (tz )
381347
382- dt = datetime .datetime (* cls ._create_datetime (
383- tz , year , month , day , hour , minute , second , microsecond
384- )[:- 1 ])
385- dt = tz .convert (dt , dst_rule = cls ._TRANSITION_RULE )
348+ if any ([year is None , month is None , day is None ]):
349+ now = datetime .datetime .utcnow ().replace (tzinfo = UTC )
350+ now = tz .convert (now , dst_rule = cls ._TRANSITION_RULE )
351+
352+ if year is None :
353+ year = now .year
354+
355+ if month is None :
356+ month = now .month
357+
358+ if day is None :
359+ day = now .day
360+
361+ dt = datetime .datetime (
362+ year , month , day , hour , minute , second , microsecond
363+ )
386364
387- return cls .instance (dt )
365+ return cls .instance (dt , tz )
388366
389367 @classmethod
390368 def create_from_date (cls , year = None , month = None , day = None , tz = 'UTC' ):
391369 """
392370 Create a Pendulum instance from just a date.
393- The time portion is set to now .
371+ The time portion is set to 00:00:00 .
394372
395373 :type year: int
396374 :type month: int
@@ -402,8 +380,8 @@ def create_from_date(cls, year=None, month=None, day=None, tz='UTC'):
402380 return cls .create (year , month , day , tz = tz )
403381
404382 @classmethod
405- def create_from_time (cls , hour = None , minute = None , second = None ,
406- microsecond = None , tz = 'UTC' ):
383+ def create_from_time (cls , hour = 0 , minute = 0 , second = 0 ,
384+ microsecond = 0 , tz = 'UTC' ):
407385 """
408386 Create a Pendulum instance from just a time.
409387 The date portion is set to today.
@@ -2275,10 +2253,10 @@ def _getstate(self):
22752253 )
22762254
22772255 def __setstate__ (self , year , month , day , hour , minute , second , microsecond , tz ):
2278- self ._datetime = datetime . datetime ( self . _create_datetime (
2279- tz , year , month , day ,
2256+ self ._datetime = tz . convert ( datetime . datetime (
2257+ year , month , day ,
22802258 hour , minute , second , microsecond
2281- )[: - 1 ] )
2259+ ))
22822260 self ._tz = tz
22832261
22842262 def __reduce__ (self ):
0 commit comments