Anda dapat membuat halaman dokumentasi untuk buat pada modul Scribunto ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
require("strict") localp={} localTEMPLATES={ birth_date="Birth date", birth_date_and_age="Tanggal lahir dan umur", birth_year="Birth-date", birth_year_and_age="Birth year and age", death_date="Death date", death_date_text="Death-date", death_date_and_age="Death date and age", death_year="Death-date", death_year_and_age="Tahun mati dan umur", } localinvalid_date_category='' localtracking_category='' localDate=require('Modul:Date')._Date localgetArgs=require('Modul:Arguments').getArgs ifmw.title.getCurrentTitle():inNamespaces(0,828,829)then -- Category only in namespaces: 0=article, 828=module & 829=module talk (last 2 needed for testcases) tracking_category='[[Kategori:Halaman dengan kelahiran atau kematian otomatis ditentukan]]' invalid_date_category='[[Kategori:Halaman dengan tanggal kelahiran atau kematian tidak valid]]' end localfunctioncheck_for_invalid_date(str) returnmw.ustring.match(str,'^%?')ormw.ustring.match(str,'^%d%d%?')ormw.ustring.match(str,'^[Uu]nk') end localfunctionexpand_template(template,args) returnmw.getCurrentFrame():expandTemplate{title=template,args=args} end localfunctionparse_date(str) localdate=Date(str) ifdatethen returntostring(date.year),tostring(date.month),tostring(date.day) end -- TODO: Date has not been parsed. Need to work out what to do. For now, throw an error. -- Example where this can occur: "birth_date = 22 December 1946" at [[Maurice Pasternak]]. -- There was a nonbreaking space after "22" whidh Date does not accept. error('Module:Person_date parse_date invalid date: "'..tostring(str)..'"') end localfunctiondate_format(str) ifmw.ustring.match(str,'^%d+%s*%a+[%.]*%s*%d%d%d%d$')then return'df' elseifmw.ustring.match(str,'^%a+[%.]*%s+%d+,%s*%d%d%d%d$')then return'mf' else return'ERROR' end end localfunctionis_valid_month(str) str=string.upper(mw.ustring.sub(str,1,1))..string.lower(mw.ustring.sub(str,2)) localmonths={'Jan','Jan.','January','Januari','Feb','Feb.','February','Februari','Mar','March','Maret','Apr','Apr.','April','May','Mei','Jun','Jun.','June','Juni','Jul','Jul.','July','Juli','Aug','Aug.','Agu','Agu.','August','Agustus','Sep','Sept','Sep.','Sept.','September','Oct','Oct.','Okt','Okt.','October','Oktober','Nov','Nov','November','Dec','Dec.','Des','Des.','December','Desember'} forindex,valueinipairs(months)do ifvalue==strthen returntrue end end returnfalse end localfunctionis_month_year_only(str) localmonth=mw.ustring.match(str,'^(%a+)[%.]*%s+%d%d%d%d$') ifmonth==nilthen returnfalse else returnis_valid_month(month) end end localfunctionis_valid_date(str) localmonth=mw.ustring.match(str,'^%d+%s*(%a+)[%.]*%s*%d%d%d%d$')ormw.ustring.match(str,'^(%a+)[%.]*%s+%d+,%s*%d%d%d%d$') ifmonth==nilthen returnfalse else returnis_valid_month(month) end end localfunctionis_year_only(str) returnmw.ustring.match(str,'^%d%d%d%d$') end localfunctionalready_has_template(str) str=mw.ustring.gsub(str,'&[Nn][Bb][Ss][Pp];',' ') returnmw.ustring.match(str,'<span')ormw.ustring.match(str,'<time')ormw.ustring.match(str,'%(aged%s*%d+')ormw.ustring.match(str,'%(age%s*%d+') end localfunctionsanatize_date(str) -- Sanatize leading & trailing whitespace (this caused an issue before it was implemented) str=mw.ustring.gsub(str,'^%s*','') str=mw.ustring.gsub(str,'%s*$','') -- Sanatize ordinals str=mw.ustring.gsub(str,'(%d+)st([,%s])','%1%2') str=mw.ustring.gsub(str,'(%d+)rd([,%s])','%1%2') str=mw.ustring.gsub(str,'(%d+)th([,%s])','%1%2') str=mw.ustring.gsub(str,'(%d+)nd([,%s])','%1%2') returnstr end localfunctionparse_birth(args) localbirth_date=args['birth_date']or'' localdeath_date=args['death_date']or'' localdisap_date=args['disappeared_date']or'' localoriginal=birth_date birth_date=sanatize_date(birth_date) death_date=sanatize_date(death_date) disap_date=sanatize_date(disap_date) -- Check for bad inputs. This used to be covered by a switch statement in infoboxes ifcheck_for_invalid_date(birth_date)then returnoriginal..invalid_date_category end ifalready_has_template(birth_date)then returnoriginal end ifis_valid_date(birth_date)then locallocation=mw.ustring.find(birth_date,'%d%d%d%d') localextra=mw.ustring.sub(birth_date,location+4)..tracking_category localdate=mw.ustring.sub(birth_date,1,location+3) localyear,month,day=parse_date(date) localformat=date_format(date) ifdeath_date==''anddisap_date==''then returnexpand_template(TEMPLATES.birth_date_and_age,{year,month,day,[format]='yes'})..extra elseifis_year_only(death_date)oris_valid_date(death_date)oris_month_year_only(death_date)then returnexpand_template(TEMPLATES.birth_date,{year,month,day,[format]='yes'})..extra else -- death_date is not a valid string (example: 'unknown') returnoriginal end end ifis_month_year_only(birth_date)then localyear=Date('1 '..birth_date):text('%Y') localmonth=Date('1 '..birth_date):text('%-m') locallocation=mw.ustring.find(birth_date,'%d%d%d%d') localdate=mw.ustring.sub(birth_date,1,location+3) localextra=mw.ustring.sub(birth_date,location+4)..tracking_category ifdeath_date==''anddisap_date==''then returnexpand_template(TEMPLATES.birth_year_and_age,{year,month})..extra elseifis_year_only(death_date)oris_valid_date(death_date)oris_month_year_only(death_date)then returnexpand_template(TEMPLATES.birth_year,{date})..extra else -- death_date is not a valid string (example: 'unknown') returnoriginal end end ifis_year_only(birth_date)then localdate=mw.ustring.sub(birth_date,1,5) localextra=mw.ustring.sub(birth_date,5)..tracking_category ifdeath_date==''anddisap_date==''then returnexpand_template(TEMPLATES.birth_year_and_age,{date})..extra elseifis_year_only(death_date)oris_valid_date(death_date)then returnexpand_template(TEMPLATES.birth_year,{date})..extra else -- death_date is not a valid string (example: 'unknown') returnoriginal end end returnoriginal end localfunctionparse_death(args) localbirth_date=args['birth_date']or'' localdeath_date=args['death_date']or'' localoriginal=death_date birth_date=sanatize_date(birth_date) death_date=sanatize_date(death_date) -- Check for bad inputs. This used to be covered by a switch statement in infoboxes ifcheck_for_invalid_date(death_date)then returnoriginal..invalid_date_category end ifalready_has_template(death_date)then returnoriginal end ifis_valid_date(death_date)oris_month_year_only(death_date)then locallocation=mw.ustring.find(death_date,'%d%d%d%d') localdate=mw.ustring.sub(death_date,1,location+3) localextra=mw.ustring.sub(death_date,location+4)..tracking_category localformat=date_format(date) ifbirth_date==''then ifis_month_year_only(death_date)then returnexpand_template(TEMPLATES.death_date_text,{date})..extra end localyear,month,day=parse_date(date) returnexpand_template(TEMPLATES.death_date,{year,month,day,[format]='yes'})..extra else ifis_year_only(birth_date)then location=mw.ustring.find(birth_date,'%d%d%d%d') localbd=mw.ustring.sub(birth_date,1,location+3) ifis_month_year_only(death_date)then returnexpand_template(TEMPLATES.death_date_and_age,{date,bd})..extra end returnexpand_template(TEMPLATES.death_date_and_age,{date,bd,[format]='yes'})..extra elseifis_valid_date(birth_date)oris_month_year_only(birth_date)then location=mw.ustring.find(birth_date,'%d%d%d%d') localbd=mw.ustring.sub(birth_date,1,location+3) if(is_month_year_only(death_date))then returnexpand_template(TEMPLATES.death_date_and_age,{date,bd})..extra end returnexpand_template(TEMPLATES.death_date_and_age,{date,bd,[format]='yes'})..extra end end end ifis_year_only(death_date)then ifbirth_date==''then returnexpand_template(TEMPLATES.death_year,{mw.ustring.sub(death_date,1,5)})..mw.ustring.sub(death_date,5)..tracking_category else ifis_year_only(birth_date)then returnexpand_template(TEMPLATES.death_year_and_age,{mw.ustring.sub(death_date,1,5),mw.ustring.sub(birth_date,1,5)})..mw.ustring.sub(death_date,5)..tracking_category else ifis_valid_date(birth_date)then locallocation=mw.ustring.find(death_date,'%d%d%d%d') localdate=mw.ustring.sub(death_date,1,location+3) localextra=mw.ustring.sub(death_date,location+4)..tracking_category location=mw.ustring.find(birth_date,'%d%d%d%d') localbd=mw.ustring.sub(birth_date,1,location+3) returnexpand_template(TEMPLATES.death_date_and_age,{date,bd})..extra end end end end returnoriginal end functionp.birth(frame) returnparse_birth(getArgs(frame,{parentFirst=true})) end functionp.death(frame) returnparse_death(getArgs(frame,{parentFirst=true})) end returnp