FANDOM


(Undo revision 12881 by Noreplyz (talk))
(Update dates to fix template)
Line 13: Line 13:
 
end
 
end
   
BirthdayInsert('1996-1-1', '钱锟', 'Kun (1996)')
+
BirthdayInsert('1996-01-01', '钱锟', 'Kun (1996)')
BirthdayInsert('1997-1-1', '谢可寅', 'Xie Keyin')
+
BirthdayInsert('1997-01-01', '谢可寅', 'Xie Keyin')
BirthdayInsert('2000-1-20', '李紫婷', 'Li Ziting')
+
BirthdayInsert('2000-01-20', '李紫婷', 'Li Ziting')
BirthdayInsert('2001-1-22', '李权哲', 'Li Quanzhe')
+
BirthdayInsert('2001-01-22', '李权哲', 'Li Quanzhe')
BirthdayInsert('1999-1-25', '黄旭熙', 'Lucas')
+
BirthdayInsert('1999-01-25', '黄旭熙', 'Lucas')
BirthdayInsert('1995-1-26', '吴宣仪', 'Wu Xuanyi')
+
BirthdayInsert('1995-01-26', '吴宣仪', 'Wu Xuanyi')
BirthdayInsert('2002-2-19', '黄明昊', 'Justin')
+
BirthdayInsert('2002-02-19', '黄明昊', 'Justin')
BirthdayInsert('1996-2-27', '李永钦', 'Ten')
+
BirthdayInsert('1996-02-27', '李永钦', 'Ten')
BirthdayInsert('2000-3-8', '高茂桐', 'Gao Maotong')
+
BirthdayInsert('2000-03-08', '高茂桐', 'Gao Maotong')
BirthdayInsert('1996-3-9', '张紫宁', 'Zhang Zining')
+
BirthdayInsert('1996-03-09', '张紫宁', 'Zhang Zining')
BirthdayInsert('1996-3-18', '朱正廷', 'Zhu Zhengting')
+
BirthdayInsert('1996-03-18', '朱正廷', 'Zhu Zhengting')
BirthdayInsert('1993-4-11', '邱治谐', 'Qiu Zhixie')
+
BirthdayInsert('1993-04-11', '邱治谐', 'Qiu Zhixie')
BirthdayInsert('1996-5-4', '林超澤', 'Lin Chaoze')
+
BirthdayInsert('1996-05-04', '林超澤', 'Lin Chaoze')
BirthdayInsert('1998-5-14', '黄新淳', 'Huang Xinchun')
+
BirthdayInsert('1998-05-14', '黄新淳', 'Huang Xinchun')
BirthdayInsert('1999-5-20', '小鬼', 'Lil Ghost')
+
BirthdayInsert('1999-05-20', '小鬼', 'Lil Ghost')
BirthdayInsert('1996-6-4', '贝汯璘', 'Bei Honglin')
+
BirthdayInsert('1996-06-04', '贝汯璘', 'Bei Honglin')
BirthdayInsert('1999-6-14', '林君怡', 'Lin Junyi')
+
BirthdayInsert('1999-06-14', '林君怡', 'Lin Junyi')
BirthdayInsert('2000-6-16', '范丞丞', 'Fan Chengcheng')
+
BirthdayInsert('2000-06-16', '范丞丞', 'Fan Chengcheng')
BirthdayInsert('1994-6-19', '徐梦洁', 'Xu Mengjie')
+
BirthdayInsert('1994-06-19', '徐梦洁', 'Xu Mengjie')
BirthdayInsert('1995-6-29', '傅菁', 'Fu Jing')
+
BirthdayInsert('1995-06-29', '傅菁', 'Fu Jing')
BirthdayInsert('1998-7-7', '赖美云', 'Lai Meiyun')
+
BirthdayInsert('1998-07-07', '赖美云', 'Lai Meiyun')
BirthdayInsert('1996-7-13', '王子异', 'Wang Ziyi')
+
BirthdayInsert('1996-07-13', '王子异', 'Wang Ziyi')
BirthdayInsert('1991-7-19', '刘丹萌', 'Liu Danmeng')
+
BirthdayInsert('1991-07-19', '刘丹萌', 'Liu Danmeng')
BirthdayInsert('2000-7-25', '陈乐一', 'Chen Leyi')
+
BirthdayInsert('2000-07-25', '陈乐一', 'Chen Leyi')
BirthdayInsert('1995-7-27', '陆定昊', 'Lu Dinghao')
+
BirthdayInsert('1995-07-27', '陆定昊', 'Lu Dinghao')
BirthdayInsert('1998-7-31', '杨超越', 'Yang Chaoyue')
+
BirthdayInsert('1998-07-31', '杨超越', 'Yang Chaoyue')
BirthdayInsert('1998-8-2', '蔡徐坤', 'Kun (1998)')
+
BirthdayInsert('1998-08-02', '蔡徐坤', 'Kun (1998)')
BirthdayInsert('1999-8-8', '肖德俊', 'Xiaojun')
+
BirthdayInsert('1999-08-08', '肖德俊', 'Xiaojun')
BirthdayInsert('1997-8-12', '徐艺洋', 'Xu Yiyang')
+
BirthdayInsert('1997-08-12', '徐艺洋', 'Xu Yiyang')
BirthdayInsert('1995-8-24', '林彦俊', 'Lin Yanjun')
+
BirthdayInsert('1995-08-24', '林彦俊', 'Lin Yanjun')
BirthdayInsert('1997-9-2', '李若天', 'Li Ruotian')
+
BirthdayInsert('1997-09-02', '李若天', 'Li Ruotian')
BirthdayInsert('1994-9-19', '尤长靖', 'You Zhangjing')
+
BirthdayInsert('1994-09-19', '尤长靖', 'You Zhangjing')
BirthdayInsert('1995-9-26', '吴卓凡', 'Wu Zhuofan')
+
BirthdayInsert('1995-09-26', '吴卓凡', 'Wu Zhuofan')
BirthdayInsert('1996-9-28', '杨芸晴', 'Sunnee')
+
BirthdayInsert('1996-09-28', '杨芸晴', 'Sunnee')
BirthdayInsert('1999-9-28', '黄冠亨', 'Hendery')
+
BirthdayInsert('1999-09-28', '黄冠亨', 'Hendery')
BirthdayInsert('2000-10-3', '陈立农', 'Chen Linong')
+
BirthdayInsert('2000-10-03', '陈立农', 'Chen Linong')
BirthdayInsert('1991-10-7', '郭颖', 'Yamy')
+
BirthdayInsert('1991-10-07', '郭颖', 'Yamy')
 
BirthdayInsert('2000-10-10', '刘扬扬', 'Yangyang')
 
BirthdayInsert('2000-10-10', '刘扬扬', 'Yangyang')
 
BirthdayInsert('1998-10-15', '孟美岐', 'Meng Meiqi')
 
BirthdayInsert('1998-10-15', '孟美岐', 'Meng Meiqi')
Line 57: Line 57:
 
BirthdayInsert('1997-11-30', '姜京佐', 'Jiang Jingzuo')
 
BirthdayInsert('1997-11-30', '姜京佐', 'Jiang Jingzuo')
 
BirthdayInsert('2001-12-28', '段奥娟', 'Duan Aojuan')
 
BirthdayInsert('2001-12-28', '段奥娟', 'Duan Aojuan')
 
BirthdayInsert('19--', '', '')
 
   
 
function Ordinal(anumber)
 
function Ordinal(anumber)

Revision as of 00:55, December 25, 2019

 
local p = {}
 
 
D = {}
J = {} 
T = {}
 
function BirthdayInsert(Date, Korean, English)
    table.insert(D, Date)
    table.insert(J, Chinese)
    table.insert(T, English)
end
 
BirthdayInsert('1996-01-01', '钱锟', 'Kun (1996)')
BirthdayInsert('1997-01-01', '谢可寅', 'Xie Keyin')
BirthdayInsert('2000-01-20', '李紫婷', 'Li Ziting')
BirthdayInsert('2001-01-22', '李权哲', 'Li Quanzhe')
BirthdayInsert('1999-01-25', '黄旭熙', 'Lucas')
BirthdayInsert('1995-01-26', '吴宣仪', 'Wu Xuanyi')
BirthdayInsert('2002-02-19', '黄明昊', 'Justin')
BirthdayInsert('1996-02-27', '李永钦', 'Ten')
BirthdayInsert('2000-03-08', '高茂桐', 'Gao Maotong')
BirthdayInsert('1996-03-09', '张紫宁', 'Zhang Zining')
BirthdayInsert('1996-03-18', '朱正廷', 'Zhu Zhengting')
BirthdayInsert('1993-04-11', '邱治谐', 'Qiu Zhixie')
BirthdayInsert('1996-05-04', '林超澤', 'Lin Chaoze')
BirthdayInsert('1998-05-14', '黄新淳', 'Huang Xinchun')
BirthdayInsert('1999-05-20', '小鬼', 'Lil Ghost')
BirthdayInsert('1996-06-04', '贝汯璘', 'Bei Honglin')
BirthdayInsert('1999-06-14', '林君怡', 'Lin Junyi')
BirthdayInsert('2000-06-16', '范丞丞', 'Fan Chengcheng')
BirthdayInsert('1994-06-19', '徐梦洁', 'Xu Mengjie')
BirthdayInsert('1995-06-29', '傅菁', 'Fu Jing')
BirthdayInsert('1998-07-07', '赖美云', 'Lai Meiyun')
BirthdayInsert('1996-07-13', '王子异', 'Wang Ziyi')
BirthdayInsert('1991-07-19', '刘丹萌', 'Liu Danmeng')
BirthdayInsert('2000-07-25', '陈乐一', 'Chen Leyi')
BirthdayInsert('1995-07-27', '陆定昊', 'Lu Dinghao')
BirthdayInsert('1998-07-31', '杨超越', 'Yang Chaoyue')
BirthdayInsert('1998-08-02', '蔡徐坤', 'Kun (1998)')
BirthdayInsert('1999-08-08', '肖德俊', 'Xiaojun')
BirthdayInsert('1997-08-12', '徐艺洋', 'Xu Yiyang')
BirthdayInsert('1995-08-24', '林彦俊', 'Lin Yanjun')
BirthdayInsert('1997-09-02', '李若天', 'Li Ruotian')
BirthdayInsert('1994-09-19', '尤长靖', 'You Zhangjing')
BirthdayInsert('1995-09-26', '吴卓凡', 'Wu Zhuofan')
BirthdayInsert('1996-09-28', '杨芸晴', 'Sunnee')
BirthdayInsert('1999-09-28', '黄冠亨', 'Hendery')
BirthdayInsert('2000-10-03', '陈立农', 'Chen Linong')
BirthdayInsert('1991-10-07', '郭颖', 'Yamy')
BirthdayInsert('2000-10-10', '刘扬扬', 'Yangyang')
BirthdayInsert('1998-10-15', '孟美岐', 'Meng Meiqi')
BirthdayInsert('1997-10-28', '董思成', 'Winwin')
BirthdayInsert('1999-11-19', '丁泽仁', 'Ding Zeren')
BirthdayInsert('1997-11-20', '毕雯珺', 'Bi Wenjun')
BirthdayInsert('1997-11-30', '姜京佐', 'Jiang Jingzuo')
BirthdayInsert('2001-12-28', '段奥娟', 'Duan Aojuan')
 
function Ordinal(anumber)
    if anumber % 10 == 1 then
        return anumber .. "st"
    elseif anumber % 10 == 2 then
        if anumber%100==12 then
            return anumber .. "th"
        else
            return anumber .. "nd"
        end
    elseif anumber % 10 == 3 then
        if anumber%100==13 then
            return anumber .. "th"
        else
            return anumber .. "rd"
        end
    else
        return anumber .. "th"
    end
end
 
function WhichBirthday(yyyymmdd)
    --Just rounds to which age is nearest. For standard uses of looking forward a week, it does the trick.
    _, _, y, m, d = string.find(yyyymmdd, "(%d%d%d%d)-(%d%d)-(%d%d)")
    difference = os.time() - os.time{year=y, month=m, day=d}
    difference = difference / 31555008
    difference = math.floor(difference+0.5) --Rounding
    return Ordinal(difference)
end
 
function WhereDayXStarts(mmdd)
    i = 0
    repeat
        i=i+1
    until string.sub( D[i], 6, 10 ) >= mmdd or i == table.getn(D)
    if string.sub(D[i], 6, 10) < mmdd then i = 1 end --If we've gone all the way and found squat, stick to the beginning.
    return i --.. " " .. string.sub( D[i], 6, 10 ) .. " >= " .. mmdd .. " or i == " .. table.getn(D)
end
 
function WhereDayXEnds(mmdd)
    _, _, m, d = string.find(mmdd, "(%d%d)-(%d%d)")
    if d+1 < 10 then
        nextday = m .. "-0" .. d+1 --Needs zero padded
    else
        nextday = m .. "-" .. d+1 --Even if this date isnt' real, it should work as a point of comparison
    end
    if nextday=="12-32" then
        return table.getn(D) -- As long as things are properly ordered, the table ends with the end of the year.
    else
        thisdaybegins = WhereDayXStarts(mmdd)
        itbegins = WhereDayXStarts(nextday)
        if(thisdaybegins==itbegins) then --Next day starts no later than today, so no need to subtract 1.
            ThenWhereDayXEnds = itbegins
        else
            ThenWhereDayXEnds = itbegins - 1 --Just before where the next day starts, see.
            if ThenWhereDayXEnds == 0 then ThenWhereDayXEnds = table.getn(D) end --Again if the very beginning is "after", the end is... the end.
        end
        return ThenWhereDayXEnds
    end
end
 
function p.upcoming(frame)
    num_days = tonumber(frame.args.days or 7)
    num_min = tonumber(frame.args.min or 2)
    starting = frame.args.starting or os.date("%m-%d",os.time()+32400)
    ending = os.date("%m-%d", os.time{year=2001, month=string.sub(starting,1,2), day=string.sub(starting,4,5)}+86400*(num_days-1))
 
    STARTBEGINS = WhereDayXStarts(starting)
    ENDENDS = WhereDayXEnds(ending)
    LISTEND = table.getn(D)
 
 
    --output = "starting: " .. starting .. " ending: " .. ending .. " STARTBEGINS: " .. STARTBEGINS .. " ENDENDS: " .. ENDENDS .. " LISTEND: " .. LISTEND
 
    startread2 = 0
    endread2 = -1
    if ENDENDS>=STARTBEGINS then
        if (ENDENDS-STARTBEGINS+1) >= num_min then
            --Is Y greater than X and Y-X>=Min? Fantastic! Read from spots X through Y.
            --output = output .. " CASE 1 "
            startread1 = STARTBEGINS
            endread1 = ENDENDS
            startread2 = 0
        elseif (LISTEND-STARTBEGINS+1) >= num_min then
            --Is Y greater than X, Y-X<Min, and End-X>=Min? OK, find what date X+Min is, find where that date ends, call it Y. Read from spots X through Y.
            --output = output .. " CASE 2 "
            ending = string.sub(D[STARTBEGINS+num_min-1], 6, 10 ) --mm-dd for minimum spot
            ENDENDS = WhereDayXEnds(ending)
            startread1 = STARTBEGINS
            endread1 = ENDENDS
        else
            --Need more to hit minimum, rest of list isn't enough. Need to check beginning of list for end of minimum and read those too.
            --output = output .. " CASE 3 "
            ending = string.sub(D[num_min-(LISTEND-STARTBEGINS+1)], 6, 10 ) --mm-dd for minimum spot
            ENDENDS = WhereDayXEnds(ending)
            startread1 = STARTBEGINS
            endread1 = LISTEND
            startread2 = 1
            endread2 = ENDENDS
        end
    else
        if (LISTEND-STARTBEGINS+ENDENDS) >= num_min then
            --Is Y less than X and (End-X+Y)>=Min? Read from spots X through End, then 1 through Y.
            --output = output .. " CASE 4 "
            startread1 = STARTBEGINS
            endread1 = LISTEND
            startread2 = 1
            endread2 = ENDENDS
        else
            --Is Y less than X, (End-X+Y)<Min? OK, find what date (Min-End-X) is, find where that date ends, call it Y. Read from spots X through End, then 1 through Y.
            --Very similar to an earlier case, except this time Y has already looped. Calculations should remain the same, though.
            --output = output .. " CASE 5 "
            ending = string.sub(D[num_min-(LISTEND-STARTBEGINS+1)], 6, 10 ) --mm-dd for minimum spot
            ENDENDS = WhereDayXEnds(ending)
            startread1 = STARTBEGINS
            endread1 = LISTEND
            startread2 = 1
            endread2 = ENDENDS
        end
    end
 
    --output = output .. " ending: " .. ending .. " ENDENDS: " .. ENDENDS
    --output = output.. " startread1: " .. startread1 .. " " .. T[startread1] .. " endread1: " .. endread1 .. " " .. T[endread1] .. " startread2: " .. startread2 .. " endread2: " .. endread2 .. "\n"
 
    lastday = 0
    output = ""
 
    --First read group
    i = startread1
    while i<= endread1 do
        thisday = string.sub( D[i], 6, 10 )
        if thisday ~= lastday then --It's a new day, something should be written.
            output = output .. ";" .. os.date("%B %e", os.time{year=2001, month=string.sub(D[i],6,7), day=string.sub(D[i],9,10)}) .. ", "
            if thisday==starting then output = output .. "Happy Birthday!" else output = output .. "Coming Soon" end
            output = output .. "\n"
        end
        output = output .. ":[[" .. T[i] .. "]] (" .. WhichBirthday(D[i]) .. ")\n"
        lastday = thisday
        i=i+1
    end
 
    --Second read group
    i = startread2
    while i<= endread2 do
        thisday = string.sub( D[i], 6, 10 )
        if thisday ~= lastday then --It's a new day, something should be written.
            output = output .. ";" .. os.date("%B %e", os.time{year=2001, month=string.sub(D[i],6,7), day=string.sub(D[i],9,10)}) .. ", "
            if thisday==starting then output = output .. "Happy Birthday!" else output = output .. "Coming Soon" end
            output = output .. "\n"
        end
        output = output .. ":[[" .. T[i] .. "]] (" .. WhichBirthday(D[i]) .. ")\n"
        lastday = thisday
        i=i+1
    end
 
    return output -- .. " " .. os.clock()
end
 
function p.year(frame)
    year = frame.args[1] or 1982
    lastday = 0
    output = ""
    for i=1, table.getn(D), 1 do
        if string.sub(D[i],1,4) == year then
            thisday = string.sub( D[i], 6, 10 )
            if thisday ~= lastday then
                output = output .. ";" .. os.date("%B %e", os.time{year=2001, month=string.sub(D[i],6,7), day=string.sub(D[i],9,10)}) .. "\n"
            end
            output = output .. ":[[" .. T[i] .. "]]\n"
            lastday = thisday
        end
    end
    return output
end
 
function p.month(frame)
    month = frame.args[1] or 1
    if month == '1' or month == '01' then
        starting='01-01'
        ending='02-01'
    elseif month == '2' or month == '02' then
        starting='02-01'
        ending='03-01'
    elseif month == '3' or month == '03' then
        starting='03-01'
        ending='04-01'
    elseif month == '4' or month == '04' then
        starting='04-01'
        ending='05-01'
    elseif month == '5' or month == '05' then
        starting='05-01'
        ending='06-01'
    elseif month == '6' or month == '06' then
        starting='06-01'
        ending='07-01'
    elseif month == '7' or month == '07' then
        starting='07-01'
        ending='08-01'
    elseif month == '8' or month == '08' then
        starting='08-01'
        ending='09-01'
    elseif month == '9' or month == '09' then
        starting='09-01'
        ending='10-01'
    elseif month == '10' then
        starting='10-01'
        ending='11-01'
    elseif month == '11' then
        starting='11-01'
        ending='12-01'
    elseif month == '12' then
        starting='12-01'
        ending='12-31'
    end
 
    STARTBEGINS = WhereDayXStarts(starting)
    --ENDENDS = WhereDayXEnds(ending)
    if month=='12' then
        NEXTBEGINS = table.getn(D) + 1 -- Past the end
    else
        NEXTBEGINS = WhereDayXStarts(ending)
    end
 
    lastday = 0
    output = ""
 
    i = STARTBEGINS
    while i < NEXTBEGINS do
        thisday = string.sub( D[i], 6, 10 )
        if thisday ~= lastday then --It's a new day, something should be written.
            output = output .. ";" .. os.date("%B %e", os.time{year=2001, month=string.sub(D[i],6,7), day=string.sub(D[i],9,10)}) .. "\n"
        end
        output = output .. ":[[" .. T[i] .. "]] (" .. string.sub(D[i], 1, 4) .. ")\n"
        lastday = thisday
        i=i+1
    end
    return output
end
 
function p.age(frame)
    age = frame.args[1] or 20
    output = ""
    starting = os.date("%Y-%m-%d",os.time()+32400) --Y-m-d for today in Japan
    _, _, y, m, d = string.find(starting, "(%d%d%d%d)-(%d%d)-(%d%d)")
    LOWBORDER = y-age .. "-" .. m .. "-" .. d
    if d+1<10 then --needs a leading 0
        HIGHBORDER = y-age-1 .. "-" .. m .. "-0" .. d+1
    else
        HIGHBORDER = y-age-1 .. "-" .. m .. "-" .. d+1 --Might be an improper date, but for comparison purposes should work
    end
    --output = "LOWBORDER: " .. LOWBORDER .. " HIGHBORDER: " .. HIGHBORDER
    --return output
    STARTBEGINS = WhereDayXStarts(string.sub(HIGHBORDER,6,10))
 
    --First half
    i = STARTBEGINS
    while i<= table.getn(D) do
        if D[i] >= HIGHBORDER and D[i] <= LOWBORDER then
            output = output .. ":[[" .. T[i] .. "]] (" .. D[i] .. ")\n"
        end
        i=i+1
    end
 
    --Second half
    i = 1
    while i<= STARTBEGINS-1 do
        if D[i] >= HIGHBORDER and D[i] <= LOWBORDER then
            output = output .. ":[[" .. T[i] .. "]] (" .. D[i] .. ")\n"
        end
        i=i+1
    end
 
    return output
end
 
function p.between(frame)
    startdate=frame.args[1]
    enddate=frame.args[2]
    if startdate > enddate then --You trying to screw things up? Well, we'll just flip 'em.
        temp = startdate
        startdate = enddate
        enddate = temp
    end
    output = ""
 
    year = string.sub(startdate,1,4)
    while year<=string.sub(enddate,1,4) do
        if year==string.sub(startdate,1,4) then
            lowcomparison = string.sub(startdate,6,10) --If it's the first year, only start at the given date
        else
            lowcomparison = '01-01'
        end
        if year==string.sub(enddate,1,4) then
            highcomparison = string.sub(enddate,6,10) --If it's the last year, stop by the given date
        else
            highcomparison = '12-31'
        end
 
        i = 1
        while i<= table.getn(D) do
            if string.sub(D[i],1,4) == year and string.sub(D[i],6,10) >= lowcomparison and string.sub(D[i],6,10) <= highcomparison then
                output = output .. ":[[" .. T[i] .. "]] (" .. D[i] .. ")\n"
            end
            i=i+1
        end
        year=tostring(year+1)
    end
    return output
end
 
function p.random()
    math.randomseed( os.time() )
   return "[[" .. T[math.random(#T)] .. "]]" 
end
 
return p
 
--[[Category:Modules]]
Community content is available under CC-BY-SA unless otherwise noted.