@@ -59,7 +59,7 @@ def __repr__(self):
5959 if num_segments > 1 :
6060 samples_per_segment = [self .get_num_samples (segment_index ) for segment_index in range (num_segments )]
6161 memory_per_segment_bytes = (self .get_memory_size (segment_index ) for segment_index in range (num_segments ))
62- durations = [self .get_duration (segment_index ) for segment_index in range (num_segments )]
62+ durations = [self .get_duration (segment_index , use_times = False ) for segment_index in range (num_segments )]
6363
6464 samples_per_segment_formated = [f"{ samples :,} " for samples in samples_per_segment ]
6565 durations_per_segment_formated = [convert_seconds_to_str (d ) for d in durations ]
@@ -95,7 +95,7 @@ def _repr_header(self):
9595 dtype = self .get_dtype ()
9696
9797 total_samples = self .get_total_samples ()
98- total_duration = self .get_total_duration ()
98+ total_duration = self .get_total_duration (use_times = False )
9999 total_memory_size = self .get_total_memory_size ()
100100
101101 sf_hz = self .get_sampling_frequency ()
@@ -216,7 +216,7 @@ def get_total_samples(self) -> int:
216216
217217 return sum (samples_per_segment )
218218
219- def get_duration (self , segment_index = None ) -> float :
219+ def get_duration (self , segment_index = None , use_times = True ) -> float :
220220 """
221221 Returns the duration in seconds.
222222
@@ -226,6 +226,9 @@ def get_duration(self, segment_index=None) -> float:
226226 The sample index to retrieve the duration for.
227227 For multi-segment objects, it is required, default: None
228228 With single segment recording returns the duration of the single segment
229+ use_times : bool, default: True
230+ If True, the duration is calculated using the time vector if available.
231+ If False, the duration is calculated using the number of samples and the sampling frequency.
229232
230233 Returns
231234 -------
@@ -234,7 +237,7 @@ def get_duration(self, segment_index=None) -> float:
234237 """
235238 segment_index = self ._check_segment_index (segment_index )
236239
237- if self .has_time_vector (segment_index ):
240+ if self .has_time_vector (segment_index ) and use_times :
238241 times = self .get_times (segment_index )
239242 segment_duration = times [- 1 ] - times [0 ] + (1 / self .get_sampling_frequency ())
240243 else :
@@ -243,16 +246,24 @@ def get_duration(self, segment_index=None) -> float:
243246
244247 return segment_duration
245248
246- def get_total_duration (self ) -> float :
249+ def get_total_duration (self , use_times = True ) -> float :
247250 """
248251 Returns the total duration in seconds
249252
253+ Parameters
254+ ----------
255+ use_times : bool, default: True
256+ If True, the duration is calculated using the time vector if available.
257+ If False, the duration is calculated using the number of samples and the sampling frequency.
258+
250259 Returns
251260 -------
252261 float
253262 The duration in seconds
254263 """
255- duration = sum ([self .get_duration (idx ) for idx in range (self .get_num_segments ())])
264+ duration = sum (
265+ [self .get_duration (segment_index , use_times ) for segment_index in range (self .get_num_segments ())]
266+ )
256267 return duration
257268
258269 def get_memory_size (self , segment_index = None ) -> int :
0 commit comments