@@ -152,7 +152,14 @@ def _get_libraries(self, date_range):
152
152
153
153
rtn = [TickStoreLibrary (self ._arctic_lib .arctic [library .library ], library .date_range )
154
154
for library in libraries ]
155
- current_start = rtn [- 1 ].date_range .end if rtn else dt (1970 , 1 , 1 , 0 , 0 ) # epoch
155
+
156
+ if rtn :
157
+ current_start = rtn [- 1 ].date_range .end
158
+ elif date_range .end .tzinfo :
159
+ current_start = dt (1970 , 1 , 1 , 0 , 0 , tzinfo = date_range .end .tzinfo )
160
+ else :
161
+ current_start = dt (1970 , 1 , 1 , 0 , 0 )
162
+
156
163
if date_range .end is None or current_start < date_range .end :
157
164
name = self .get_name ()
158
165
db_name , tick_type = name .split ('.' , 1 )
@@ -195,8 +202,20 @@ def _get_library_metadata(self, date_range):
195
202
query = {'$or' : [{'start' : {'$lte' : start }, 'end' : {'$gte' : start }},
196
203
{'start' : {'$gte' : start }, 'end' : {'$lte' : end }},
197
204
{'start' : {'$lte' : end }, 'end' : {'$gte' : end }}]}
198
- return [TickStoreLibrary (res ['library_name' ], DateRange (res ['start' ], res ['end' ], CLOSED_CLOSED ))
199
- for res in self ._collection .find (query ,
200
- projection = {'library_name' : 1 ,
201
- 'start' : 1 , 'end' : 1 },
202
- sort = [('start' , pymongo .ASCENDING )])]
205
+
206
+ cursor = self ._collection .find (query ,
207
+ projection = {'library_name' : 1 , 'start' : 1 , 'end' : 1 },
208
+ sort = [('start' , pymongo .ASCENDING )])
209
+
210
+ results = []
211
+ for res in cursor :
212
+ start = res ['start' ]
213
+ if date_range .start .tzinfo is not None and start .tzinfo is None :
214
+ start = start .replace (tzinfo = mktz ("UTC" )).astimezone (tz = date_range .start .tzinfo )
215
+
216
+ end = res ['end' ]
217
+ if date_range .end .tzinfo is not None and end .tzinfo is None :
218
+ end = end .replace (tzinfo = mktz ("UTC" )).astimezone (tz = date_range .end .tzinfo )
219
+
220
+ results .append (TickStoreLibrary (res ['library_name' ], DateRange (start , end , CLOSED_CLOSED )))
221
+ return results
0 commit comments