@@ -164,7 +164,9 @@ def __new__(cls, year, month, day,
164164
165165 def __init__ (self , year , month , day ,
166166 hour = 0 , minute = 0 , second = 0 , microsecond = 0 ,
167- tzinfo = 'UTC' ):
167+ tzinfo = UTC ):
168+ self .__float_timestamp = None
169+
168170 # If a TimezoneInfo is passed we do not convert:
169171 if isinstance (tzinfo , TimezoneInfo ):
170172 self ._tz = tzinfo .tz
@@ -183,7 +185,7 @@ def __init__(self, year, month, day,
183185 ))
184186
185187 @classmethod
186- def instance (cls , dt , tz = ' UTC' ):
188+ def instance (cls , dt , tz = UTC ):
187189 """
188190 Create a Carbon instance from a datetime one.
189191
@@ -197,7 +199,6 @@ def instance(cls, dt, tz='UTC'):
197199 """
198200 tz = dt .tzinfo or tz
199201
200- # Bypassing default constructor
201202 return cls (
202203 dt .year , dt .month , dt .day ,
203204 dt .hour , dt .minute , dt .second , dt .microsecond ,
@@ -349,7 +350,7 @@ def _create_datetime(cls, tz, year=None, month=None, day=None,
349350 @classmethod
350351 def create (cls , year = None , month = None , day = None ,
351352 hour = None , minute = None , second = None , microsecond = None ,
352- tz = ' UTC' ):
353+ tz = UTC ):
353354 """
354355 Create a new Carbon instance from a specific date and time.
355356
@@ -432,23 +433,23 @@ def create_from_format(cls, time, fmt, tz=UTC):
432433 return cls .instance (dt , tz )
433434
434435 @classmethod
435- def create_from_timestamp (cls , timestamp , tz = ' UTC' ):
436+ def create_from_timestamp (cls , timestamp , tz = UTC ):
436437 """
437438 Create a Pendulum instance from a timestamp.
438439
439440 :param timestamp: The timestamp
440441 :type timestamp: int or float
441442
442443 :param tz: The timezone
443- :type tz: tzinfo or str or int or None
444+ :type tz: TimezoneInfo or str or int or None
444445
445446 :rtype: Pendulum
446447 """
447448 dt = datetime .datetime .utcfromtimestamp (timestamp ).replace (tzinfo = UTC )
449+ if tz is not UTC and tz != 'UTC' :
450+ tz = cls ._safe_create_datetime_zone (tz )
448451
449- tz = cls ._safe_create_datetime_zone (tz )
450-
451- dt = tz .convert (dt )
452+ dt = tz .convert (dt )
452453
453454 return cls .instance (dt )
454455
@@ -552,18 +553,23 @@ def timestamp(self):
552553
553554 @property
554555 def float_timestamp (self ):
556+ if self .__float_timestamp is not None :
557+ return self .__float_timestamp
558+
555559 # If Python > 3.3 we use the native function
556560 # else we emulate it
557561 if PY33 :
558- return self ._datetime .timestamp ()
559-
560- if self ._datetime . tzinfo is None :
561- return _time . mktime ( (self .year , self .month , self .day ,
562- self .hour , self .minute , self .second ,
563- - 1 , - 1 , - 1 )) + self .microsecond / 1e6
562+ self . __float_timestamp = self ._datetime .timestamp ()
563+ elif self . _datetime . tzinfo is None :
564+ self .__float_timestamp = _time . mktime (
565+ (self .year , self .month , self .day ,
566+ self .hour , self .minute , self .second ,
567+ - 1 , - 1 , - 1 )) + self .microsecond / 1e6
564568
565569 else :
566- return (self ._datetime - self ._EPOCH ).total_seconds ()
570+ self .__float_timestamp = (self ._datetime - self ._EPOCH ).total_seconds ()
571+
572+ return self .__float_timestamp
567573
568574 @property
569575 def week_of_month (self ):
@@ -712,7 +718,7 @@ def in_timezone(self, tz):
712718 """
713719 tz = self ._safe_create_datetime_zone (tz )
714720
715- return self . instance ( tz .convert (self . _datetime ) )
721+ return tz .convert (self )
716722
717723 def in_tz (self , tz ):
718724 """
0 commit comments