-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
search result depends on datetime format #644
Comments
I'm not sure if it's the cause of the observed difference, but pystac-client will "pad" the end datetime when you pass a string. See the I wonder what you get if you set |
Thanks a lot @TomAugspurger for helping to solve this. I changed the strings and pattern but get the same result.
|
Okay so the problem is in pystac-client/pystac_client/item_search.py Line 442 in e50483d
I guess in my case the one hour difference comes from the difference between UTC and CET where I am. >>> from datetime import datetime, timezone
>>> acq_start = '2022-02-02T12:00:00'
>>> pattern = '%Y-%m-%dT%H:%M:%S'
>>> acq_start_dt = datetime.strptime(acq_start, pattern)
>>> acq_start_dt_utc = acq_start_dt.astimezone(timezone.utc)
>>> print(acq_start_dt_utc)
2022-02-02 11:00:00+00:00 |
Ah, I was going to suggest timezones as a potential issue, but I misread
the docs. I thought the docs indicated tz-naive timezones would be
interpreted as UTC (i.e. `dt.replace(tzinfo=datetime.timezone.utc)` in
code) rather than converted from your locale to UTC.
Converting timezone-naive, rather than interpreting them as UTC, is a bit
surprising to me. I'd be open to deprecating the current behavior unless
there's strong precedence elsewhere in the stac-utils ecosystem around how
tz-naive datetimes are treated.
…On Wed, Feb 21, 2024 at 7:12 AM John Truckenbrodt ***@***.***> wrote:
Okay so the problem is in ItemSearch._to_utc_isoformat. The following
line converts all datetime.datetime objects to UTC:
https://github.com/stac-utils/pystac-client/blob/e50483de27a2ec0c4fb19961019fc5ac2451da46/pystac_client/item_search.py#L442
I guess in my case the one hour difference comes from the difference
between UTC and CET where I am.
>>> from datetime import datetime>>> acq_start = '2022-02-02T12:00:00'>>> pattern = '%Y-%m-%dT%H:%M:%S'>>> acq_start_dt = datetime.strptime(acq_start, pattern)>>> acq_start_dt_utc = acq_start_dt.astimezone(timezone.utc)>>> print(acq_start_dt_utc)2022-02-02 11:00:00+00:00
—
Reply to this email directly, view it on GitHub
<#644 (comment)>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKAOIRNGCUDVDQLAMILCMLYUXXDNBFKMF2HI4TJMJ2XIZLTSOBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLLDTOVRGUZLDORPXI6LQMWWES43TOVSUG33NNVSW45FGORXXA2LDOOJIFJDUPFYGLKTSMVYG643JORXXE6NFOZQWY5LFVEZTIMZZHEYDKMJZQKSHI6LQMWSWS43TOVS2K5TBNR2WLKRSGE2DMNJUGQ4DGNVHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
|
There's not a "usual" behavior as far as I know, so changing pystac-client to do the least surprising thing gets a 👍🏼 from me. |
🤔 I dug into this a bit, and I think pystac-client is doing "the right thing", i.e. interpreting strings w/o timezone information as UTC: pystac-client/pystac_client/item_search.py Lines 475 to 498 in df117b6
@johntruckenbrodt I think two different results are correct for your original post, since |
Ah I see. Wouldn't it then be more intuitive to assume the same time zone for strings and datetime objects if not specified by the user? Currently, the documentation of
However, |
@johntruckenbrodt right you are — thanks for sticking with it. I agree, #686 should fix -- LMK if that matches your understanding. |
Great! IMO this fixes it. Thanks a lot. |
Hi. I just observed some unexpected behavior when comparing the search result from queries with
datetime
as string and asdatetime.datetime
object. Can you help me out here?The first query returns 20 scenes in the defined time interval. The second query only returns 7 scenes outside the interval.
The text was updated successfully, but these errors were encountered: