# obspy.io.mseed.util.get_start_and_end_time

`get_start_and_end_time`(file_or_file_object)

  Returns the start and end time of a MiniSEED file or file-like object.

  Parameters: | file_or_file_object (str or file) MiniSEED file name or open file-like object containing a MiniSEED record.
  Returns: | tuple (start time of first record, end time of last record)

  This method will return the start time of the first record and the end time of the last record. Keep in mind that it will not return the correct result if the records in the MiniSEED file do not have a chronological ordering.

  The returned end time is the time of the last data sample and not the time that the last sample covers.

  Example

      >>> from obspy.core.util import get_example_file
      >>> filename = get_example_file(
      ...     "BW.BGLD.__.EHE.D.2008.001.first_10_records")
      >>> get_start_and_end_time(filename)
          (UTCDateTime(2007, 12, 31, 23, 59, 59, 915000),
          UTCDateTime(2008, 1, 1, 0, 0, 20, 510000))

  It also works with an open file pointer. The file pointer itself will not be changed.

      >>> f = open(filename, 'rb')
      >>> get_start_and_end_time(f)
          (UTCDateTime(2007, 12, 31, 23, 59, 59, 915000),
          UTCDateTime(2008, 1, 1, 0, 0, 20, 510000))

  And also with a MiniSEED file stored in a BytesIO

      >>> import io
      >>> file_object = io.BytesIO(f.read())
      >>> get_start_and_end_time(file_object)
          (UTCDateTime(2007, 12, 31, 23, 59, 59, 915000),
          UTCDateTime(2008, 1, 1, 0, 0, 20, 510000))
      >>> file_object.close()

  If the file pointer does not point to the first record, the start time will refer to the record it points to.

      >>> _ = f.seek(512)
      >>> get_start_and_end_time(f)
          (UTCDateTime(2008, 1, 1, 0, 0, 1, 975000),
          UTCDateTime(2008, 1, 1, 0, 0, 20, 510000))

  The same is valid for a file-like object.

      >>> file_object = io.BytesIO(f.read())
      >>> get_start_and_end_time(file_object)
          (UTCDateTime(2008, 1, 1, 0, 0, 1, 975000),
          UTCDateTime(2008, 1, 1, 0, 0, 20, 510000))
      >>> f.close()

### Thank you!

We would like to thank our contributors, whose efforts make this software what it is. These people have helped by writing code and documentation, and by testing. They have created and maintained this product, its associated libraries and applications, our build tools and our web sites.

#### Contributors

- Ackerley, Nick
- Allgeyer, Sebastien
- Ammon, Charles J.
- Antunes, Emanuel
- Arnarsson, Ólafur St.
- Bank, Markus
- Barsch, Robert
- Behr, Yannik
- Bernardi, Fabrizio
- Bernauer, Felix
- Bes de Berc, Maxime
- Beyreuther, Moritz
- Boltz, Shawn
- Bonaimé, Sébastien
- Carothers, Lloyd
- Chamberlain, Calum
- Chambers, Derrick
- Chen, Zhao
- Clark, Adam
- Danecek, Peter
- Egdorf, Sven
- Engels, Fabian
- Ermert, Laura
- Eulenfeld, Tom

- Fabbri, Tommaso
- Falco, Nicholas
- Fee, Jeremy
- Grellier, Clément
- Grunberg, Marc
- Hammer, Conny
- Heimann, Sebastian
- Heiniger, Lukas
- Hope, Gaute
- Igel, Heiner
- Inza, Adolfo
- Isken, Marius
- Ketchum, David
- Koymans, Mathijs
- Kremers, Simon
- Kress, Victor
- Krieger, Lars
- Krischer, Lion
- Kula, Damian
- Käufl, Paul
- Köhler, Andreas
- Lecocq, Thomas
- Leeman, John
- Legovini, Paride

- Lesage, Philippe
- Li, Yulin
- Lomax, Anthony
- Lopes, Rui L.
- MacCarthy, Jonathan
- Maggi, Alessia
- Martin, Henri
- Medlin, Andrew
- Megies, Tobias
- Meschede, Matthias
- Michelini, Alberto
- Miller, Nathaniel C.
- Morgenstern, Bernhard
- Nof, Ran Novitsky
- Panning, Mark P.
- Parker, Tom
- Pestourie, Romain
- Rapagnani, Giovanni
- Reyes, Celso
- Ringler, Adam
- Rothenhäusler, Nicolas
- Russo, Emiliano
- Sales de Andrade, Elliott

- Satriano, Claudio
- Saul, Joachim
- Scheingraber, Chris
- Schneider, Simon
- Sippl, Christian
- Snoke, Arthur
- Stange, Stefan
- Stähler, Simon C.
- Sullivan, Benjamin
- Tian, Dongdong
- Trabant, Chad
- Trani, Luca
- Uieda, Leonardo
- Walker, Andrew
- Walther, Marcus
- Wassermann, Joachim
- Williams, Mark C.
- Winkelman, Andrew
- Zaccarelli, Riccardo
- Zad, Seyed Kasra Hosseini
- Zhu, Lijun
- van Driel, Martin
- van Wijk, Kasper

#### Funds

ObsPy was partially funded by the

- German Science Foundation (DFG) via grant DFG IG 16/9-1
- German Ministry for Education and Research (BMBF), GEOTECHNOLOGIEN grant 03G0646H.
- NERA project (Network of European Research Infrastructures for Earthquake Risk Assessment and Mitigation) under the European Community's Seventh Framework Programme (FP7/2007-2013) grant agreement n° 262330
- Leibniz Institute for Applied Geophysics (LIAG)
- VERCE EU-FP7 project (no. 283543)