Repository: dlr-eoc/ukis-pysat

Issue:
Datetime Object to ESA date
**Is your feature request related to a problem? Please describe.**
We now have the option to create a datetime object from _ESA dates_, it would be nice to also be able to go back. This can be helpful when naming output files.

**Describe the solution you'd like**
Just a simple function to change the format back.


Discussion:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 6e95526..a614feb 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -16,6 +16,11 @@ something was changed
 [master]  (2020-**-**)
 ----------------------
 
+Added
+*****
+- ``file``: added to_ESA_date() function #80
+
+
 [0.6.0]  (2020-08-28)
 ----------------------
 
@@ -42,7 +47,7 @@ Changed
 
 Removed
 *******
-``file``: removed `pack()` and `unpack()` #57
+- ``file``: removed `pack()` and `unpack()` #57
 
 
 [0.5.0]  (2020-07-03)
diff --git a/ukis_pysat/file.py b/ukis_pysat/file.py
index 26e5ad0..9c263e7 100644
--- a/ukis_pysat/file.py
+++ b/ukis_pysat/file.py
@@ -118,6 +118,19 @@ def get_ts_from_sentinel_filename(filename, start_date=True):
             return datetime.strptime(filename[32:47], "%Y%m%dT%H%M%S").replace(tzinfo=timezone.utc)
 
 
+def get_sat_ts_from_datetime(dt: datetime, dformat: str = "%Y%m%dT%H%M%S") -> str:
+    """Get ESA timestamp string (used in their filenames) from datetime object.
+
+    :param dt: datetime.datetime object
+    :param dformat: : str, (default: %Y%m%dT%H%M%S)
+    :return: ESA timestamp as string
+
+    >>> get_sat_ts_from_datetime(datetime(2020, 1, 13, 7, 46, 19, tzinfo=timezone.utc)
+    '20200113T074619'
+    """
+    return dt.strftime(dformat)
+
+
 def get_footprint_from_manifest(xml_path):
     """Return a shapely polygon with footprint of scene, tested for Sentinel-1.
 


Test patch:
diff --git a/tests/test_file.py b/tests/test_file.py
index bcebb27..e2dbe40 100644
--- a/tests/test_file.py
+++ b/tests/test_file.py
@@ -82,6 +82,11 @@ class FileTest(unittest.TestCase):
             datetime(2020, 1, 13, 0, 22, 19, tzinfo=timezone.utc),
         )
 
+    def test_get_ESA_date_from_datetime(self):
+        self.assertEqual(
+            psf.get_sat_ts_from_datetime(datetime(2020, 1, 13, 7, 46, 19, tzinfo=timezone.utc)), "20200113T074619"
+        )
+
     def test_get_footprint_from_manifest(self):
         self.assertEqual(
             psf.get_footprint_from_manifest(path_testfiles.joinpath("manifest.safe")).wkt,