Module:Citation/CS1/Date validation: Difference between revisions

    m>Trappist the monk
    (Synch from sandbox;)
    m>Trappist the monk
    m (Synch from sandbox;)
    Line 34: Line 34:




    -- Function gets current year from the server and compares it to year from a citation parameter.  Years more than one year in the future are not acceptable.
    --[[--------------------------< I S _ V A L I D _ Y E A R >----------------------------------------------------
     
    Function gets current year from the server and compares it to year from a citation parameter.  Years more than one year in the future are not acceptable.
     
    ]]
     
    function is_valid_year(year)
    function is_valid_year(year)
    if not is_set(year_limit) then
    if not is_set(year_limit) then
    year_limit = tonumber(os.date("%Y"))+1; -- global variable so we only have to fetch it once (os.date("Y") no longer works?)
    year_limit = tonumber(os.date("%Y"))+1; -- global variable so we only have to fetch it once
    end
    end
    return tonumber(year) <= year_limit; -- false if year is in the future more than one year
    return tonumber(year) <= year_limit; -- false if year is in the future more than one year
    end
    end


    Line 114: Line 119:
    character abbreviations, and seasons must be spelled correctly. Future years beyond next year are not allowed.
    character abbreviations, and seasons must be spelled correctly. Future years beyond next year are not allowed.


    If the date fails the fomat tests, this function returns false and does not return values for anchor_year and COinS_date.  When this happens, the date parameter is
    If the date fails the format tests, this function returns false and does not return values for anchor_year and COinS_date.  When this happens, the date parameter is
    used in the COinS metadata and the CITEREF identifier gets its year from the year parameter if present otherwise CITEREF does not get a date value.
    used in the COinS metadata and the CITEREF identifier gets its year from the year parameter if present otherwise CITEREF does not get a date value.


    Inputs:
    Inputs:
    date_string - date string from date-holding parameters (date, year, accessdate, embargo, archivedate, etc)
    date_string - date string from date-holding parameters (date, year, accessdate, embargo, archivedate, etc.)


    Returns:
    Returns:
    Line 275: Line 280:
    end
    end


    --[[
    --[[--------------------------< D A T E S >--------------------------------------------------------------------
     
    Cycle the date-holding parameters in passed table date_parameters_list through check_date() to check compliance with MOS:DATE. For all valid dates, check_date() returns
    Cycle the date-holding parameters in passed table date_parameters_list through check_date() to check compliance with MOS:DATE. For all valid dates, check_date() returns
    true. The |date= parameter test is unique, it is the only date holding parameter from which values for anchor_year (used in CITEREF identifiers) and COinS_date (used in
    true. The |date= parameter test is unique, it is the only date holding parameter from which values for anchor_year (used in CITEREF identifiers) and COinS_date (used in
    Line 282: Line 288:
    Unlike most error messages created in this module, only one error message is created by this function. Because all of the date holding parameters are processed serially,
    Unlike most error messages created in this module, only one error message is created by this function. Because all of the date holding parameters are processed serially,
    a single error message is created as the dates are tested.
    a single error message is created as the dates are tested.
    ]]
    ]]


    Line 301: Line 308:
    end
    end
    elseif 'date'==k then -- if the parameter is |date=
    elseif 'date'==k then -- if the parameter is |date=
    if v:match("n%.d%.%a?") then -- if |date=n.d. with or without a CITEREF disambiguator
    if v:match("^n%.d%.%a?") then -- if |date=n.d. with or without a CITEREF disambiguator
    good_date, anchor_year, COinS_date = true, v:match("((n%.d%.)%a?)"); --"n.d."; no error when date parameter is set to no date
    good_date, anchor_year, COinS_date = true, v:match("((n%.d%.)%a?)"); --"n.d."; no error when date parameter is set to no date
    elseif v:match("nd%a?$") then -- if |date=nd with or without a CITEREF disambiguator
    elseif v:match("^nd%a?$") then -- if |date=nd with or without a CITEREF disambiguator
    good_date, anchor_year, COinS_date = true, v:match("((nd)%a?)"); --"nd"; no error when date parameter is set to no date
    good_date, anchor_year, COinS_date = true, v:match("((nd)%a?)"); --"nd"; no error when date parameter is set to no date
    else
    else