Hi there. Our code mostly works with julian dates and starting from the cycle date, I need to set environment variables for start and end of each of each cycle in julian date format. What would be the best way to do this?
Cheers!
Gaby
Is this Julian dates as used in astronomy?
Using the formula from Wikipedia
(1461 ร (Y + 4800 + (M โ 14)/12))/4 +(367 ร (M โ 2 โ 12 ร ((M โ 14)/12)))/12 โ (3 ร ((Y + 4900 + (M - 14)/12)/100))/4 + D โ 32075
Iโd say the best way to do this might be using a python script and the isodatetime library
Quick script to illustrate; made with assistance of GitHub Copilot; Iโve not tested this:
from metomi.isodatetime.datetimeoper import DateTimeOperator
cycle_point, _ = DateTimeOperator().date_parse('ref') # uses $CYLC_TASK_CYCLE_POINT
julian_date = (
1461 * (
cycle_point.year + 4800 + (cycle_point.month_of_year - 14) // 12
)
) // 4 + (
367 * (
cycle_point.month_of_year - 2 - 12 * ((cycle_point.month_of_year - 14) // 12)
)
) // 12 - (
3 * ((cycle_point.year + 4900 + (cycle_point.month_of_year - 14) // 12) // 100)
) // 4 + cycle_point.day_of_month - 32075
You could make a pull request to the open source Metomi-Isodatetime library used by Cylc to add a Julian Cycling mode. Effectively just some data inputting at isodatetime/metomi/isodatetime/data.py at master ยท metomi/isodatetime ยท GitHub
Oh and I guess I missed this out: you should be able to import the script in Jinja2 in the workflow in order to set the environment variables. See Jinja2 โ Cylc 8.3.0 documentation
Ha, I will need to figure out which kind of Julian date they are taking about. Apparently there are different versions being used , but thanx for the tip about using a script