-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
invalid date for authority #37
Comments
Do they have a uniform format? E.g., are they always of form |
Yes. but probably " is used more than single. On Sat, May 23, 2015 at 9:19 PM, Philip Kahn notifications@github.com
|
Then I'll match it against this regex: |
Will change single quotes to double quotes, checks both years, and single year if just the one testAuthorityYear = (authYearDeepInputSelector) ->
###
# Helper function!
# Take in a deep element selector, then run it through match
# patterns for the authority year.
#
# @param authYearDeepInputSelector -- Selector for a shadow DOM
# element, ideally a paper-input.
###
yearString = d$(authYearDeepInputSelector).val()
error = undefined
linnaeusYear = 1707 # Linnaeus's birth year
d = new Date()
nextYear = d.getUTCFullYear() + 1 # So we can honestly say "between" and mean it
# Authority date regex
# From
# https://github.com/tigerhawkvok/SSAR-species-database/issues/37
authorityRegex = /^\d{4}$|^\d{4} (\"|')\d{4}\1$/
unless isNumber(yearString) and linnaeusYear < yearString < nextYear
unless authorityRegex.test(yearString)
# It's definitely bad, we just need to decide how bad
if yearString.search(" ") is -1
error = "This must be a valid year between #{linnaeusYear} and #{nextYear}"
else
error = "Nonstandard years must be of the form: YYYY 'YYYY', eg, 1801 '1802'"
else
# It matches the regex, but fails the check
# So, it may be valid, but we need to check
if yearString.search(" ") is -1
# It's a simple year, but fails the check.
# Therefore, it's out of range.
error = "This must be a valid year between #{linnaeusYear} and #{nextYear}"
else
# There's a space, so it's of format:
# 1801 '1802'
# So we need to parse that out for a valid year check
# The format is otherwise assured by the regex
years = yearString.split(" ")
unless linnaeusYear < years[0] < nextYear
error = "The first year must be a valid year between #{linnaeusYear} and #{nextYear}"
altYear = years[1].replace(/(\"|')/g,"")
unless linnaeusYear < altYear < nextYear
error = "The second year must be a valid year between #{linnaeusYear} and #{nextYear}"
# Now, for input consistency, replace single-quotes with
# double-quotes
yearString = yearString.replace(/\"/g,'"')
# If there were any error strings assigned, display an error.
if error?
escapeCompletion = true
console.warn("#{authYearDeepInputSelector} failed its validity checks for #{yearString}!")
# Populate the paper-input errors
try
$("html /deep/ #{authYearDeepInputSelector} /deep/ paper-input-decorator")
.attr("error",error)
.attr("isinvalid","isinvalid")
catch e
$("html >>> #{authYearDeepInputSelector} >>> paper-input-decorator")
.attr("error",error)
.attr("isinvalid","isinvalid")
# Return the value for assignment
return yearString |
There are instances where we have to address taxonomic rules, e.g., see Alligator: Daudin 1802 '1801' which is the only valid way of citing the authority. So need to remove the validation rules for this field or allow exceptions.
The text was updated successfully, but these errors were encountered: