Skip to content

Commit 11d022c

Browse files
committed
Update time handling in knob and MQT extractors for improved clarity and consistency
1 parent 927f394 commit 11d022c

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

omc3/knob_extractor.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
- **time** *(str)*:
4545
4646
At what time to extract the knobs. Accepts ISO-format (YYYY-MM-
47-
DDThh:mm:ss), timestamp or 'now'. The default timezone for the ISO-
48-
format is local time, but you can force e.g. UTC by adding +00:00.
47+
DDThh:mm:ss) with timezone, timestamp or 'now'. Timezone must be
48+
specified for ISO-format (e.g. +00:00 for UTC).
4949
5050
default: ``now``
5151
@@ -212,7 +212,7 @@ class Head:
212212

213213
USAGE_EXAMPLES = """Usage Examples:
214214
215-
python -m omc3.knob_extractor --knobs disp chroma --time 2022-05-04T14:00
215+
python -m omc3.knob_extractor --knobs disp chroma --time 2022-05-04T14:00+00:00
216216
extracts the chromaticity and dispersion knobs at 14h on May 4th 2022
217217
218218
python -m omc3.knob_extractor --knobs disp chroma --time now _2h
@@ -241,9 +241,8 @@ def get_params():
241241
"type": str,
242242
"help": (
243243
"At what time to extract the knobs. "
244-
"Accepts ISO-format (YYYY-MM-DDThh:mm:ss), timestamp or 'now'. "
245-
"The default timezone for the ISO-format is local time, "
246-
"but you can force e.g. UTC by adding +00:00."
244+
"Accepts ISO-format (YYYY-MM-DDThh:mm:ss) with timezone, timestamp or 'now'. "
245+
"Timezone must be specified for ISO-format (e.g. +00:00 for UTC)."
247246
),
248247
"default": "now",
249248
},

omc3/mqt_extractor.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
- **time** *(str)*:
2626
2727
At what time to extract the MQT knobs. Accepts ISO-format (YYYY-MM-
28-
DDThh:mm:ss), timestamp or 'now'. The default timezone for the ISO-
29-
format is local time, but you can force e.g. UTC by adding +00:00.
28+
DDThh:mm:ss) with timezone, timestamp or 'now'. Timezone must be
29+
specified for ISO-format (e.g. +00:00 for UTC).
3030
3131
default: ``now``
3232
@@ -81,7 +81,7 @@
8181

8282
USAGE_EXAMPLES = """Usage Examples:
8383
84-
python -m omc3.mqt_extractor --beam 1 --time 2022-05-04T14:00
84+
python -m omc3.mqt_extractor --beam 1 --time 2022-05-04T14:00+00:00
8585
extracts the MQT knobs for beam 1 at 14h on May 4th 2022
8686
8787
python -m omc3.mqt_extractor --beam 2 --time now --timedelta _2h
@@ -102,9 +102,8 @@ def get_params():
102102
"type": str,
103103
"help": (
104104
"At what time to extract the MQT knobs. "
105-
"Accepts ISO-format (YYYY-MM-DDThh:mm:ss), timestamp or 'now'. "
106-
"The default timezone for the ISO-format is local time, "
107-
"but you can force e.g. UTC by adding +00:00."
105+
"Accepts ISO-format (YYYY-MM-DDThh:mm:ss) with timezone, timestamp or 'now'. "
106+
"Timezone must be specified for ISO-format (e.g. +00:00 for UTC)."
108107
),
109108
"default": "now",
110109
},

tests/unit/test_nxcals_mqt_extraction.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,27 +182,31 @@ def test_parse_time_now():
182182
"""Test that _parse_time correctly handles 'now'."""
183183
from datetime import datetime
184184

185-
result = mqt_extractor._parse_time("now")
185+
from omc3.utils.time_tools import parse_time
186+
187+
result = parse_time("now")
186188
now = datetime.now(timezone.utc)
187189

188190
# Should be very close to now (within 1 second)
189191
diff = abs((now - result).total_seconds())
190-
assert diff < 1, f"_parse_time('now') should return current time, diff was {diff}s"
192+
assert diff < 1, f"parse_time('now') should return current time, diff was {diff}s"
191193

192194

193195
def test_parse_time_with_timedelta():
194196
"""Test that _parse_time correctly applies timedelta."""
195197
from datetime import datetime
196198

199+
from omc3.utils.time_tools import parse_time
200+
197201
now_str = datetime.now(timezone.utc).isoformat()
198202

199203
# Test positive timedelta
200-
result_plus = mqt_extractor._parse_time(now_str, "1h")
201-
result_base = mqt_extractor._parse_time(now_str)
204+
result_plus = parse_time(now_str, "1h")
205+
result_base = parse_time(now_str)
202206
diff_plus = (result_plus - result_base).total_seconds()
203207
assert abs(diff_plus - 3600) < 1, f"1h timedelta should add 3600s, got {diff_plus}s"
204208

205209
# Test negative timedelta
206-
result_minus = mqt_extractor._parse_time(now_str, "_2h")
210+
result_minus = parse_time(now_str, "_2h")
207211
diff_minus = (result_minus - result_base).total_seconds()
208212
assert abs(diff_minus + 7200) < 1, f"_2h timedelta should subtract 7200s, got {diff_minus}s"

0 commit comments

Comments
 (0)