Template:Gregorian serial date

From Iwe

(Difference between revisions)
Line 1: Line 1:
-
<noinclude>
+
{{#expr:  
-
This template gives the [[Gregorian calendar|Gregorian]] serial day. This is the numbers of days from the start of 1 A.D. (Monday, 1 Jan 1 = 1). (In the Gregorian Calendar there is no year 0) This template should handle all leap year exceptions including the 100 and 400 year rule. By default this template gives the serial for today. To find the serial for another date fill in the date into this code: '''<nowiki>{{Gregorian serial date|month = |day = |year = }}</nowiki>
+
         {{void|Days from all years past:}}
-
 
+
-
'''Today's Date is'''
+
-
</noinclude>{{#expr:  
+
-
         <!--Days from all years past:-->
+
         + (({{{year|{{CURRENTYEAR}}}}} - 1) * 365)
         + (({{{year|{{CURRENTYEAR}}}}} - 1) * 365)
-
         + ((({{{year|{{CURRENTYEAR}}}}} - 1) - (({{{year|{{CURRENTYEAR}}}}} - 1) mod 4)) / 4)    <!--add a day for every leap-->
+
         + ((({{{year|{{CURRENTYEAR}}}}} - 1) - (({{{year|{{CURRENTYEAR}}}}} - 1) mod 4)) / 4)    {{void|add a day for every leap}}
-
         - ((({{{year|{{CURRENTYEAR}}}}} - 1) - (({{{year|{{CURRENTYEAR}}}}} - 1) mod 100)) / 100) <!--subtract 100 year exception-->
+
         - ((({{{year|{{CURRENTYEAR}}}}} - 1) - (({{{year|{{CURRENTYEAR}}}}} - 1) mod 100)) / 100) {{void|subtract 100 year exception}}
-
         + ((({{{year|{{CURRENTYEAR}}}}} - 1) - (({{{year|{{CURRENTYEAR}}}}} - 1) mod 400)) / 400) <!--readd 400 year exception-->
+
         + ((({{{year|{{CURRENTYEAR}}}}} - 1) - (({{{year|{{CURRENTYEAR}}}}} - 1) mod 400)) / 400) {{void|readd 400 year exception}}
-
       <!--Days so far this year:-->
+
       {{void|Days so far this year:}}
   
   
-
         + {{ #ifexpr:    <!--add days for past months this year--> <!--Gives 1 or 2 extra days because of February-->
+
         + {{ #ifexpr:    {{void|add days for past months this year}} {{void|Gives 1 or 2 extra days because of February}}
                     ({{{month|{{CURRENTMONTH}}}}} - 1) < 8  
                     ({{{month|{{CURRENTMONTH}}}}} - 1) < 8  
                     | ( ({{{month|{{CURRENTMONTH}}}}} - 1) * 30.5 round 0)  
                     | ( ({{{month|{{CURRENTMONTH}}}}} - 1) * 30.5 round 0)  
Line 19: Line 15:
           }}  
           }}  
         - {{ #ifexpr: ({{{month|{{CURRENTMONTH}}}}} <= 2) | 0 |   
         - {{ #ifexpr: ({{{month|{{CURRENTMONTH}}}}} <= 2) | 0 |   
-
             {{ #ifexpr:    <!-- if leap year  -->
+
             {{ #ifexpr:    {{void| if leap year  }}
-
                     ({{{year|{{CURRENTYEAR}}}}} / 4) = ({{{year|{{CURRENTYEAR}}}}} / 4 round 0)          <!--If divisible by 4-->
+
                     ({{{year|{{CURRENTYEAR}}}}} / 4) = ({{{year|{{CURRENTYEAR}}}}} / 4 round 0)          {{void|If divisible by 4}}
-
                       and ({{{year|{{CURRENTYEAR}}}}} / 100 != {{{year|{{CURRENTYEAR}}}}} / 100 round 0)  <!--and not by 100-->
+
                       and ({{{year|{{CURRENTYEAR}}}}} / 100 != {{{year|{{CURRENTYEAR}}}}} / 100 round 0)  {{void|and not by 100}}
                 | 1 | 2  
                 | 1 | 2  
             }}
             }}
           }}
           }}
         + {{ #ifexpr: ({{{month|{{CURRENTMONTH}}}}} <= 2) | 0 |
         + {{ #ifexpr: ({{{month|{{CURRENTMONTH}}}}} <= 2) | 0 |
-
             {{ #ifexpr: <!--400 year exception-->
+
             {{ #ifexpr: {{void|400 year exception}}
                     ({{{year|{{CURRENTYEAR}}}}} / 400) = ({{{year|{{CURRENTYEAR}}}}} / 400 round 0)  
                     ({{{year|{{CURRENTYEAR}}}}} / 400) = ({{{year|{{CURRENTYEAR}}}}} / 400 round 0)  
                 | 1 | 0  
                 | 1 | 0  
Line 34: Line 30:
  }}{{#ifexpr: {{{year|{{CURRENTYEAR}}}}} < 1 |
  }}{{#ifexpr: {{{year|{{CURRENTYEAR}}}}} < 1 |
         _ERROR - Can not handle dates before January 1, 1 A.D.
         _ERROR - Can not handle dates before January 1, 1 A.D.
-
   }}<noinclude>
+
   }}<noinclude>{{doc}}</noinclude>
-
 
+
-
 
+
-
 
+
-
*<nowiki>{{gsd|year=1|month=1|day=1}}</nowiki> gives {{gsd|year=1|month=1|day=1}}
+
-
*<nowiki>{{gsd|year=2000|month=12|day=31}}</nowiki> gives {{gsd|year=2000|month=12|day=31}} (5 times the number of days of a cycle, 146,097)
+
-
*<nowiki>{{gsd|year=2000|month=1|day=1}}</nowiki> gives {{gsd|year=2000|month=1|day=1}}
+
-
*<nowiki>{{gsd|year=2001|month=1|day=1}}</nowiki> gives {{gsd|year=2001|month=1|day=1}}
+
-
*<nowiki>{{gsd|year=2001|month=2|day=28}}</nowiki> gives {{gsd|year=2001|month=2|day=28}}
+
-
*<nowiki>{{gsd|year=2001|month=3|day=1}}</nowiki> gives {{gsd|year=2001|month=3|day=1}}
+

Revision as of 02:58, 18 August 2016

{{#expr:


       + ((2025 - 1) * 365)
       + (((2025 - 1) - ((2025 - 1) mod 4)) / 4)     
       - (((2025 - 1) - ((2025 - 1) mod 100)) / 100) 
       + (((2025 - 1) - ((2025 - 1) mod 400)) / 400) 


       + {{ #ifexpr:     
                    (01 - 1) < 8 
                    | ( (01 - 1) * 30.5 round 0) 
                    | ( (01 - 1) * 30.5 + 0.9 round 0 ) 
         }} 
       - {{ #ifexpr: (01 <= 2) | 0 |  
            {{ #ifexpr:    
                    (2025 / 4) = (2025 / 4 round 0)          
                     and (2025 / 100 != 2025 / 100 round 0)  
               | 1 | 2 
            }}
         }}
       + {{ #ifexpr: (01 <= 2) | 0 |
            {{ #ifexpr: 
                    (2025 / 400) = (2025 / 400 round 0) 
               | 1 | 0 
            }}
         }} 
       + 28
}}{{#ifexpr: 2025 < 1 |
       _ERROR - Can not handle dates before January 1, 1 A.D.
  }}Template:Doc
Personal tools