File tree 2 files changed +27
-3
lines changed
2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,24 @@ class Timestamp(_Timestamp):
165
165
def asm8 (self ):
166
166
return np.int64(self .value).view(' M8[ns]' )
167
167
168
+ def tz_localize (self , tz ):
169
+ """
170
+ Convert naive Timestamp to local time zone
171
+
172
+ Parameters
173
+ ----------
174
+ tz : pytz.timezone
175
+
176
+ Returns
177
+ -------
178
+ localized : Timestamp
179
+ """
180
+ if self .tzinfo is None :
181
+ # tz naive, localize
182
+ return Timestamp(self .to_pydatetime(), tz = tz)
183
+ else :
184
+ raise Exception (' Cannot localize tz-aware Timestamp' )
185
+
168
186
def tz_convert (self , tz ):
169
187
"""
170
188
Convert Timestamp to another time zone or localize to requested time
@@ -445,12 +463,15 @@ cpdef convert_to_tsobject(object ts, object tz=None):
445
463
# sort of a temporary hack
446
464
if ts.tzinfo is not None :
447
465
ts = tz.normalize(ts)
466
+ obj.value = _pydatetime_to_dts(ts, & obj.dts)
448
467
elif tz is not pytz.utc:
449
468
ts = tz.localize(ts)
450
-
451
- obj.value = _pydatetime_to_dts(ts, & obj.dts)
469
+ obj.value = _pydatetime_to_dts(ts, & obj.dts)
470
+ obj.value -= _delta_to_nanoseconds(ts.tzinfo._utcoffset)
471
+ else :
472
+ # UTC
473
+ obj.value = _pydatetime_to_dts(ts, & obj.dts)
452
474
obj.tzinfo = ts.tzinfo
453
- obj.value -= _delta_to_nanoseconds(obj.tzinfo._utcoffset)
454
475
else :
455
476
obj.value = _pydatetime_to_dts(ts, & obj.dts)
456
477
obj.tzinfo = ts.tzinfo
Original file line number Diff line number Diff line change @@ -1507,6 +1507,9 @@ def test_create_with_tz(self):
1507
1507
1508
1508
self .assertEquals (stamp , rng [1 ])
1509
1509
1510
+ utc_stamp = Timestamp ('3/11/2012 05:00' , tz = 'utc' )
1511
+ self .assertEquals (utc_stamp .hour , 5 )
1512
+
1510
1513
def test_tz_convert_localize (self ):
1511
1514
stamp = Timestamp ('3/11/2012 04:00' )
1512
1515
You can’t perform that action at this time.
0 commit comments