codecov-commenter: # [Codecov](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/43?src=pr&el=h1) Report
> Merging [#43](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/43?src=pr&el=desc) into [master](https://codecov.io/gh/dlr-eoc/ukis-pysat/commit/9da685ab9d4644ddb0b7a7fc0c864fd96f642d98&el=desc) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/43/graphs/tree.svg?width=650&height=150&src=pr&token=6LYPGRGMXV)](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/43?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master      #43      +/-   ##
==========================================
+ Coverage   93.46%   93.48%   +0.01%     
==========================================
  Files           8        8              
  Lines         673      675       +2     
==========================================
+ Hits          629      631       +2     
  Misses         44       44              
```

| Flag | Coverage Δ | |
|---|---|---|
| #unittests | `93.48% <100.00%> (+0.01%)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/43?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [tests/test\_file.py](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/43/diff?src=pr&el=tree#diff-dGVzdHMvdGVzdF9maWxlLnB5) | `97.91% <100.00%> (+0.04%)` | :arrow_up: |
| [ukis\_pysat/file.py](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/43/diff?src=pr&el=tree#diff-dWtpc19weXNhdC9maWxlLnB5) | `94.33% <100.00%> (+0.05%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/43?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/43?src=pr&el=footer). Last update [9da685a...0daa85c](https://codecov.io/gh/dlr-eoc/ukis-pysat/pull/43?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 0fb8f90..5dc2efe 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -13,10 +13,14 @@ Changed
 ~~~~~~~
 something was changed
 
-[master]  (2020-XX-XX)
+[master]  (2020-06-16)
 ----------------------
 
-[master]  (2020-05-06)
+Fixed
+*****
+- ``file.get_ts_from_sentinel_filename()``: Return datetime.datetime objects instead of timestamp strings #42
+
+[0.4.0]  (2020-06-05)
 ----------------------
 
 Added
diff --git a/ukis_pysat/file.py b/ukis_pysat/file.py
index 1c40e3e..046c57e 100644
--- a/ukis_pysat/file.py
+++ b/ukis_pysat/file.py
@@ -7,6 +7,7 @@ import shutil
 import tempfile
 import xml.etree.ElementTree as ET
 import zipfile
+from datetime import datetime, timezone
 
 
 def env_get(key):
@@ -110,35 +111,35 @@ def get_polarization_from_s1_filename(filename, dual=False):
 
 def get_ts_from_sentinel_filename(filename, start_date=True):
     """Get timestamp from the filename of a Sentinel scene, according to naming conventions.
-    Currently works for S1, S2 (generated after the 6th of December, 2016) & S3.
+    Currently works for S1, S2 & S3.
 
     :param  filename: top-level SENTINEL product folder or file name
     :param start_date: boolean (default: True), False is Stop Date, optional
-    :return: str
+    :return: datetime.datetime object with timezone information
 
     >>> get_ts_from_sentinel_filename("S1M_BB_TTTR_LFPP_20200113T074619_YYYYMMDDTHHMMSS_OOOOOO_DDDDDD_CCCC.SAFE.zip")
-    '20200113T074619'
+    datetime.datetime(2020, 1, 13, 7, 46, 19, tzinfo=datetime.timezone.utc)
     >>> get_ts_from_sentinel_filename("S1M_BB_TTTR_LFPP_YYYYMMDDTHHMMSS_20200113T002219_OOOOOO_DDDDDD_CCCC.SAFE.zip", False)
-    '20200113T002219'
-    >>> get_ts_from_sentinel_filename("S3M_OL_L_TTT____yyyymmddThhmmss_YYYYMMDDTHHMMSS_YYYYMMDDTHHMMSS_i_GGG_c.SEN3")
-    'yyyymmddThhmmss'
-    >>> get_ts_from_sentinel_filename("S3M_OL_L_TTTTTT_yyyymmddThhmmss_YYYYMMDDTHHMMSS_YYYYMMDDTHHMMSS_i_GGG_c.SEN3", False)
-    'YYYYMMDDTHHMMSS'
-    >>> get_ts_from_sentinel_filename("S2AM_MSIXXX_YYYYMMDDHHMMSS_Nxxyy_ROOO_Txxxxx_<Product Discriminator>.SAFE")
-    'YYYYMMDDHHMMSS'
+    datetime.datetime(2020, 1, 13, 0, 22, 19, tzinfo=datetime.timezone.utc)
+    >>> get_ts_from_sentinel_filename("S3M_OL_L_TTT____20200113T074619_YYYYMMDDTHHMMSS_YYYYMMDDTHHMMSS_i_GGG_c.SEN3")
+    datetime.datetime(2020, 1, 13, 7, 46, 19, tzinfo=datetime.timezone.utc)
+    >>> get_ts_from_sentinel_filename("S3M_OL_L_TTTTTT_yyyymmddThhmmss_20200113T074619_YYYYMMDDTHHMMSS_i_GGG_c.SEN3", False)
+    datetime.datetime(2020, 1, 13, 7, 46, 19, tzinfo=datetime.timezone.utc)
+    >>> get_ts_from_sentinel_filename("S2AM_MSIXXX_20200113T074619_Nxxyy_ROOO_Txxxxx_<Product Discriminator>.SAFE")
+    datetime.datetime(2020, 1, 13, 7, 46, 19, tzinfo=datetime.timezone.utc)
     """
     if filename.startswith("S2"):
-        return filename.split("_")[2]
+        return datetime.strptime(filename.split("_")[2], "%Y%m%dT%H%M%S").replace(tzinfo=timezone.utc)
     elif filename.startswith("S1"):
         if start_date:
-            return filename.split("_")[4]
+            return datetime.strptime(filename.split("_")[4], "%Y%m%dT%H%M%S").replace(tzinfo=timezone.utc)
         else:
-            return filename.split("_")[5]
+            return datetime.strptime(filename.split("_")[5], "%Y%m%dT%H%M%S").replace(tzinfo=timezone.utc)
     else:
         if start_date:
-            return filename[16:31]
+            return datetime.strptime(filename[16:31], "%Y%m%dT%H%M%S").replace(tzinfo=timezone.utc)
         else:
-            return filename[32:47]
+            return datetime.strptime(filename[32:47], "%Y%m%dT%H%M%S").replace(tzinfo=timezone.utc)
 
 
 def get_footprint_from_manifest(xml_path):

`get_ts_from_sentinel_filename()` does not return a defined date format
**Describe the bug**
`get_ts_from_sentinel_filename()` does not return a defined date format, but just a substring of the filename. It would be more useful to return something which is readable for common parsers. I would even expect this to happen and therefore label this as _bug_.

**Expected behavior**
Return a timestamp in ISO 8601 `YYYY-MM-DD`, e.g. with [`isoformat()`](https://docs.python.org/3/library/datetime.html#datetime.date.isoformat)

diff --git a/tests/test_file.py b/tests/test_file.py
index 9060aae..0aa2520 100644
--- a/tests/test_file.py
+++ b/tests/test_file.py
@@ -1,6 +1,8 @@
 import os
 import shutil
 import unittest
+from datetime import datetime, timezone
+
 import ukis_pysat.file as psf
 
 path_testfiles = os.path.join(os.path.dirname(__file__), "testfiles")
@@ -60,33 +62,33 @@ class FileTest(unittest.TestCase):
     def test_get_ts_from_sentinel_filename(self):
         self.assertEqual(
             psf.get_ts_from_sentinel_filename(
-                "S3M_OL_L_TTT____yyyymmddThhmmss_YYYYMMDDTHHMMSS_YYYYMMDDTHHMMSS_i_GGG_c.SEN3"
+                "S3M_OL_L_TTT____20200113T002219_YYYYMMDDTHHMMSS_YYYYMMDDTHHMMSS_i_GGG_c.SEN3"
             ),
-            "yyyymmddThhmmss",
+            datetime(2020, 1, 13, 0, 22, 19, tzinfo=timezone.utc),
         )
         self.assertEqual(
             psf.get_ts_from_sentinel_filename(
                 "S1M_BB_TTTR_LFPP_YYYYMMDDTHHMMSS_20200113T002219_OOOOOO_DDDDDD_CCCC.SAFE.zip", False,
             ),
-            "20200113T002219",
+            datetime(2020, 1, 13, 0, 22, 19, tzinfo=timezone.utc),
         )
         self.assertEqual(
             psf.get_ts_from_sentinel_filename(
                 "S1M_BB_TTTR_LFPP_20200113T074619_YYYYMMDDTHHMMSS_OOOOOO_DDDDDD_CCCC.SAFE.zip"
             ),
-            "20200113T074619",
+            datetime(2020, 1, 13, 7, 46, 19, tzinfo=timezone.utc),
         )
         self.assertEqual(
             psf.get_ts_from_sentinel_filename(
-                "S2AM_MSIXXX_YYYYMMDDHHMMSS_Nxxyy_ROOO_Txxxxx_<Product Discriminator>.SAFE"
+                "S2AM_MSIXXX_20200113T002219_Nxxyy_ROOO_Txxxxx_<Product Discriminator>.SAFE"
             ),
-            "YYYYMMDDHHMMSS",
+            datetime(2020, 1, 13, 0, 22, 19, tzinfo=timezone.utc),
         )
         self.assertEqual(
             psf.get_ts_from_sentinel_filename(
-                "S3M_OL_L_TTTTTT_yyyymmddThhmmss_YYYYMMDDTHHMMSS_YYYYMMDDTHHMMSS_i_GGG_c.SEN3", False
+                "S3M_OL_L_TTTTTT_yyyymmddThhmmss_20200113T002219_YYYYMMDDTHHMMSS_i_GGG_c.SEN3", False
             ),
-            "YYYYMMDDTHHMMSS",
+            datetime(2020, 1, 13, 0, 22, 19, tzinfo=timezone.utc),
         )
 
     def test_get_footprint_from_manifest(self):

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-xdist pytest-mock pytest-asyncio pytest
apt-get update apt-get install -y gcc
3.7
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
affine==2.4.0
alabaster==0.7.13
appdirs==1.4.4
attrs==24.2.0
Babel==2.14.0
certifi @ file:///croot/certifi_1671487769961/work/certifi
chardet==3.0.4
click==7.1.2
click-plugins==1.1.1
cligj==0.7.2
coverage==7.2.7
dask==2.14.0
decopatch==1.4.10
docutils==0.19
exceptiongroup==1.2.2
execnet==2.0.2
Fiona==1.8.22
geographiclib==2.0
geojson==3.2.0
geomet==1.1.0
geopy==2.4.1
html2text==2020.1.16
idna==2.10
imagesize==1.4.1
importlib-metadata==6.7.0
iniconfig==2.0.0
Jinja2==3.1.6
landsatxplore==0.6
makefun==1.15.6
MarkupSafe==2.1.5
munch==4.0.0
numpy==1.18.5
packaging==24.0
pandas==1.0.5
Pillow==7.1.2
pluggy==1.2.0
pyfields==1.1.5
Pygments==2.17.2
pylandsat==0.4
pyparsing==3.1.4
pyproj==2.6.1.post1
pytest==7.4.4
pytest-asyncio==0.21.2
pytest-cov==4.1.0
pytest-mock==3.11.1
pytest-xdist==3.5.0
python-dateutil==2.8.2
pytz==2025.2
rasterio==1.1.8
requests==2.23.0
rio-mucho==1.0.0
rio-toa==0.3.0
sentinelsat==0.14
Shapely==1.7.1
six==1.17.0
snowballstemmer==2.2.0
snuggs==1.4.7
Sphinx==5.3.0
sphinx-rtd-theme==2.0.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
tomli==2.0.1
toolz==0.12.1
tqdm==4.67.1
typing_extensions==4.7.1
-e git+https://github.com/dlr-eoc/ukis-pysat.git@9da685ab9d4644ddb0b7a7fc0c864fd96f642d98#egg=ukis_pysat
urllib3==1.25.11
utm==0.5.0
valid8==5.1.2
zipp==3.15.0

name: ukis-pysat
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - affine==2.4.0
      - alabaster==0.7.13
      - appdirs==1.4.4
      - attrs==24.2.0
      - babel==2.14.0
      - chardet==3.0.4
      - click==7.1.2
      - click-plugins==1.1.1
      - cligj==0.7.2
      - coverage==7.2.7
      - dask==2.14.0
      - decopatch==1.4.10
      - docutils==0.19
      - exceptiongroup==1.2.2
      - execnet==2.0.2
      - fiona==1.8.22
      - geographiclib==2.0
      - geojson==3.2.0
      - geomet==1.1.0
      - geopy==2.4.1
      - html2text==2020.1.16
      - idna==2.10
      - imagesize==1.4.1
      - importlib-metadata==6.7.0
      - iniconfig==2.0.0
      - jinja2==3.1.6
      - landsatxplore==0.6
      - makefun==1.15.6
      - markupsafe==2.1.5
      - munch==4.0.0
      - numpy==1.18.5
      - packaging==24.0
      - pandas==1.0.5
      - pillow==7.1.2
      - pluggy==1.2.0
      - pyfields==1.1.5
      - pygments==2.17.2
      - pylandsat==0.4
      - pyparsing==3.1.4
      - pyproj==2.6.1.post1
      - pytest==7.4.4
      - pytest-asyncio==0.21.2
      - pytest-cov==4.1.0
      - pytest-mock==3.11.1
      - pytest-xdist==3.5.0
      - python-dateutil==2.8.2
      - pytz==2025.2
      - rasterio==1.1.8
      - requests==2.23.0
      - rio-mucho==1.0.0
      - rio-toa==0.3.0
      - sentinelsat==0.14
      - shapely==1.7.1
      - six==1.17.0
      - snowballstemmer==2.2.0
      - snuggs==1.4.7
      - sphinx==5.3.0
      - sphinx-rtd-theme==2.0.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jquery==4.1
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - tomli==2.0.1
      - toolz==0.12.1
      - tqdm==4.67.1
      - typing-extensions==4.7.1
      - urllib3==1.25.11
      - utm==0.5.0
      - valid8==5.1.2
      - zipp==3.15.0
prefix: /opt/conda/envs/ukis-pysat

tests/test_file.py::FileTest::test_get_ts_from_sentinel_filename
tests/test_file.py::FileTest::test_env tests/test_file.py::FileTest::test_get_footprint_from_manifest tests/test_file.py::FileTest::test_get_ipf_from_manifest tests/test_file.py::FileTest::test_get_origin_from_manifest tests/test_file.py::FileTest::test_get_pixel_spacing tests/test_file.py::FileTest::test_get_polarization_from_s1_filename tests/test_file.py::FileTest::test_get_proj_string tests/test_file.py::FileTest::test_get_sentinel_scene_from_dir tests/test_file.py::FileTest::test_zip
CHANGELOG.rst ukis_pysat/file.py
CHANGELOG.rst ukis_pysat/file.py