Skip to content

Allow for quantity-string time delta as CxoTime initializer#60

Merged
taldcroft merged 4 commits intomasterfrom
init-with-delta-time
Oct 7, 2025
Merged

Allow for quantity-string time delta as CxoTime initializer#60
taldcroft merged 4 commits intomasterfrom
init-with-delta-time

Conversation

@taldcroft
Copy link
Copy Markdown
Member

@taldcroft taldcroft commented Sep 26, 2025

Description

This is a long-standing desire of mine to allow supplying a delta time offset from now to initialize DateTime.
This is in the form "+/-1yr 2d 3hr 4.2min 10.25s". Any function or command line tool that uses Ska
CxoTime or DateTime will work with this format.

This is especially convenient for command line arguments like --start=-14d --stop=-7d, or similar for any function that has DateTimeLike start / stop args.

This leverages the same functionality in CxoTime.

Requires

Interface impacts

Adds a new way to initialize DateTime.

Testing

Unit tests

  • Mac
# Including https://github.com/sot/cxotime/pull/54 @ 19f4f95 in the path

(ska3) ➜  chandra_time git:(init-with-delta-time) git rev-parse --short HEAD                       
024fdfb
(ska3) ➜  chandra_time git:(init-with-delta-time) env PYTHONPATH=/Users/aldcroft/git/cxotime pytest
======================================= test session starts ========================================
platform darwin -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0
rootdir: /Users/aldcroft/git/chandra_time
configfile: pytest.ini
plugins: anyio-4.7.0, timeout-2.3.1
collected 48 items                                                                                 

chandra_time/tests/test_Time.py ................................................             [100%]

======================================== 48 passed in 1.39s ========================================

Independent check of unit tests by Jean

  • OSX
(ska3-latest) flame:chandra_time jean$ git rev-parse HEAD
1a5a5db8e4569a795c6886b5984cd681b2430dfd
(ska3-latest) flame:chandra_time jean$ pytest
====================================================================== test session starts ======================================================================
platform darwin -- Python 3.12.8, pytest-8.3.4, pluggy-1.5.0
rootdir: /Users/jean/git/chandra_time
configfile: pytest.ini
plugins: socket-0.7.0, anyio-4.7.0, timeout-2.3.1
collected 48 items                                                                                                                                              

chandra_time/tests/test_Time.py ................................................                                                                          [100%]

====================================================================== 48 passed in 1.56s

Functional tests

No functional testing.

Copy link
Copy Markdown
Contributor

@jeanconn jeanconn left a comment

Choose a reason for hiding this comment

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

This looks good, though given using DateTime is already unofficially deprecated, I'm not sure if new code will ever exist to use it?

@taldcroft
Copy link
Copy Markdown
Member Author

This addresses the large swath of older Ska code that uses DateTime, including cheta and kadi.events.

@taldcroft taldcroft merged commit 72311d1 into master Oct 7, 2025
1 check passed
@taldcroft taldcroft deleted the init-with-delta-time branch October 7, 2025 19:23
@jeanconn
Copy link
Copy Markdown
Contributor

jeanconn commented Oct 7, 2025

Good point.

@javierggt javierggt mentioned this pull request Oct 31, 2025
@javierggt javierggt mentioned this pull request Nov 18, 2025
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