Repository: mne-tools/mne-python

Issue:
SNIRF reader can't handle file with MeasurementTime containing milliseconds
### Description of the problem

Can't read .snirf file with `/nirs(i)/metaDataTags/MeasurementTime` in the format `hh:mm:ss.sss`







### Steps to reproduce

```Python
import mne
raw_intensity = mne.io.read_raw_snirf(file, verbose=True).load_data()
```


### Link to data

https://file.io/qgHnp94ioNl7

### Expected results

File should be read without issues since milliseconds should be fine according to the snirf spec (file also passes snirf validator):

![image](https://github.com/mne-tools/mne-python/assets/61238634/e12b2966-1b05-420c-86d1-4607ee357a86)



### Actual results

![image](https://github.com/mne-tools/mne-python/assets/61238634/b59cf336-7229-49ff-8be8-00c6d2238654)

### Additional information

Platform             Windows-10-10.0.19044-SP0
Python               3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 17:59:51) [MSC v.1935 64 bit (AMD64)]
Executable           C:\Users\kdahlslatt\Anaconda3\envs\mne\python.exe
CPU                  Intel64 Family 6 Model 158 Stepping 10, GenuineIntel (12 cores)
Memory               15.7 GB

Core
├☑ mne               1.4.2
├☑ numpy             1.24.3 (MKL 2022.1-Product with 6 threads)
├☑ scipy             1.10.1
├☑ matplotlib        3.7.1 (backend=module://matplotlib_inline.backend_inline)
├☑ pooch             1.7.0
└☑ jinja2            3.1.2

Numerical (optional)
├☑ sklearn           1.2.2
├☑ numba             0.57.0
├☑ nibabel           5.1.0
├☑ nilearn           0.10.1
├☑ dipy              1.7.0
├☑ openmeeg          2.5.6
├☑ pandas            2.0.2
└☐ unavailable       cupy

Visualization (optional)
├☑ pyvista           0.39.1 (OpenGL 4.5.0 - Build 30.0.101.1404 via Intel(R) UHD Graphics 630)
├☑ pyvistaqt         0.0.0
├☑ ipyvtklink        0.2.2
├☑ vtk               9.2.6
├☑ qtpy              2.3.1 (PyQt5=5.15.6)
├☑ pyqtgraph         0.13.3
├☑ mne-qt-browser    0.5.1
└☐ unavailable       ipympl

Ecosystem (optional)
├☑ mne-nirs          0.5.0
└☐ unavailable       mne-bids, mne-features, mne-connectivity, mne-icalabel, mne-bids-pipeline


Discussion:
Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴

@kdarti agreed this is a bug, do you want to try to fix it? I think these lines would need to be changed, probably just by adding another possibility to the list of attempted strings:

https://github.com/mne-tools/mne-python/blob/5608da261cc18f4813c1165baa8a6d5f64a1ea8c/mne/io/snirf/_snirf.py#L421-L434
I'd be happy to try and fix the bug!
@Xiezhibin feel free to give it a shot!

Resolving patch:
diff --git a/mne/io/snirf/_snirf.py b/mne/io/snirf/_snirf.py
--- a/mne/io/snirf/_snirf.py
+++ b/mne/io/snirf/_snirf.py
@@ -419,7 +419,12 @@ def natural_keys(text):
             str_datetime = str_date + str_time
 
             # Several formats have been observed so we try each in turn
-            for dt_code in ["%Y-%m-%d%H:%M:%SZ", "%Y-%m-%d%H:%M:%S"]:
+            for dt_code in [
+                "%Y-%m-%d%H:%M:%SZ",
+                "%Y-%m-%d%H:%M:%S",
+                "%Y-%m-%d%H:%M:%S.%f",
+                "%Y-%m-%d%H:%M:%S.%f%z",
+            ]:
                 try:
                     meas_date = datetime.datetime.strptime(str_datetime, dt_code)
                 except ValueError:


Test patch: