Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Usage  














Module:Infobox/dates






Afrikaans
تۆرکجه
Basa Bali

 / Bân-lâm-gú

Bikol Central
Cebuano
Cymraeg
الدارجة
Español
فارسی

ि
Ilokano
Bahasa Indonesia
Jawa

Kurdî
Madhurâ
ि
Македонски

مازِرونی
Bahasa Melayu
Mirandés
Na Vosa Vakaviti

Norsk bokmål
ି
Oʻzbekcha / ўзбекча


Português
Română
Scots
Shqip
Simple English
Slovenščina
کوردی
Српски / srpski
Tagalog

Tiếng Vit
Yorùbá


 

Edit links
 









Module
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 





Permanently protected module

From Wikipedia, the free encyclopedia
 

< Module:Infobox

Usage

  • {{#invoke:infobox/dates|start_end_date_template_validation}} - checks if the values of |first_aired=, |released=, |aired=, |released_date= are not passed via {{Start date}} and if the value of |last_aired= is not passed via {{End date}} (or is not |last_aired=present, where relevant). If they aren't, the function returns the default error category, Category:Pages using infobox television with nonstandard dates or the error category from |error_category= if used.
  • local getArgs = require('Module:Arguments').getArgs
    
    local default_error_category = "[[Category:Pages using infobox television with nonstandard dates]]"
    
    local p = {}
    
    function p.start_end_date_template_validation(frame)
     local args = getArgs(frame)
     local error_category = args.error_category or default_error_category
    
     local start_date = args.first_aired or args.released or args.airdate or args.release_date or args.airdate_overall
     if start_date then
      if not start_date:find("dtstart") then
       return error_category
      end
     end
    
     local end_date = args.last_aired
     if end_date then
      if not end_date:find("dtend") and end_date ~= "present" then
       return error_category
      end
     end
    end
    
    function p.dates(frame)
     local returnval
     local args = getArgs(frame)
     
     if table.getn(args) < 2 then
      if args['1'] == nil and args['2'] == nil then
       return ''
      elseif args['1'] == nil then 
       return args['2']
      elseif args['2'] == nil then 
       return args['1']
      end
     end
     
     args['1'] = args['1']:gsub("&nbsp;"," ")
     args['2'] = args['2']:gsub("&nbsp;"," ")
     
     local dmy = false
     local pr1, m1, d1, y1, su1 = string.match(args['1'], '(.-)(%u%a+)%s(%d+),%s(%d+)(.*)')
     local pr2, m2, d2, y2, su2 = string.match(args['2'], '(.-)(%u%a+)%s(%d+),%s(%d+)(.*)')
     if y1 == nil then
      dmy = true
      pr1, d1, m1, y1, su1 = string.match(args['1'], '(.-)(%d%d?)%s(%a+)%s(%d+)(.*)')
      pr2, d2, m2, y2, su2 = string.match(args['2'], '(.-)(%d%d?)%s(%a+)%s(%d+)(.*)')
     end
     
     local dash = '&nbsp;–<br />'
     if y1 ~= nil and y2 ~= nil then
      su1 = su1 or ''
      su2 = su2 or ''
      
      local MONTHS = {January=1, February=2, March=3, April=4, May=5, June=6, July=7, August=8, September=9, October=10, November=11, December=12}
      local diff = os.time({year=y2, month=MONTHS[m2], day=d2, hour=0, min=0, sec=0}) - os.time({year=y1, month=MONTHS[m1], day=d1, hour=0, min=0, sec=0})
      
      if diff < 0 then
       returnval = 'Invalid date range'
      else
       if y1 == y2 then
        if dmy == false then
         returnval = pr1 .. m1 .. ' ' .. d1 .. su1 .. dash .. pr2 .. m2 ..' '.. d2 ..', '.. y2 .. su2
        else
         returnval = pr1 .. d1 .. ' ' .. m1 .. su1 .. dash .. pr2 .. d2 .. ' ' .. m2 .. ' ' .. y2 .. su2
        end
       else
        if dmy == false then
         returnval = pr1 .. m1 .. ' ' .. d1 ..', '.. y1 .. su1 .. dash .. pr2 .. m2 .. ' '.. d2 .. ', ' .. y2 .. su2
        else
         returnval = pr1 .. d1 .. ' ' .. m1 ..' '.. y1 .. su1 .. dash .. pr2 .. d2 .. ' '.. m2 .. ' ' .. y2 .. su2
        end
       end
      end
     else
      returnval = args['1']..dash..args['2'];
     end
     
     return returnval;
    end
    
    return p
    

    Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Infobox/dates&oldid=1032499976"

    Hidden category: 
    Wikipedia template-protected modules
     



    This page was last edited on 7 July 2021, at 20:09 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki