Template talk:IntFixCal

Latest comment: 1 month ago by Crissov in topic Accuracy of calculation

Accuracy of calculation edit

Saturday, 28 April 2024

Current source code (pretty-printed and annotated) edit

Main template {{IntFixCal}}:

{{#switch: <!-- leap year? -->
{{#ifexpr: ({{CURRENTYEAR}} mod 4) = 0 
  | {{#ifexpr: ({{CURRENTYEAR}} mod 100)=0
      | {{#ifexpr: ({{CURRENTYEAR}} mod 400)=0 
          | 1 
          | 0 
         }} 
      | 1 <!-- this value is used in 2024 -->
    }} 
  | 0 
}}
|1= {{#ifexpr: {{#time:z}} < 169 <!-- = 6 * 4*7 + 1, IFC leap day -->
      | {{/days|{{#time:z}} }} <!-- we’re currently here, (after the Gregorian but) before the IFC leap day -->
      | {{#ifexpr: {{#time:z}}=169 
          | Leap Day 
          | {{/days|{{#time:z}} - 1 }}
        }}
    }}
|0= {{/days|{{#time:z}}}}
}} 
{{CURRENTYEAR}}

Helper sub-template {{IntFixCal/days}}, only considers common years, because the leap day is already handled by the parent template:

{{#ifeq: {{{1|{{#time:z}}}}} | 365 
  | NYD <!-- New Year’s Day -->
  | {{#ifeq: {{#expr:{{{1|{{#time:z}}}}} mod 28}} | 0 <!-- last day of the month? -->
      | 28 
      | {{#expr:{{{1|{{#time:z}}}}} mod 28}} 
    }} 
    {{#switch:{{#expr:{{{1|{{#time:z}}}}}/28 + 0.4999 round 0}} 
      |1=January 
      |2=February 
      |3=March 
      |4=April 
      |5=May 
      |6=June 
      |7=Sol
      |8=July
      |9=August 
      |10=September 
      |11=October 
      |12=November 
      |13=December 
    }} 
}}

Description edit

{{#time:z}} gives the ordinal day of the year starting at 0, therefore its maximum value for the last day of December is 364 in common years and 365 in leap years. (This is always the same for the Gregorian and the International Fixed calendar.) The IFC leap day comes after its sixth 4-week month, and thus is always the 169th day of the year. This day 169 is Gregorian 18 June in common years and 17 June in leap years. However, z is 168 then! Likewise, the value for NYD is 364! The expressions in the sub-template also assume a day number starting at 1.

I’ll go ahead and fix these issues by bulk-replacing {{#time:z}} with ({{#time:z}}+1). This could be written more elegantly, of course. — Christoph Päper 14:34, 4 March 2024 (UTC)Reply