Hi all,
I have been challenged to
a) validate a date given in a date picker custom field
b) compare two dates within a couple of other date picker custom fields
The use cases are (while creating an issue)
a) students may be able to sign up for services and will have to leave a day of birth - which has to be a reasonable value in the past - it would be plenty to check if the given date is around 20 years in the past (for example)
b) in order to request a machine user an initial time frame of validity for the machine user shall not extend 1 year from "start date" hence the value from "end date" shall not be higher than one year compared to "start date"
Both should be done with the help of Script Runner. I went through both the Adaptavist manual and library and also have checked around here:
In best case I came close. However for the first use case I had a couple of (very basic) approaches since I'm not very familiar with scripting even though I understand the concept of class imports, defining variables etc. For example I did not understand why I do not have to import classes here (taken from the first link above)? In general I found this one quite useful when changed appropriately (for which I'd appreciate your help.
def startTime = cfValues['Start Time']
def currentDate = new Date()
if (currentDate.getHours()>=12){
currentDate.plus(2).clearTime().compareTo(startTime) <= 0
}
else {
currentDate.plus(1).clearTime().compareTo(startTime) <= 0
}
For instance the first three lines would look like this:
def bday = cfValues['Day-of-Birth']
def currentDate = new Date()
if (currentDate.getYear()>=20)
As for the second use case (can we handle this here too?) I have learned that we can calculate the difference. However I was unable to deal with the value then during issue creation. I'm sure there's a way, can someone please show me?
Thank you very much in advance
Cheers,
Johannes