Jump to content

Template:Timestamp2MJD

From Meta, a Wikimedia project coordination wiki

Note: this template does not work on installations (as has been observed on Windows) where a number, before mod is applied, is reduced to php data-type "signed INT", i.e. a signed 32-bits integer [1], i.e. where mod gives wrong results for integers outside the range -2,147,483,648 through 2,147,483,647. This template applies mod to timestamps, which have 14 digits, five too many. It could be rewritten either to use Template:Mod (which uses "round"), or use "round" directly. Also replacing mod with fmod seems to work, if mw:Extension:ParserFunctions (extended) has been installed.

This auxiliary template allows template:MJD (edittalklinkshistory) to operate on a single "{{CURRENTTIMESTAMP|=}}" gives "Template:CURRENTTIMESTAMP" [2] without risk of critical races:
60669.238576389

Usage: {{Timestamp2MJD|YYYYMMDDhhmmss}}, only non-negative whole numbers, almost no error handling. Months are checked for plausibility, this catches incomplete timestamps hhmmss and some variations of YYYYMMDDhmmss instead of YYYYMMDD0hmmss.

{{Timestamp2MJD|0}} gives Expression error: Unrecognized word "badmonth".
{{Timestamp2MJD|101223344|||=}} gives -678940.05990741, NOT RECOMMENDED
{{Timestamp2MJD|00000101000000|||=}} gives -678941, minimal Gregorian date
{{Timestamp2MJD|02000301000000|||=}} gives -605833, see also {{YMD2MJD}}
{{Timestamp2MJD|18581115223344|||=}} gives -1.0599074074074
{{Timestamp2MJD|18581116223344|||=}} gives -0.05990740740741
{{Timestamp2MJD|18581117223344|||=}} gives 0.94009259259259
{{Timestamp2MJD|18581118223344|||=}} gives 1.9400925925926
{{Timestamp2MJD|(18581115223344 round -6)|||=}} gives -2
{{Timestamp2MJD|(18581116223344 round -6)|||=}} gives -1
{{Timestamp2MJD|(18581117223344 round -6)|||=}} gives 0
{{Timestamp2MJD|(18581118223344 round -6)|||=}} gives 1
{{Timestamp2MJD|(20241225054333 round -6)|||=}} gives 60669

Test with subst and 20070321123457 (see edit box):

54180