Skip to content

Fix datetime assume UTC allow ranges - #31

Merged
Alexander-Barth merged 8 commits into
JuliaClimate:mainfrom
danlooo:fix-date-format
Jul 22, 2026
Merged

Alexander-Barth merged 8 commits into
JuliaClimate:mainfrom
danlooo:fix-date-format

Conversation

@danlooo

@danlooo danlooo commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

This PR aims to fix the error of parsing datetime e.g. at CDSE. Consider the README example:

using STAC, Dates

collections = ["sentinel-2-l1c"]
time_range = (DateTime(2026,2,9,10,20), DateTime(2026,2,9,10,30))
lon_range = (0, 20)  # west, east
lat_range = (32, 45)  # south, north

catalog = STAC.Catalog("https://stac.dataspace.copernicus.eu/v1/")

search_results = collect(search(catalog, collections, lon_range, lat_range, time_range))

returns error

search_results = collect(search(catalog, collections, lon_range, lat_range, time_range))
77-element Vector{STAC.Item}:
Error showing value of type Vector{STAC.Item}:

SYSTEM (REPL): showing an error caused an error
ERROR: 1-element ExceptionStack:
MethodError: no method matching parseDT(::Type{DateTime}, ::String)
The function `parseDT` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  parseDT(::Type{Tuple}, ::Any)
   @ CFTime ~/.julia/packages/CFTime/5SQZS/src/conversions.jl:106

According to STAC Spec 1.1, acquisition time of STAC items is mainly stored in filed datetime, SHOULD be in UTC, and may be an interval instead from start_datetime to end_datetime.

Therefore, I used Dates.dateformat"yyyy-mm-ddTHH:MM:SS.sZ", also tried start of datetime range, and kept returning nothing otherwise.

@codecov

codecov Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.72727% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.00%. Comparing base (6a7f562) to head (5f1f39f).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
src/item.jl 72.72% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #31      +/-   ##
==========================================
- Coverage   75.77%   75.00%   -0.78%     
==========================================
  Files           9        9              
  Lines         322      336      +14     
==========================================
+ Hits          244      252       +8     
- Misses         78       84       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Alexander-Barth

Alexander-Barth commented Jul 20, 2026 •

Copy link
Copy Markdown
Member

Thanks a lot for the PR! (I removed CFTime.parseDT but I did not remember that it was used here)

Concerning the start_datetime and end_datetime: would it be better to return a tuple with both (rather than the first)? The function is already now (somewhat) type unstable (Union{DateTime,Nothing}).

Alternatively, there could also be the methods start_datetime(item::Item) and end_datetime(item::Item) (and DateTime would just be nothing if there is a range) ?

Maybe we can have a function like tryparse_utc, in case we want to add also the handle the suffix "+00:00" for UTC.

function tryparse_utc(s) 
    try
        return DateTime(s, Dates.dateformat"yyyy-mm-ddTHH:MM:SS.sZ")
    catch
        return nothing
    end
end

@danlooo danlooo left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is called DateTime(item::Item) thus I think it would be confusing to also return a tuple of time span. There is also STAC extension timestamps defining the entire life cycle from capture to publishing, motivating new calls like get_datetime(item, :published). How about having the general method get_datetime and maybe add the exposure duration to the show method if a range is present?

@danlooo
danlooo marked this pull request as draft July 21, 2026 09:43
@danlooo
danlooo marked this pull request as ready for review July 21, 2026 12:37
@Alexander-Barth

Copy link
Copy Markdown
Member

Thanks a lot ! Would you be ok to call the function datetime(item, symbol) instead of get_datetime(item, symbol).
get_foo/set_foo is quite often used in C++ and Java, but not that much in julia. We have already several method called title, description, keywords, doi... that get the corresponding info with the prefix get_.

@Alexander-Barth

Copy link
Copy Markdown
Member

This is great, thank you!

@Alexander-Barth
Alexander-Barth merged commit 03c820b into JuliaClimate:main Jul 22, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants