Template:YMD2MJD/2
- This auxiliary template allows template:YMD2MJD (edit•talk•links•history) to operate on a single
"{{CURRENTTIMESTAMP|=}}"
gives "Template:CURRENTTIMESTAMP" [1] without risk of critical races: - 60425
Usage: {{YMD2MJD/2|YYYYMMDDhhmmss}}
, only nonnegative whole numbers, no error handling.
y | = year, can be zero (1 BC) or negative (2 BC etc.) |
m | = month 1..12, leading zero not required |
d | = similar day 1..31 |
hh | = hours (3600 seconds), any value for non-negative total |
mm | = minutes (60 seconds), any value for non-negative total |
ss | = seconds, any value for non-negative total seconds |
now | = current timestamp ymdhhmmss (string) |
ymd | = date, 0 < m <= 12 and 0 < d <= 31 |
T( p q ) | = template {{ ''T'' | ''p'' | ''q'' }} |
p + q | = {{ #expr: p + q }} |
MJD(y m d hh mm ss) | = YMD2MJD(y m d)+dectime(hh mm ss) |
MJD( ) | = Timestamp2MJD( now ) |
Timestamp2MJD(ymdhhmmss) | = YMD2MJD(y m d)+dectime(hh mm ss) |
dectime(hh mm ss) | = computed inline |
YMD2MJD(y m d) | = computed inline |
dectime( ) | = dectime/2( now ) |
YMD2MJD( ) | = YMD2MJD/2( now ) |
dectime/2( ymdhhmmss ) | = computed inline ignoring ymd |
YMD2MJD/2( ymdhhmmss ) | = computed inline ignoring hhmmss |
It's not possible to replace dectime(hh mm ss) by dectime/2(hhmmss) generally: dectime accepts any numerical value for hh mm ss, while dectime/2 is for strings of in essence six digits hhmmss, where signs, fractions, or missing zeros could cause havoc.
Likewise replacing YMD2MJD everywhere by YMD2MJD/2 won't work. The purpose of YMD2MJD/2 and dectime/2 is to evaluate CURRENTTIMESTAMP only once avoiding race conditions for second 59 and the next minute.
Some simplifications were still possible: Timestamp2MJD didn't need the error handling of YMD2MJD, it could use YMD2MJD/2. For similar reasons it could use dectime/2 instead of dectime. With those modifications we got:
MJD(y m d hh mm ss) | = YMD2MJD(y m d)+dectime(hh mm ss) |
MJD( ) | = Timestamp2MJD( now ) |
Timestamp2MJD(ymdhhmmss) | = YMD2MJD/2(ymdhhmmss)+dectime(ymdhhmmss) |
dectime(hh mm ss) | = computed inline |
YMD2MJD(y m d) | = computed inline |
dectime( ) | = dectime/2( now ) |
YMD2MJD( ) | = YMD2MJD/2( now ) |
dectime/2( ymdhhmmss ) | = computed inline ignoring ymd |
YMD2MJD/2( ymdhhmmss ) | = computed inline ignoring hhmmss |
Looking at the intermediate result it was possible to copy the code of dectime/2 and YMD2MJD/2 into Timestamp2MJD.
After that modification it's possible to replace the auxiliary templates by Timestamp2MJD in dectime and YMD2MJD. For that YMD2MJD has to use ymdhhmmss round -6, or in other words ymd000000, for the allowed non-negative timestamps, where 0 <= hh < 50 is guaranteed.
Similar dectime has to use ymdhhmmss mod 1000000 to get the desired decimal fraction between 0 and 1 excluding 1. Putting it all together without disrupting the working templates:
- Let Timestamp2MD use the code of the auxiliary /2 templates.
- Let YMD2MJD use Timestamp2MJD with round -6.
- Let dectime use Timestamp2MJD with mod 1000000.
- Remove the auxiliary templates from unrelated documentation.
MJD(y m d hh mm ss) | = YMD2MJD(y m d)+dectime(hh mm ss) |
MJD( ) | = Timestamp2MJD( now ) |
Timestamp2MJD(ymdhhmmss) | = computed inline |
dectime(hh mm ss) | = computed inline |
YMD2MJD(y m d) | = computed inline |
dectime( ) | = Timetamp2MJD( now ) (mod 1000000) |
YMD2MJD( ) | = TimestampMJD( now ) (round -6) |